Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv
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
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
opencv
Commits
525b6eca
Commit
525b6eca
authored
Aug 26, 2013
by
Roman Donchenko
Committed by
OpenCV Buildbot
Aug 26, 2013
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1311 from leszekhanusz:png_palette_alpha
parents
b43890a7
32635a68
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
111 additions
and
10 deletions
+111
-10
grfmt_png.cpp
modules/highgui/src/grfmt_png.cpp
+19
-10
test_grfmt.cpp
modules/highgui/test/test_grfmt.cpp
+92
-0
No files found.
modules/highgui/src/grfmt_png.cpp
View file @
525b6eca
...
...
@@ -171,7 +171,9 @@ bool PngDecoder::readHeader()
if
(
!
m_buf
.
empty
()
||
m_f
)
{
png_uint_32
wdth
,
hght
;
int
bit_depth
,
color_type
;
int
bit_depth
,
color_type
,
num_trans
=
0
;
png_bytep
trans
;
png_color_16p
trans_values
;
png_read_info
(
png_ptr
,
info_ptr
);
...
...
@@ -187,15 +189,22 @@ bool PngDecoder::readHeader()
{
switch
(
color_type
)
{
case
PNG_COLOR_TYPE_RGB
:
case
PNG_COLOR_TYPE_PALETTE
:
m_type
=
CV_8UC3
;
break
;
case
PNG_COLOR_TYPE_RGB_ALPHA
:
m_type
=
CV_8UC4
;
break
;
default
:
m_type
=
CV_8UC1
;
case
PNG_COLOR_TYPE_RGB
:
m_type
=
CV_8UC3
;
break
;
case
PNG_COLOR_TYPE_PALETTE
:
png_get_tRNS
(
png_ptr
,
info_ptr
,
&
trans
,
&
num_trans
,
&
trans_values
);
//Check if there is a transparency value in the palette
if
(
num_trans
>
0
)
m_type
=
CV_8UC4
;
else
m_type
=
CV_8UC3
;
break
;
case
PNG_COLOR_TYPE_RGB_ALPHA
:
m_type
=
CV_8UC4
;
break
;
default
:
m_type
=
CV_8UC1
;
}
if
(
bit_depth
==
16
)
m_type
=
CV_MAKETYPE
(
CV_16U
,
CV_MAT_CN
(
m_type
));
...
...
modules/highgui/test/test_grfmt.cpp
View file @
525b6eca
...
...
@@ -280,6 +280,98 @@ TEST(Highgui_ImreadVSCvtColor, regression)
EXPECT_LT
(
actual_avg_diff
,
MAX_MEAN_DIFF
);
EXPECT_LT
(
actual_maxval
,
MAX_ABS_DIFF
);
}
//Test OpenCV issue 3075 is solved
class
CV_GrfmtReadPNGColorPaletteWithAlphaTest
:
public
cvtest
::
BaseTest
{
public
:
void
run
(
int
)
{
try
{
// First Test : Read PNG with alpha, imread flag -1
Mat
img
=
imread
(
string
(
ts
->
get_data_path
())
+
"readwrite/color_palette_alpha.png"
,
-
1
);
if
(
img
.
empty
())
ts
->
set_failed_test_info
(
cvtest
::
TS
::
FAIL_INVALID_TEST_DATA
);
ASSERT_TRUE
(
img
.
channels
()
==
4
);
unsigned
char
*
img_data
=
(
unsigned
char
*
)
img
.
data
;
// Verification first pixel is red in BGRA
ASSERT_TRUE
(
img_data
[
0
]
==
0x00
);
ASSERT_TRUE
(
img_data
[
1
]
==
0x00
);
ASSERT_TRUE
(
img_data
[
2
]
==
0xFF
);
ASSERT_TRUE
(
img_data
[
3
]
==
0xFF
);
// Verification second pixel is red in BGRA
ASSERT_TRUE
(
img_data
[
4
]
==
0x00
);
ASSERT_TRUE
(
img_data
[
5
]
==
0x00
);
ASSERT_TRUE
(
img_data
[
6
]
==
0xFF
);
ASSERT_TRUE
(
img_data
[
7
]
==
0xFF
);
// Second Test : Read PNG without alpha, imread flag -1
img
=
imread
(
string
(
ts
->
get_data_path
())
+
"readwrite/color_palette_no_alpha.png"
,
-
1
);
if
(
img
.
empty
())
ts
->
set_failed_test_info
(
cvtest
::
TS
::
FAIL_INVALID_TEST_DATA
);
ASSERT_TRUE
(
img
.
channels
()
==
3
);
img_data
=
(
unsigned
char
*
)
img
.
data
;
// Verification first pixel is red in BGR
ASSERT_TRUE
(
img_data
[
0
]
==
0x00
);
ASSERT_TRUE
(
img_data
[
1
]
==
0x00
);
ASSERT_TRUE
(
img_data
[
2
]
==
0xFF
);
// Verification second pixel is red in BGR
ASSERT_TRUE
(
img_data
[
3
]
==
0x00
);
ASSERT_TRUE
(
img_data
[
4
]
==
0x00
);
ASSERT_TRUE
(
img_data
[
5
]
==
0xFF
);
// Third Test : Read PNG with alpha, imread flag 1
img
=
imread
(
string
(
ts
->
get_data_path
())
+
"readwrite/color_palette_alpha.png"
,
1
);
if
(
img
.
empty
())
ts
->
set_failed_test_info
(
cvtest
::
TS
::
FAIL_INVALID_TEST_DATA
);
ASSERT_TRUE
(
img
.
channels
()
==
3
);
img_data
=
(
unsigned
char
*
)
img
.
data
;
// Verification first pixel is red in BGR
ASSERT_TRUE
(
img_data
[
0
]
==
0x00
);
ASSERT_TRUE
(
img_data
[
1
]
==
0x00
);
ASSERT_TRUE
(
img_data
[
2
]
==
0xFF
);
// Verification second pixel is red in BGR
ASSERT_TRUE
(
img_data
[
3
]
==
0x00
);
ASSERT_TRUE
(
img_data
[
4
]
==
0x00
);
ASSERT_TRUE
(
img_data
[
5
]
==
0xFF
);
// Fourth Test : Read PNG without alpha, imread flag 1
img
=
imread
(
string
(
ts
->
get_data_path
())
+
"readwrite/color_palette_no_alpha.png"
,
1
);
if
(
img
.
empty
())
ts
->
set_failed_test_info
(
cvtest
::
TS
::
FAIL_INVALID_TEST_DATA
);
ASSERT_TRUE
(
img
.
channels
()
==
3
);
img_data
=
(
unsigned
char
*
)
img
.
data
;
// Verification first pixel is red in BGR
ASSERT_TRUE
(
img_data
[
0
]
==
0x00
);
ASSERT_TRUE
(
img_data
[
1
]
==
0x00
);
ASSERT_TRUE
(
img_data
[
2
]
==
0xFF
);
// Verification second pixel is red in BGR
ASSERT_TRUE
(
img_data
[
3
]
==
0x00
);
ASSERT_TRUE
(
img_data
[
4
]
==
0x00
);
ASSERT_TRUE
(
img_data
[
5
]
==
0xFF
);
}
catch
(...)
{
ts
->
set_failed_test_info
(
cvtest
::
TS
::
FAIL_EXCEPTION
);
}
ts
->
set_failed_test_info
(
cvtest
::
TS
::
OK
);
}
};
TEST
(
Highgui_Image
,
read_png_color_palette_with_alpha
)
{
CV_GrfmtReadPNGColorPaletteWithAlphaTest
test
;
test
.
safe_run
();
}
#endif
#ifdef HAVE_JPEG
...
...
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