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
97d6125f
Commit
97d6125f
authored
Sep 01, 2013
by
Davis King
Browse files
Made the PNG loader able to load in grayscale images with an alpha channel.
parent
f2a52a47
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
68 additions
and
2 deletions
+68
-2
dlib/image_loader/png_loader.cpp
dlib/image_loader/png_loader.cpp
+9
-1
dlib/image_loader/png_loader.h
dlib/image_loader/png_loader.h
+48
-0
dlib/image_loader/png_loader_abstract.h
dlib/image_loader/png_loader_abstract.h
+11
-1
No files found.
dlib/image_loader/png_loader.cpp
View file @
97d6125f
...
@@ -73,6 +73,13 @@ namespace dlib
...
@@ -73,6 +73,13 @@ namespace dlib
return
(
color_type_
==
PNG_COLOR_TYPE_GRAY
);
return
(
color_type_
==
PNG_COLOR_TYPE_GRAY
);
}
}
// ----------------------------------------------------------------------------------------
bool
png_loader
::
is_graya
()
const
{
return
(
color_type_
==
PNG_COLOR_TYPE_GRAY_ALPHA
);
}
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
bool
png_loader
::
is_rgb
()
const
bool
png_loader
::
is_rgb
()
const
...
@@ -169,7 +176,8 @@ namespace dlib
...
@@ -169,7 +176,8 @@ namespace dlib
if
(
color_type_
!=
PNG_COLOR_TYPE_GRAY
&&
if
(
color_type_
!=
PNG_COLOR_TYPE_GRAY
&&
color_type_
!=
PNG_COLOR_TYPE_RGB
&&
color_type_
!=
PNG_COLOR_TYPE_RGB
&&
color_type_
!=
PNG_COLOR_TYPE_RGB_ALPHA
)
color_type_
!=
PNG_COLOR_TYPE_RGB_ALPHA
&&
color_type_
!=
PNG_COLOR_TYPE_GRAY_ALPHA
)
{
{
fclose
(
fp
);
fclose
(
fp
);
png_destroy_read_struct
(
&
(
ld_
->
png_ptr_
),
&
(
ld_
->
info_ptr_
),
&
(
ld_
->
end_info_
)
);
png_destroy_read_struct
(
&
(
ld_
->
png_ptr_
),
&
(
ld_
->
info_ptr_
),
&
(
ld_
->
end_info_
)
);
...
...
dlib/image_loader/png_loader.h
View file @
97d6125f
...
@@ -23,6 +23,7 @@ namespace dlib
...
@@ -23,6 +23,7 @@ namespace dlib
~
png_loader
();
~
png_loader
();
bool
is_gray
()
const
;
bool
is_gray
()
const
;
bool
is_graya
()
const
;
bool
is_rgb
()
const
;
bool
is_rgb
()
const
;
bool
is_rgba
()
const
;
bool
is_rgba
()
const
;
...
@@ -41,6 +42,7 @@ namespace dlib
...
@@ -41,6 +42,7 @@ namespace dlib
COMPILE_TIME_ASSERT
(
sizeof
(
T
)
==
0
);
COMPILE_TIME_ASSERT
(
sizeof
(
T
)
==
0
);
#endif
#endif
typedef
typename
T
::
type
pixel_type
;
t
.
set_size
(
height_
,
width_
);
t
.
set_size
(
height_
,
width_
);
...
@@ -68,6 +70,52 @@ namespace dlib
...
@@ -68,6 +70,52 @@ namespace dlib
}
}
}
}
}
}
else
if
(
is_graya
()
&&
bit_depth_
==
8
)
{
for
(
unsigned
n
=
0
;
n
<
height_
;
n
++
)
{
const
unsigned
char
*
v
=
get_row
(
n
);
for
(
unsigned
m
=
0
;
m
<
width_
;
m
++
)
{
unsigned
char
p
=
v
[
m
*
2
];
if
(
!
pixel_traits
<
pixel_type
>::
has_alpha
)
{
assign_pixel
(
t
[
n
][
m
],
p
);
}
else
{
unsigned
char
pa
=
v
[
m
*
2
+
1
];
rgb_alpha_pixel
pix
;
assign_pixel
(
pix
,
p
);
assign_pixel
(
pix
.
alpha
,
pa
);
assign_pixel
(
t
[
n
][
m
],
pix
);
}
}
}
}
else
if
(
is_graya
()
&&
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
*
2
];
if
(
!
pixel_traits
<
pixel_type
>::
has_alpha
)
{
assign_pixel
(
t
[
n
][
m
],
p
);
}
else
{
dlib
::
uint16
pa
=
v
[
m
*
2
+
1
];
rgb_alpha_pixel
pix
;
assign_pixel
(
pix
,
p
);
assign_pixel
(
pix
.
alpha
,
pa
);
assign_pixel
(
t
[
n
][
m
],
pix
);
}
}
}
}
else
if
(
is_rgb
()
&&
bit_depth_
==
8
)
else
if
(
is_rgb
()
&&
bit_depth_
==
8
)
{
{
for
(
unsigned
n
=
0
;
n
<
height_
;
n
++
)
for
(
unsigned
n
=
0
;
n
<
height_
;
n
++
)
...
...
dlib/image_loader/png_loader_abstract.h
View file @
97d6125f
...
@@ -75,7 +75,17 @@ namespace dlib
...
@@ -75,7 +75,17 @@ namespace dlib
)
const
;
)
const
;
/*!
/*!
ensures
ensures
- if (this object contains a grayscale image) then
- if (this object contains a grayscale image without an alpha channel) then
- returns true
- else
- returns false
!*/
bool
is_graya
(
)
const
;
/*!
ensures
- if (this object contains a grayscale image with an alpha channel) then
- returns true
- returns true
- else
- else
- returns false
- returns false
...
...
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