Commit 7d85f183 authored by Davis King's avatar Davis King

Removed the requirement that you load dng files into an image of the exact

pixel type that created the file.  Now you can use any pixel type.  I also
changed the code so that grayscale pixels with more than 16 bits get saved as
16 bit grayscale images instead of 8 bit images.

--HG--
extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%403586
parent 02286701
...@@ -588,11 +588,6 @@ namespace dlib ...@@ -588,11 +588,6 @@ namespace dlib
switch (type) switch (type)
{ {
case rgb_alpha_paeth: case rgb_alpha_paeth:
if (get_pixel_type<image_type>() != rgb_alpha)
{
image.clear();
throw image_load_error("You have tried to load a dng file that contains rgb_alpha_pixel data into an incompatible pixel type");
}
for (long r = 0; r < image.nr(); ++r) for (long r = 0; r < image.nr(); ++r)
{ {
...@@ -617,11 +612,6 @@ namespace dlib ...@@ -617,11 +612,6 @@ namespace dlib
break; break;
case rgb_alpha: case rgb_alpha:
if (get_pixel_type<image_type>() != rgb_alpha)
{
image.clear();
throw image_load_error("You have tried to load a dng file that contains rgb_alpha_pixel data into an incompatible pixel type");
}
for (long r = 0; r < image.nr(); ++r) for (long r = 0; r < image.nr(); ++r)
{ {
...@@ -646,11 +636,6 @@ namespace dlib ...@@ -646,11 +636,6 @@ namespace dlib
break; break;
case rgb_paeth: case rgb_paeth:
if (get_pixel_type<image_type>() != rgb)
{
image.clear();
throw image_load_error("You have tried to load a dng file that contains rgb_pixel data into an incompatible pixel type");
}
for (long r = 0; r < image.nr(); ++r) for (long r = 0; r < image.nr(); ++r)
{ {
...@@ -672,11 +657,6 @@ namespace dlib ...@@ -672,11 +657,6 @@ namespace dlib
break; break;
case rgb: case rgb:
if (get_pixel_type<image_type>() != rgb)
{
image.clear();
throw image_load_error("You have tried to load a dng file that contains rgb_pixel data into an incompatible pixel type");
}
for (long r = 0; r < image.nr(); ++r) for (long r = 0; r < image.nr(); ++r)
{ {
...@@ -698,11 +678,6 @@ namespace dlib ...@@ -698,11 +678,6 @@ namespace dlib
break; break;
case hsi: case hsi:
if (get_pixel_type<image_type>() != hsi)
{
image.clear();
throw image_load_error("You have tried to load a dng file that contains hsi_pixel data into an incompatible pixel type");
}
for (long r = 0; r < image.nr(); ++r) for (long r = 0; r < image.nr(); ++r)
{ {
...@@ -725,10 +700,6 @@ namespace dlib ...@@ -725,10 +700,6 @@ namespace dlib
case grayscale: case grayscale:
{ {
// An 8bit grayscale image should load successfully into any type of pixel since
// the assign_pixel() function converts perfectly between this pixel type and all
// others.
unsigned char p; unsigned char p;
for (long r = 0; r < image.nr(); ++r) for (long r = 0; r < image.nr(); ++r)
{ {
...@@ -745,12 +716,6 @@ namespace dlib ...@@ -745,12 +716,6 @@ namespace dlib
case grayscale_16bit: case grayscale_16bit:
{ {
if (get_pixel_type<image_type>() != grayscale_16bit)
{
image.clear();
throw image_load_error("You have tried to load a dng file that contains 16bit grayscale data into an incompatible pixel type");
}
uint16 p; uint16 p;
for (long r = 0; r < image.nr(); ++r) for (long r = 0; r < image.nr(); ++r)
{ {
......
...@@ -37,6 +37,9 @@ namespace dlib ...@@ -37,6 +37,9 @@ namespace dlib
- #image[0][0] will be the upper left corner of the image - #image[0][0] will be the upper left corner of the image
- #image[image.nr()-1][image.nc()-1] will be the lower right - #image[image.nr()-1][image.nc()-1] will be the lower right
corner of the image corner of the image
- Performs any color space conversion necessairy to convert the
BMP image data into the pixel type used by the given image
object.
throws throws
- image_load_error - image_load_error
This exception is thrown if there is an error that prevents us This exception is thrown if there is an error that prevents us
...@@ -73,6 +76,9 @@ namespace dlib ...@@ -73,6 +76,9 @@ namespace dlib
- #image[0][0] will be the upper left corner of the image - #image[0][0] will be the upper left corner of the image
- #image[image.nr()-1][image.nc()-1] will be the lower right - #image[image.nr()-1][image.nc()-1] will be the lower right
corner of the image corner of the image
- Performs any color space conversion necessairy to convert the
dng image data into the pixel type used by the given image
object.
throws throws
- image_load_error - image_load_error
This exception is thrown if there is an error that prevents us This exception is thrown if there is an error that prevents us
......
...@@ -20,24 +20,9 @@ namespace dlib ...@@ -20,24 +20,9 @@ namespace dlib
rgb_paeth, rgb_paeth,
rgb_alpha, rgb_alpha,
rgb_alpha_paeth, rgb_alpha_paeth,
grayscale_16bit, grayscale_16bit
}; };
template <typename image_type>
int get_pixel_type()
{
if (pixel_traits<typename image_type::type>::grayscale == true && sizeof(typename image_type::type) == 2)
return grayscale_16bit;
else if (pixel_traits<typename image_type::type>::grayscale == true && sizeof(typename image_type::type) == 1)
return grayscale_16bit;
else if (pixel_traits<typename image_type::type>::rgb == true)
return rgb;
else if (pixel_traits<typename image_type::type>::hsi == true)
return hsi;
else if (pixel_traits<typename image_type::type>::rgb_alpha == true)
return rgb_alpha;
}
const unsigned long dng_magic_byte = 100; const unsigned long dng_magic_byte = 100;
template <typename T> template <typename T>
......
...@@ -241,13 +241,13 @@ namespace dlib ...@@ -241,13 +241,13 @@ namespace dlib
template < template <
typename image_type, typename image_type,
int pixel_type = static_switch < int pixel_type = static_switch <
pixel_traits<typename image_type::type>::grayscale && sizeof(typename image_type::type) != 2, pixel_traits<typename image_type::type>::grayscale && sizeof(typename image_type::type) == 1,
pixel_traits<typename image_type::type>::rgb, pixel_traits<typename image_type::type>::rgb,
pixel_traits<typename image_type::type>::hsi, pixel_traits<typename image_type::type>::hsi,
false, false,
pixel_traits<typename image_type::type>::rgb_alpha, pixel_traits<typename image_type::type>::rgb_alpha,
false, false,
pixel_traits<typename image_type::type>::grayscale && sizeof(typename image_type::type) == 2 pixel_traits<typename image_type::type>::grayscale && sizeof(typename image_type::type) != 1
>::value >::value
> >
struct save_dng_helper; struct save_dng_helper;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment