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
a2a6e00f
Commit
a2a6e00f
authored
Feb 08, 2016
by
Davis King
Browse files
Fixed GIF reader so it works on a wider variety of GIF files.
parent
9c48b871
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
11 deletions
+13
-11
dlib/image_loader/load_image.h
dlib/image_loader/load_image.h
+13
-11
No files found.
dlib/image_loader/load_image.h
View file @
a2a6e00f
...
@@ -82,28 +82,30 @@ namespace dlib
...
@@ -82,28 +82,30 @@ namespace dlib
GifFileType
*
gif
=
DGifOpenFileName
(
file_name
.
c_str
());
GifFileType
*
gif
=
DGifOpenFileName
(
file_name
.
c_str
());
try
try
{
{
if
(
gif
==
0
)
if
(
gif
==
0
)
throw
image_load_error
(
"Couldn't open file "
+
file_name
);
throw
image_load_error
(
"Couldn't open file "
+
file_name
);
if
(
DGifSlurp
(
gif
)
!=
GIF_OK
)
if
(
DGifSlurp
(
gif
)
!=
GIF_OK
)
throw
image_load_error
(
"Error reading from "
+
file_name
);
throw
image_load_error
(
"Error reading from "
+
file_name
);
if
(
gif
->
ImageCount
!=
1
)
throw
image_load_error
(
"Dlib only supports reading GIF files containing one image."
);
if
(
gif
->
ImageCount
!=
1
)
throw
image_load_error
(
"Dlib only supports reading GIF files containing one image."
);
if
(
gif
->
SColorMap
==
0
)
throw
image_load_error
(
"Unsupported GIF format 1."
);
if
(
gif
->
SavedImages
==
0
)
throw
image_load_error
(
"Unsupported GIF format 1."
);
if
(
gif
->
SavedImages
==
0
)
throw
image_load_error
(
"Unsupported GIF format 2."
);
if
(
gif
->
SavedImages
->
ImageDesc
.
Width
!=
gif
->
SWidth
)
throw
image_load_error
(
"Unsupported GIF format 3."
);
ColorMapObject
*
cmo
=
gif
->
SColorMap
?
gif
->
SColorMap
:
gif
->
SavedImages
->
ImageDesc
.
ColorMap
;
if
(
gif
->
SavedImages
->
ImageDesc
.
Height
!=
gif
->
SHeight
)
throw
image_load_error
(
"Unsupported GIF format 4."
);
if
(
gif
->
SColorMap
->
ColorCount
!=
256
)
throw
image_load_error
(
"Unsupported GIF format 5."
);
if
(
cmo
==
0
)
throw
image_load_error
(
"Unsupported GIF format 2."
);
if
(
gif
->
SColorMap
->
BitsPerPixel
!=
8
)
throw
image_load_error
(
"Unsupported GIF format 6."
);
if
(
cmo
->
Colors
==
0
)
throw
image_load_error
(
"Unsupported GIF format 3."
);
if
(
gif
->
SavedImages
->
RasterBits
==
0
)
throw
image_load_error
(
"Unsupported GIF format 7."
);
if
(
gif
->
SavedImages
->
ImageDesc
.
Width
!=
gif
->
SWidth
)
throw
image_load_error
(
"Unsupported GIF format 4."
);
if
(
gif
->
SColorMap
->
Colors
==
0
)
throw
image_load_error
(
"Unsupported GIF format 8."
);
if
(
gif
->
SavedImages
->
ImageDesc
.
Height
!=
gif
->
SHeight
)
throw
image_load_error
(
"Unsupported GIF format 5."
);
if
(
gif
->
SavedImages
->
RasterBits
==
0
)
throw
image_load_error
(
"Unsupported GIF format 6."
);
img
.
set_size
(
gif
->
SHeight
,
gif
->
SWidth
);
img
.
set_size
(
gif
->
SHeight
,
gif
->
SWidth
);
unsigned
char
*
raster
=
gif
->
SavedImages
->
RasterBits
;
unsigned
char
*
raster
=
gif
->
SavedImages
->
RasterBits
;
GifColorType
*
colormap
=
gif
->
SColorMap
->
Colors
;
GifColorType
*
colormap
=
cmo
->
Colors
;
for
(
long
r
=
0
;
r
<
img
.
nr
();
++
r
)
for
(
long
r
=
0
;
r
<
img
.
nr
();
++
r
)
{
{
for
(
long
c
=
0
;
c
<
img
.
nc
();
++
c
)
for
(
long
c
=
0
;
c
<
img
.
nc
();
++
c
)
{
{
if
(
*
raster
>=
cmo
->
ColorCount
)
throw
image_load_error
(
"Invalid GIF color value"
);
rgb_pixel
p
;
rgb_pixel
p
;
p
.
red
=
colormap
[
*
raster
].
Red
;
p
.
red
=
colormap
[
*
raster
].
Red
;
p
.
green
=
colormap
[
*
raster
].
Green
;
p
.
green
=
colormap
[
*
raster
].
Green
;
...
...
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