Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
bob
bob.io.image
Commits
e51d59da
Commit
e51d59da
authored
Mar 01, 2017
by
Manuel Günther
Committed by
André Anjos
Aug 25, 2018
Browse files
Reading all records from the image; use only the first image inside the GIF
parent
1ec669e8
Changes
1
Hide whitespace changes
Inline
Side-by-side
bob/io/image/cpp/gif.cpp
View file @
e51d59da
...
...
@@ -416,51 +416,65 @@ static void im_load_color(boost::shared_ptr<GifFileType> in_file, bob::io::base:
int
InterlacedOffset
[]
=
{
0
,
4
,
2
,
1
};
// The way Interlaced image should.
int
InterlacedJumps
[]
=
{
8
,
8
,
4
,
2
};
// be read - offsets and jumps...
int
row
,
col
,
width
,
height
,
count
,
ext_code
;
int
error
=
DGifGetRecordType
(
in_file
.
get
(),
&
record_type
);
if
(
error
==
GIF_ERROR
)
GifErrorHandler
(
"DGifGetRecordType"
,
error
);
switch
(
record_type
)
{
case
IMAGE_DESC_RECORD_TYPE
:
error
=
DGifGetImageDesc
(
in_file
.
get
());
if
(
error
==
GIF_ERROR
)
GifErrorHandler
(
"DGifGetImageDesc"
,
error
);
row
=
in_file
->
Image
.
Top
;
// Image Position relative to Screen.
col
=
in_file
->
Image
.
Left
;
width
=
in_file
->
Image
.
Width
;
height
=
in_file
->
Image
.
Height
;
if
(
in_file
->
Image
.
Left
+
in_file
->
Image
.
Width
>
in_file
->
SWidth
||
in_file
->
Image
.
Top
+
in_file
->
Image
.
Height
>
in_file
->
SHeight
)
{
throw
std
::
runtime_error
(
"GIF: the dimensions of image larger than the dimensions of the canvas."
);
}
if
(
in_file
->
Image
.
Interlace
)
{
// Need to perform 4 passes on the images:
for
(
int
i
=
count
=
0
;
i
<
4
;
++
i
)
for
(
int
j
=
row
+
InterlacedOffset
[
i
];
j
<
row
+
height
;
j
+=
InterlacedJumps
[
i
])
{
++
count
;
error
=
DGifGetLine
(
in_file
.
get
(),
&
screen_buffer
[
j
][
col
],
width
);
bool
terminated
=
false
;
bool
image_found
=
false
;
do
{
int
error
=
DGifGetRecordType
(
in_file
.
get
(),
&
record_type
);
if
(
error
==
GIF_ERROR
)
GifErrorHandler
(
"DGifGetRecordType"
,
error
);
switch
(
record_type
)
{
case
IMAGE_DESC_RECORD_TYPE
:
if
(
image_found
){
// we already have found an image...
break
;
}
error
=
DGifGetImageDesc
(
in_file
.
get
());
if
(
error
==
GIF_ERROR
)
GifErrorHandler
(
"DGifGetImageDesc"
,
error
);
row
=
in_file
->
Image
.
Top
;
// Image Position relative to Screen.
col
=
in_file
->
Image
.
Left
;
width
=
in_file
->
Image
.
Width
;
height
=
in_file
->
Image
.
Height
;
if
(
in_file
->
Image
.
Left
+
in_file
->
Image
.
Width
>
in_file
->
SWidth
||
in_file
->
Image
.
Top
+
in_file
->
Image
.
Height
>
in_file
->
SHeight
)
{
throw
std
::
runtime_error
(
"GIF: the dimensions of image larger than the dimensions of the canvas."
);
}
if
(
in_file
->
Image
.
Interlace
)
{
// Need to perform 4 passes on the images:
for
(
int
i
=
count
=
0
;
i
<
4
;
++
i
)
for
(
int
j
=
row
+
InterlacedOffset
[
i
];
j
<
row
+
height
;
j
+=
InterlacedJumps
[
i
])
{
++
count
;
error
=
DGifGetLine
(
in_file
.
get
(),
&
screen_buffer
[
j
][
col
],
width
);
if
(
error
==
GIF_ERROR
)
GifErrorHandler
(
"DGifGetLine"
,
error
);
}
}
else
{
for
(
int
i
=
0
;
i
<
height
;
++
i
)
{
error
=
DGifGetLine
(
in_file
.
get
(),
&
screen_buffer
[
row
++
][
col
],
width
);
if
(
error
==
GIF_ERROR
)
GifErrorHandler
(
"DGifGetLine"
,
error
);
}
}
else
{
for
(
int
i
=
0
;
i
<
height
;
++
i
)
{
error
=
DGifGetLine
(
in_file
.
get
(),
&
screen_buffer
[
row
++
][
col
],
width
);
if
(
error
==
GIF_ERROR
)
GifErrorHandler
(
"DGifGetLine"
,
error
);
}
}
break
;
case
EXTENSION_RECORD_TYPE
:
// Skip any extension blocks in file:
error
=
DGifGetExtension
(
in_file
.
get
(),
&
ext_code
,
&
extension
);
if
(
error
==
GIF_ERROR
)
GifErrorHandler
(
"DGifGetExtension"
,
error
);
while
(
extension
!=
NULL
)
{
error
=
DGifGetExtensionNext
(
in_file
.
get
(),
&
extension
);
if
(
error
==
GIF_ERROR
)
GifErrorHandler
(
"DGifGetExtensionNext"
,
error
);
}
break
;
case
TERMINATE_RECORD_TYPE
:
break
;
default:
// Should be trapped by DGifGetRecordType.
break
;
image_found
=
true
;
break
;
case
EXTENSION_RECORD_TYPE
:
// Skip any extension blocks in file:
error
=
DGifGetExtension
(
in_file
.
get
(),
&
ext_code
,
&
extension
);
if
(
error
==
GIF_ERROR
)
GifErrorHandler
(
"DGifGetExtension"
,
error
);
while
(
extension
!=
NULL
)
{
error
=
DGifGetExtensionNext
(
in_file
.
get
(),
&
extension
);
if
(
error
==
GIF_ERROR
)
GifErrorHandler
(
"DGifGetExtensionNext"
,
error
);
}
break
;
case
TERMINATE_RECORD_TYPE
:
terminated
=
true
;
break
;
default:
// Should be trapped by DGifGetRecordType.
break
;
}
}
while
(
!
terminated
);
if
(
!
image_found
){
std
::
runtime_error
(
"GIF: image does not contain an image section"
);
}
// Lets dump it - set the global variables required and do it:
...
...
Write
Preview
Supports
Markdown
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