Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
dlib
Commits
6f4c65a6
Commit
6f4c65a6
authored
May 27, 2011
by
Davis King
Browse files
updated png_loader so it can load 16bit data.
parent
b81db5eb
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
67 additions
and
4 deletions
+67
-4
dlib/image_loader/png_loader.cpp
dlib/image_loader/png_loader.cpp
+11
-1
dlib/image_loader/png_loader.h
dlib/image_loader/png_loader.h
+48
-3
dlib/image_loader/png_loader_abstract.h
dlib/image_loader/png_loader_abstract.h
+8
-0
No files found.
dlib/image_loader/png_loader.cpp
View file @
6f4c65a6
...
...
@@ -11,6 +11,7 @@
#include "../dir_nav.h"
#include "png_loader.h"
#include <png.h>
#include "../string.h"
namespace
dlib
{
...
...
@@ -154,12 +155,14 @@ namespace dlib
png_init_io
(
ld_
->
png_ptr_
,
fp
);
png_set_sig_bytes
(
ld_
->
png_ptr_
,
8
);
// flags force one byte per channel output
png_read_png
(
ld_
->
png_ptr_
,
ld_
->
info_ptr_
,
PNG_TRANSFORM_STRIP_16
|
PNG_TRANSFORM_PACKING
,
NULL
);
png_read_png
(
ld_
->
png_ptr_
,
ld_
->
info_ptr_
,
PNG_TRANSFORM_PACKING
,
NULL
);
height_
=
png_get_image_height
(
ld_
->
png_ptr_
,
ld_
->
info_ptr_
);
width_
=
png_get_image_width
(
ld_
->
png_ptr_
,
ld_
->
info_ptr_
);
bit_depth_
=
png_get_bit_depth
(
ld_
->
png_ptr_
,
ld_
->
info_ptr_
);
color_type_
=
png_get_color_type
(
ld_
->
png_ptr_
,
ld_
->
info_ptr_
);
std
::
cout
<<
"bit_depth_: "
<<
bit_depth_
<<
std
::
endl
;
if
(
color_type_
!=
PNG_COLOR_TYPE_GRAY
&&
color_type_
!=
PNG_COLOR_TYPE_RGB
&&
color_type_
!=
PNG_COLOR_TYPE_RGB_ALPHA
)
...
...
@@ -169,6 +172,13 @@ namespace dlib
throw
image_load_error
(
std
::
string
(
"png_loader: unsupported color type in file "
)
+
filename
);
}
if
(
bit_depth_
!=
8
&&
bit_depth_
!=
16
)
{
fclose
(
fp
);
png_destroy_read_struct
(
&
(
ld_
->
png_ptr_
),
&
(
ld_
->
info_ptr_
),
&
(
ld_
->
end_info_
)
);
throw
image_load_error
(
"png_loader: unsupported bit depth of "
+
cast_to_string
(
bit_depth_
)
+
" in file "
+
std
::
string
(
filename
));
}
ld_
->
row_pointers_
=
png_get_rows
(
ld_
->
png_ptr_
,
ld_
->
info_ptr_
);
fclose
(
fp
);
...
...
dlib/image_loader/png_loader.h
View file @
6f4c65a6
...
...
@@ -26,6 +26,8 @@ namespace dlib
bool
is_rgb
()
const
;
bool
is_rgba
()
const
;
unsigned
int
bit_depth
()
const
{
return
bit_depth_
;
}
template
<
typename
T
>
void
get_image
(
T
&
t
)
const
{
...
...
@@ -42,7 +44,7 @@ namespace dlib
t
.
set_size
(
height_
,
width_
);
if
(
is_gray
())
if
(
is_gray
()
&&
bit_depth_
==
8
)
{
for
(
unsigned
n
=
0
;
n
<
height_
;
n
++
)
{
...
...
@@ -54,7 +56,19 @@ namespace dlib
}
}
}
else
if
(
is_rgb
())
else
if
(
is_gray
()
&&
bit_depth_
==
16
)
{
for
(
unsigned
n
=
0
;
n
<
height_
;
n
++
)
{
const
uint16
*
v
=
(
uint16
*
)
get_row
(
n
);
for
(
unsigned
m
=
0
;
m
<
width_
;
m
++
)
{
dlib
::
uint16
p
=
v
[
m
];
assign_pixel
(
t
[
n
][
m
],
p
);
}
}
}
else
if
(
is_rgb
()
&&
bit_depth_
==
8
)
{
for
(
unsigned
n
=
0
;
n
<
height_
;
n
++
)
{
...
...
@@ -69,7 +83,22 @@ namespace dlib
}
}
}
else
if
(
is_rgba
())
else
if
(
is_rgb
()
&&
bit_depth_
==
16
)
{
for
(
unsigned
n
=
0
;
n
<
height_
;
n
++
)
{
const
uint16
*
v
=
(
uint16
*
)
get_row
(
n
);
for
(
unsigned
m
=
0
;
m
<
width_
;
m
++
)
{
rgb_pixel
p
;
p
.
red
=
static_cast
<
uint8
>
(
v
[
m
*
3
]);
p
.
green
=
static_cast
<
uint8
>
(
v
[
m
*
3
+
1
]);
p
.
blue
=
static_cast
<
uint8
>
(
v
[
m
*
3
+
2
]);
assign_pixel
(
t
[
n
][
m
],
p
);
}
}
}
else
if
(
is_rgba
()
&&
bit_depth_
==
8
)
{
for
(
unsigned
n
=
0
;
n
<
height_
;
n
++
)
{
...
...
@@ -85,6 +114,22 @@ namespace dlib
}
}
}
else
if
(
is_rgba
()
&&
bit_depth_
==
16
)
{
for
(
unsigned
n
=
0
;
n
<
height_
;
n
++
)
{
const
uint16
*
v
=
(
uint16
*
)
get_row
(
n
);
for
(
unsigned
m
=
0
;
m
<
width_
;
m
++
)
{
rgb_alpha_pixel
p
;
p
.
red
=
static_cast
<
uint8
>
(
v
[
m
*
4
]);
p
.
green
=
static_cast
<
uint8
>
(
v
[
m
*
4
+
1
]);
p
.
blue
=
static_cast
<
uint8
>
(
v
[
m
*
4
+
2
]);
p
.
alpha
=
static_cast
<
uint8
>
(
v
[
m
*
4
+
3
]);
assign_pixel
(
t
[
n
][
m
],
p
);
}
}
}
}
private:
...
...
dlib/image_loader/png_loader_abstract.h
View file @
6f4c65a6
...
...
@@ -101,6 +101,14 @@ namespace dlib
- returns false
!*/
unsigned
int
bit_depth
(
)
const
;
/*!
ensures
- returns the number of bits per channel in the image contained by this
object. The possible values are 8 or 16.
!*/
template
<
typename
image_type
>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment