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
a2a6e00f
Commit
a2a6e00f
authored
Feb 08, 2016
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed GIF reader so it works on a wider variety of GIF files.
parent
9c48b871
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
11 deletions
+13
-11
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
GifFileType
*
gif
=
DGifOpenFileName
(
file_name
.
c_str
());
try
{
if
(
gif
==
0
)
throw
image_load_error
(
"Couldn't open file "
+
file_name
);
if
(
gif
==
0
)
throw
image_load_error
(
"Couldn't open file "
+
file_name
);
if
(
DGifSlurp
(
gif
)
!=
GIF_OK
)
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
->
SColorMap
==
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."
);
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
(
gif
->
SColorMap
->
BitsPerPixel
!=
8
)
throw
image_load_error
(
"Unsupported GIF format 6."
);
if
(
gif
->
SavedImages
->
RasterBits
==
0
)
throw
image_load_error
(
"Unsupported GIF format 7."
);
if
(
gif
->
SColorMap
->
Colors
==
0
)
throw
image_load_error
(
"Unsupported GIF format 8."
);
if
(
gif
->
SavedImages
==
0
)
throw
image_load_error
(
"Unsupported GIF format 1."
);
ColorMapObject
*
cmo
=
gif
->
SColorMap
?
gif
->
SColorMap
:
gif
->
SavedImages
->
ImageDesc
.
ColorMap
;
if
(
cmo
==
0
)
throw
image_load_error
(
"Unsupported GIF format 2."
);
if
(
cmo
->
Colors
==
0
)
throw
image_load_error
(
"Unsupported GIF format 3."
);
if
(
gif
->
SavedImages
->
ImageDesc
.
Width
!=
gif
->
SWidth
)
throw
image_load_error
(
"Unsupported GIF format 4."
);
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
);
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
c
=
0
;
c
<
img
.
nc
();
++
c
)
{
if
(
*
raster
>=
cmo
->
ColorCount
)
throw
image_load_error
(
"Invalid GIF color value"
);
rgb_pixel
p
;
p
.
red
=
colormap
[
*
raster
].
Red
;
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