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
97d6125f
Commit
97d6125f
authored
Sep 01, 2013
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Made the PNG loader able to load in grayscale images with an alpha channel.
parent
f2a52a47
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
68 additions
and
2 deletions
+68
-2
png_loader.cpp
dlib/image_loader/png_loader.cpp
+9
-1
png_loader.h
dlib/image_loader/png_loader.h
+48
-0
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