Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
D
dlib
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
钟尚武
dlib
Commits
6f4c65a6
Commit
6f4c65a6
authored
May 27, 2011
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updated png_loader so it can load 16bit data.
parent
b81db5eb
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
67 additions
and
4 deletions
+67
-4
png_loader.cpp
dlib/image_loader/png_loader.cpp
+11
-1
png_loader.h
dlib/image_loader/png_loader.h
+48
-3
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