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
715e19dd
Commit
715e19dd
authored
May 28, 2011
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added some unit tests for the save_png() and load_png() functions.
parent
eaa0b45c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
240 additions
and
2 deletions
+240
-2
image.cpp
dlib/test/image.cpp
+240
-2
No files found.
dlib/test/image.cpp
View file @
715e19dd
...
@@ -144,6 +144,45 @@ namespace
...
@@ -144,6 +144,45 @@ namespace
}
}
}
}
#ifdef DLIB_PNG_SUPPORT
{
array2d
<
rgb_alpha_pixel
>
img
;
img
.
set_size
(
14
,
15
);
for
(
long
r
=
0
;
r
<
14
;
++
r
)
{
for
(
long
c
=
0
;
c
<
15
;
++
c
)
{
img
[
r
][
c
].
red
=
static_cast
<
unsigned
char
>
(
r
*
14
+
c
+
1
);
img
[
r
][
c
].
green
=
static_cast
<
unsigned
char
>
(
r
*
14
+
c
+
2
);
img
[
r
][
c
].
blue
=
static_cast
<
unsigned
char
>
(
r
*
14
+
c
+
3
);
img
[
r
][
c
].
alpha
=
static_cast
<
unsigned
char
>
(
r
*
14
+
c
+
4
);
}
}
save_png
(
img
,
"test.png"
);
img
.
clear
();
DLIB_TEST
(
img
.
nr
()
==
0
);
DLIB_TEST
(
img
.
nc
()
==
0
);
load_png
(
img
,
"test.png"
);
DLIB_TEST
(
img
.
nr
()
==
14
);
DLIB_TEST
(
img
.
nc
()
==
15
);
for
(
long
r
=
0
;
r
<
14
;
++
r
)
{
for
(
long
c
=
0
;
c
<
15
;
++
c
)
{
DLIB_TEST
(
img
[
r
][
c
].
red
==
r
*
14
+
c
+
1
);
DLIB_TEST
(
img
[
r
][
c
].
green
==
r
*
14
+
c
+
2
);
DLIB_TEST
(
img
[
r
][
c
].
blue
==
r
*
14
+
c
+
3
);
DLIB_TEST
(
img
[
r
][
c
].
alpha
==
r
*
14
+
c
+
4
);
}
}
}
#endif // DLIB_PNG_SUPPORT
{
{
...
@@ -207,7 +246,138 @@ namespace
...
@@ -207,7 +246,138 @@ namespace
}
}
}
}
}
}
{
array2d
<
bgr_pixel
>
img
;
img
.
set_size
(
14
,
15
);
for
(
long
r
=
0
;
r
<
14
;
++
r
)
{
for
(
long
c
=
0
;
c
<
15
;
++
c
)
{
img
[
r
][
c
].
red
=
static_cast
<
unsigned
char
>
(
r
*
14
+
c
+
1
);
img
[
r
][
c
].
green
=
static_cast
<
unsigned
char
>
(
r
*
14
+
c
+
2
);
img
[
r
][
c
].
blue
=
static_cast
<
unsigned
char
>
(
r
*
14
+
c
+
3
);
}
}
ostringstream
sout
;
save_dng
(
img
,
sout
);
save_bmp
(
img
,
sout
);
save_dng
(
img
,
sout
);
save_bmp
(
img
,
sout
);
istringstream
sin
(
sout
.
str
());
for
(
int
i
=
0
;
i
<
2
;
++
i
)
{
img
.
clear
();
DLIB_TEST
(
img
.
nr
()
==
0
);
DLIB_TEST
(
img
.
nc
()
==
0
);
load_dng
(
img
,
sin
);
DLIB_TEST
(
img
.
nr
()
==
14
);
DLIB_TEST
(
img
.
nc
()
==
15
);
for
(
long
r
=
0
;
r
<
14
;
++
r
)
{
for
(
long
c
=
0
;
c
<
15
;
++
c
)
{
DLIB_TEST
(
img
[
r
][
c
].
red
==
r
*
14
+
c
+
1
);
DLIB_TEST
(
img
[
r
][
c
].
green
==
r
*
14
+
c
+
2
);
DLIB_TEST
(
img
[
r
][
c
].
blue
==
r
*
14
+
c
+
3
);
}
}
img
.
clear
();
DLIB_TEST
(
img
.
nr
()
==
0
);
DLIB_TEST
(
img
.
nc
()
==
0
);
load_bmp
(
img
,
sin
);
DLIB_TEST
(
img
.
nr
()
==
14
);
DLIB_TEST
(
img
.
nc
()
==
15
);
for
(
long
r
=
0
;
r
<
14
;
++
r
)
{
for
(
long
c
=
0
;
c
<
15
;
++
c
)
{
DLIB_TEST_MSG
(
img
[
r
][
c
].
red
==
r
*
14
+
c
+
1
,
"got "
<<
(
int
)
img
[
r
][
c
].
red
<<
" but expected "
<<
r
*
14
+
c
+
1
);
DLIB_TEST
(
img
[
r
][
c
].
green
==
r
*
14
+
c
+
2
);
DLIB_TEST
(
img
[
r
][
c
].
blue
==
r
*
14
+
c
+
3
);
}
}
}
}
#ifdef DLIB_PNG_SUPPORT
{
array2d
<
rgb_pixel
>
img
;
img
.
set_size
(
14
,
15
);
for
(
long
r
=
0
;
r
<
14
;
++
r
)
{
for
(
long
c
=
0
;
c
<
15
;
++
c
)
{
img
[
r
][
c
].
red
=
static_cast
<
unsigned
char
>
(
r
*
14
+
c
+
1
);
img
[
r
][
c
].
green
=
static_cast
<
unsigned
char
>
(
r
*
14
+
c
+
2
);
img
[
r
][
c
].
blue
=
static_cast
<
unsigned
char
>
(
r
*
14
+
c
+
3
);
}
}
save_png
(
img
,
"test.png"
);
img
.
clear
();
DLIB_TEST
(
img
.
nr
()
==
0
);
DLIB_TEST
(
img
.
nc
()
==
0
);
load_png
(
img
,
"test.png"
);
DLIB_TEST
(
img
.
nr
()
==
14
);
DLIB_TEST
(
img
.
nc
()
==
15
);
for
(
long
r
=
0
;
r
<
14
;
++
r
)
{
for
(
long
c
=
0
;
c
<
15
;
++
c
)
{
DLIB_TEST
(
img
[
r
][
c
].
red
==
r
*
14
+
c
+
1
);
DLIB_TEST
(
img
[
r
][
c
].
green
==
r
*
14
+
c
+
2
);
DLIB_TEST
(
img
[
r
][
c
].
blue
==
r
*
14
+
c
+
3
);
}
}
}
{
array2d
<
bgr_pixel
>
img
;
img
.
set_size
(
14
,
15
);
for
(
long
r
=
0
;
r
<
14
;
++
r
)
{
for
(
long
c
=
0
;
c
<
15
;
++
c
)
{
img
[
r
][
c
].
red
=
static_cast
<
unsigned
char
>
(
r
*
14
+
c
+
1
);
img
[
r
][
c
].
green
=
static_cast
<
unsigned
char
>
(
r
*
14
+
c
+
2
);
img
[
r
][
c
].
blue
=
static_cast
<
unsigned
char
>
(
r
*
14
+
c
+
3
);
}
}
save_png
(
img
,
"test.png"
);
img
.
clear
();
DLIB_TEST
(
img
.
nr
()
==
0
);
DLIB_TEST
(
img
.
nc
()
==
0
);
load_png
(
img
,
"test.png"
);
DLIB_TEST
(
img
.
nr
()
==
14
);
DLIB_TEST
(
img
.
nc
()
==
15
);
for
(
long
r
=
0
;
r
<
14
;
++
r
)
{
for
(
long
c
=
0
;
c
<
15
;
++
c
)
{
DLIB_TEST
(
img
[
r
][
c
].
red
==
r
*
14
+
c
+
1
);
DLIB_TEST
(
img
[
r
][
c
].
green
==
r
*
14
+
c
+
2
);
DLIB_TEST
(
img
[
r
][
c
].
blue
==
r
*
14
+
c
+
3
);
}
}
}
#endif // DLIB_PNG_SUPPORT
...
@@ -218,7 +388,7 @@ namespace
...
@@ -218,7 +388,7 @@ namespace
{
{
for
(
long
c
=
0
;
c
<
15
;
++
c
)
for
(
long
c
=
0
;
c
<
15
;
++
c
)
{
{
img
[
r
][
c
]
=
static_cast
<
unsigned
short
>
(
r
*
14
+
c
+
0xF
F
);
img
[
r
][
c
]
=
static_cast
<
unsigned
short
>
(
r
*
14
+
c
+
0xF
0
);
}
}
}
}
...
@@ -239,12 +409,46 @@ namespace
...
@@ -239,12 +409,46 @@ namespace
{
{
for
(
long
c
=
0
;
c
<
15
;
++
c
)
for
(
long
c
=
0
;
c
<
15
;
++
c
)
{
{
DLIB_TEST
(
img
[
r
][
c
]
==
r
*
14
+
c
+
0xF
F
);
DLIB_TEST
(
img
[
r
][
c
]
==
r
*
14
+
c
+
0xF
0
);
}
}
}
}
}
}
#ifdef DLIB_PNG_SUPPORT
{
array2d
<
unsigned
short
>
img
;
img
.
set_size
(
14
,
15
);
for
(
long
r
=
0
;
r
<
14
;
++
r
)
{
for
(
long
c
=
0
;
c
<
15
;
++
c
)
{
img
[
r
][
c
]
=
static_cast
<
unsigned
short
>
(
r
*
14
+
c
+
0xF0
);
}
}
save_png
(
img
,
"test.png"
);
img
.
clear
();
DLIB_TEST
(
img
.
nr
()
==
0
);
DLIB_TEST
(
img
.
nc
()
==
0
);
load_png
(
img
,
"test.png"
);
DLIB_TEST
(
img
.
nr
()
==
14
);
DLIB_TEST
(
img
.
nc
()
==
15
);
for
(
long
r
=
0
;
r
<
14
;
++
r
)
{
for
(
long
c
=
0
;
c
<
15
;
++
c
)
{
DLIB_TEST
(
img
[
r
][
c
]
==
r
*
14
+
c
+
0xF0
);
}
}
}
#endif // DLIB_PNG_SUPPORT
{
{
array2d
<
unsigned
char
>
img
;
array2d
<
unsigned
char
>
img
;
...
@@ -304,6 +508,40 @@ namespace
...
@@ -304,6 +508,40 @@ namespace
}
}
#ifdef DLIB_PNG_SUPPORT
{
array2d
<
unsigned
char
>
img
;
img
.
set_size
(
14
,
15
);
for
(
long
r
=
0
;
r
<
14
;
++
r
)
{
for
(
long
c
=
0
;
c
<
15
;
++
c
)
{
img
[
r
][
c
]
=
static_cast
<
unsigned
char
>
(
r
*
14
+
c
);
}
}
save_png
(
img
,
"test.png"
);
img
.
clear
();
DLIB_TEST
(
img
.
nr
()
==
0
);
DLIB_TEST
(
img
.
nc
()
==
0
);
load_png
(
img
,
"test.png"
);
DLIB_TEST
(
img
.
nr
()
==
14
);
DLIB_TEST
(
img
.
nc
()
==
15
);
for
(
long
r
=
0
;
r
<
14
;
++
r
)
{
for
(
long
c
=
0
;
c
<
15
;
++
c
)
{
DLIB_TEST
(
img
[
r
][
c
]
==
r
*
14
+
c
);
}
}
}
#endif // DLIB_PNG_SUPPORT
{
{
// in this test we will only assign pixel values that can be
// in this test we will only assign pixel values that can be
...
...
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