GIF decode: optional error messages and fault tolerance.
Add new runtime configuration variable,
images.gif.suppressDecoderWarnings, which suppresses warning and
errors from the GIF library. It defaults to "true", which is current
behavior.
(This setting can be changed by setting the environment variable
skia_images_gif_suppressDecoderWarnings="false".)
Some conditions which were errors before are now warnings:
- If the image width or height is greater than the GIF screen width or
height (respectively) we expand the screen to hold the image.
- If the offset of the image inside the screen would place the
image outside of the screen, we shift the image to fix this.
- If the image lacks a color table, we create a default color table.
- If the image is truncated, then the rest of the image is filled with
the fill color.
In all four cases, if images.gif.suppressDecoderWarnings is set to
false, then a warning message is printed via SkDebugf.
In the event of another kind of error, SkGIFImageDecoder::onDecode()
will still return false. But with this change, if
images.gif.suppressDecoderWarnings is set to false, a description of
the error is printed via SkDebugf.
Also, added a new unit test GifTest, which tests the deconing of both
good GIf files and corrupted files that should now work with this
change. This unit test is disabled on Win32, iOS, and Mac.
BUG=skia:1689
R=scroggo@google.com
Review URL: https://codereview.chromium.org/26743002
git-svn-id: http://skia.googlecode.com/svn/trunk@11734 2bbb7eff-a529-9590-31e7-b0007b416f81
2013-10-11 18:21:56 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2013 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/codec/SkAndroidCodec.h"
|
|
|
|
#include "include/core/SkBitmap.h"
|
|
|
|
#include "include/core/SkCanvas.h"
|
|
|
|
#include "include/core/SkData.h"
|
|
|
|
#include "include/core/SkImage.h"
|
|
|
|
#include "include/core/SkStream.h"
|
|
|
|
#include "include/core/SkTypes.h"
|
|
|
|
#include "tests/CodecPriv.h"
|
|
|
|
#include "tests/Test.h"
|
|
|
|
#include "tools/Resources.h"
|
GIF decode: optional error messages and fault tolerance.
Add new runtime configuration variable,
images.gif.suppressDecoderWarnings, which suppresses warning and
errors from the GIF library. It defaults to "true", which is current
behavior.
(This setting can be changed by setting the environment variable
skia_images_gif_suppressDecoderWarnings="false".)
Some conditions which were errors before are now warnings:
- If the image width or height is greater than the GIF screen width or
height (respectively) we expand the screen to hold the image.
- If the offset of the image inside the screen would place the
image outside of the screen, we shift the image to fix this.
- If the image lacks a color table, we create a default color table.
- If the image is truncated, then the rest of the image is filled with
the fill color.
In all four cases, if images.gif.suppressDecoderWarnings is set to
false, then a warning message is printed via SkDebugf.
In the event of another kind of error, SkGIFImageDecoder::onDecode()
will still return false. But with this change, if
images.gif.suppressDecoderWarnings is set to false, a description of
the error is printed via SkDebugf.
Also, added a new unit test GifTest, which tests the deconing of both
good GIf files and corrupted files that should now work with this
change. This unit test is disabled on Win32, iOS, and Mac.
BUG=skia:1689
R=scroggo@google.com
Review URL: https://codereview.chromium.org/26743002
git-svn-id: http://skia.googlecode.com/svn/trunk@11734 2bbb7eff-a529-9590-31e7-b0007b416f81
2013-10-11 18:21:56 +00:00
|
|
|
|
2014-01-21 23:39:22 +00:00
|
|
|
static unsigned char gGIFData[] = {
|
|
|
|
0x47, 0x49, 0x46, 0x38, 0x37, 0x61, 0x03, 0x00, 0x03, 0x00, 0xe3, 0x08,
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0x00,
|
|
|
|
0xff, 0x80, 0x80, 0x80, 0x00, 0xff, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
|
|
|
|
0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
|
|
|
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
|
|
|
0xff, 0x2c, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x03, 0x00, 0x00, 0x04,
|
|
|
|
0x07, 0x50, 0x1c, 0x43, 0x40, 0x41, 0x23, 0x44, 0x00, 0x3b
|
|
|
|
};
|
|
|
|
|
|
|
|
static unsigned char gGIFDataNoColormap[] = {
|
Fix SkGifCodec bugs around truncated data
Prior to this CL, if a GIF file was truncated before reading the local
color map of a frame, incremental decode would do the wrong thing. In
onStartIncrementalDecode, we would either create a color table based on
the global color map, or we would create a dummy one with only one
color (transparent). The dummy color table is correct if there is
neither a global nor a local color map, and allows us to fill the frame
with transparent. But if more data is provided, and it includes an
actual color map and image data, one of the following can happen:
- If the created color table is smaller than the actual one, the
decoded data may include indices outside of the range of the created
color table, resulting in a crash.
- If we get lucky, and the created color table is large enough, it may
still be the wrong colors (and most likely is).
To solve this, make onStartIncrementalDecode fail if there is a local
color map that has not been read yet. A future call may read more data
and read the correct color map.
This is done by returning kIncompleteInput in
SkGifCodec::prepareToDecode if there is a local color map that has not
yet been read. (It is possible that there is no color map at all, in
which case we still need to support decoding that frame. Skip
attempting to decode in that case.)
In onGetPixels, if prepareToDecode returned kIncompleteInput, return
kInvalidInput. Although the input is technically incomplete, no future
call will provide more data (unlike in incremental decoding), and there
is nothing interesting for the client to draw. This also prevents
SkCodec from attempting to fill the data with an SkSwizzler, which has
not been created. (An alternative solution would be create the dummy
color table and an SkSwizzler, which would keep the current behavior.
But I think the new behavior of returning kInvalidInput makes more
sense.)
Add tests to verify the intended behavior:
- getPixels fails.
- startIncrementalDecode fails, but after providing more data it will
succeed and incremental decoding matches the image decoded from the
full stream.
- Both succeed if there is no color table at all.
Change-Id: Ifb52fe7f723673406a28e80c8805a552f0ac33b6
Reviewed-on: https://skia-review.googlesource.com/5758
Reviewed-by: Matt Sarett <msarett@google.com>
Commit-Queue: Leon Scroggins <scroggo@google.com>
2016-12-09 21:39:33 +00:00
|
|
|
// Header
|
|
|
|
0x47, 0x49, 0x46, 0x38, 0x39, 0x61,
|
|
|
|
// Screen descriptor
|
|
|
|
0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
// Graphics control extension
|
|
|
|
0x21, 0xf9, 0x04, 0x01, 0x0a, 0x00, 0x01, 0x00,
|
|
|
|
// Image descriptor
|
|
|
|
0x2c, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00,
|
|
|
|
// Image data
|
|
|
|
0x02, 0x02, 0x4c, 0x01, 0x00,
|
|
|
|
// Trailer
|
|
|
|
0x3b
|
2014-01-21 23:39:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static unsigned char gInterlacedGIF[] = {
|
|
|
|
0x47, 0x49, 0x46, 0x38, 0x37, 0x61, 0x09, 0x00, 0x09, 0x00, 0xe3, 0x08, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0x00, 0xff, 0x80,
|
|
|
|
0x80, 0x80, 0x00, 0xff, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff,
|
|
|
|
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
|
|
|
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x2c, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x09, 0x00, 0x09, 0x00, 0x40, 0x04, 0x1b, 0x50, 0x1c, 0x23, 0xe9, 0x44,
|
|
|
|
0x23, 0x60, 0x9d, 0x09, 0x28, 0x1e, 0xf8, 0x6d, 0x64, 0x56, 0x9d, 0x53, 0xa8,
|
|
|
|
0x7e, 0xa8, 0x65, 0x94, 0x5c, 0xb0, 0x8a, 0x45, 0x04, 0x00, 0x3b
|
|
|
|
};
|
GIF decode: optional error messages and fault tolerance.
Add new runtime configuration variable,
images.gif.suppressDecoderWarnings, which suppresses warning and
errors from the GIF library. It defaults to "true", which is current
behavior.
(This setting can be changed by setting the environment variable
skia_images_gif_suppressDecoderWarnings="false".)
Some conditions which were errors before are now warnings:
- If the image width or height is greater than the GIF screen width or
height (respectively) we expand the screen to hold the image.
- If the offset of the image inside the screen would place the
image outside of the screen, we shift the image to fix this.
- If the image lacks a color table, we create a default color table.
- If the image is truncated, then the rest of the image is filled with
the fill color.
In all four cases, if images.gif.suppressDecoderWarnings is set to
false, then a warning message is printed via SkDebugf.
In the event of another kind of error, SkGIFImageDecoder::onDecode()
will still return false. But with this change, if
images.gif.suppressDecoderWarnings is set to false, a description of
the error is printed via SkDebugf.
Also, added a new unit test GifTest, which tests the deconing of both
good GIf files and corrupted files that should now work with this
change. This unit test is disabled on Win32, iOS, and Mac.
BUG=skia:1689
R=scroggo@google.com
Review URL: https://codereview.chromium.org/26743002
git-svn-id: http://skia.googlecode.com/svn/trunk@11734 2bbb7eff-a529-9590-31e7-b0007b416f81
2013-10-11 18:21:56 +00:00
|
|
|
|
|
|
|
static void test_gif_data_no_colormap(skiatest::Reporter* r,
|
2014-01-21 23:39:22 +00:00
|
|
|
void* data,
|
|
|
|
size_t size) {
|
GIF decode: optional error messages and fault tolerance.
Add new runtime configuration variable,
images.gif.suppressDecoderWarnings, which suppresses warning and
errors from the GIF library. It defaults to "true", which is current
behavior.
(This setting can be changed by setting the environment variable
skia_images_gif_suppressDecoderWarnings="false".)
Some conditions which were errors before are now warnings:
- If the image width or height is greater than the GIF screen width or
height (respectively) we expand the screen to hold the image.
- If the offset of the image inside the screen would place the
image outside of the screen, we shift the image to fix this.
- If the image lacks a color table, we create a default color table.
- If the image is truncated, then the rest of the image is filled with
the fill color.
In all four cases, if images.gif.suppressDecoderWarnings is set to
false, then a warning message is printed via SkDebugf.
In the event of another kind of error, SkGIFImageDecoder::onDecode()
will still return false. But with this change, if
images.gif.suppressDecoderWarnings is set to false, a description of
the error is printed via SkDebugf.
Also, added a new unit test GifTest, which tests the deconing of both
good GIf files and corrupted files that should now work with this
change. This unit test is disabled on Win32, iOS, and Mac.
BUG=skia:1689
R=scroggo@google.com
Review URL: https://codereview.chromium.org/26743002
git-svn-id: http://skia.googlecode.com/svn/trunk@11734 2bbb7eff-a529-9590-31e7-b0007b416f81
2013-10-11 18:21:56 +00:00
|
|
|
SkBitmap bm;
|
2016-03-01 20:12:27 +00:00
|
|
|
bool imageDecodeSuccess = decode_memory(data, size, &bm);
|
GIF decode: optional error messages and fault tolerance.
Add new runtime configuration variable,
images.gif.suppressDecoderWarnings, which suppresses warning and
errors from the GIF library. It defaults to "true", which is current
behavior.
(This setting can be changed by setting the environment variable
skia_images_gif_suppressDecoderWarnings="false".)
Some conditions which were errors before are now warnings:
- If the image width or height is greater than the GIF screen width or
height (respectively) we expand the screen to hold the image.
- If the offset of the image inside the screen would place the
image outside of the screen, we shift the image to fix this.
- If the image lacks a color table, we create a default color table.
- If the image is truncated, then the rest of the image is filled with
the fill color.
In all four cases, if images.gif.suppressDecoderWarnings is set to
false, then a warning message is printed via SkDebugf.
In the event of another kind of error, SkGIFImageDecoder::onDecode()
will still return false. But with this change, if
images.gif.suppressDecoderWarnings is set to false, a description of
the error is printed via SkDebugf.
Also, added a new unit test GifTest, which tests the deconing of both
good GIf files and corrupted files that should now work with this
change. This unit test is disabled on Win32, iOS, and Mac.
BUG=skia:1689
R=scroggo@google.com
Review URL: https://codereview.chromium.org/26743002
git-svn-id: http://skia.googlecode.com/svn/trunk@11734 2bbb7eff-a529-9590-31e7-b0007b416f81
2013-10-11 18:21:56 +00:00
|
|
|
REPORTER_ASSERT(r, imageDecodeSuccess);
|
|
|
|
REPORTER_ASSERT(r, bm.width() == 1);
|
|
|
|
REPORTER_ASSERT(r, bm.height() == 1);
|
|
|
|
REPORTER_ASSERT(r, !(bm.empty()));
|
|
|
|
if (!(bm.empty())) {
|
Add support for multiple frames in SkCodec
Add an interface to decode frames beyond the first in SkCodec, and
add an implementation for SkGifCodec.
Add getFrameData to SkCodec. This method reads ahead in the stream
to return a vector containing meta data about each frame in the image.
This is not required in order to decode frames beyond the first, but
it allows a client to learn extra information:
- how long the frame should be displayed
- whether a frame should be blended with a prior frame, allowing the
client to provide the prior frame to speed up decoding
Add a new fields to SkCodec::Options:
- fFrameIndex
- fHasPriorFrame
The API is designed so that SkCodec never caches frames. If a
client wants a frame beyond the first, they specify the frame in
Options.fFrameIndex. If the client does not have the
frame's required frame (the frame that this frame must be blended on
top of) cached, they pass false for
Options.fHasPriorFrame. Unless the frame is
independent, the codec will then recursively decode all frames
necessary to decode fFrameIndex. If the client has the required frame
cached, they can put it in the dst they pass to the codec, and the
codec will only draw fFrameIndex onto it.
Replace SkGifCodec's scanline decoding support with progressive
decoding, and update the tests accordingly.
Implement new APIs in SkGifCodec. Instead of using gif_lib, use
GIFImageReader, imported from Chromium (along with its copyright
headers) with the following changes:
- SkGifCodec is now the client
- Replace blink types
- Combine GIFColorMap::buildTable and ::getTable into a method that
creates and returns an SkColorTable
- Input comes from an SkStream, instead of a SegmentReader. Add
SkStreamBuffer, which buffers the (potentially partial) stream in
order to decode progressively.
(FIXME: This requires copying data that previously was read directly
from the SegmentReader. Does this hurt performance? If so, can we
fix it?)
- Remove UMA code
- Instead of reporting screen width and height to the client, allow the
client to query for it
- Fail earlier if the first frame AND screen have size of zero
- Compute required previous frame when adding a new one
- Move GIFParseQuery from GIFImageDecoder to GIFImageReader
- Allow parsing up to a specific frame (to skip parsing the rest of the
stream if a client only wants the first frame)
- Compute whether the first frame has alpha and supports index 8, to
create the SkImageInfo. This happens before reporting that the size
has been decoded.
Add GIFImageDecoder::haveDecodedRow to SkGifCodec, imported from
Chromium (along with its copyright header), with the following changes:
- Add support for sampling
- Use the swizzler
- Keep track of the rows decoded
- Do *not* keep track of whether we've seen alpha
Remove SkCodec::kOutOfOrder_SkScanlineOrder, which was only used by GIF
scanline decoding.
Call onRewind even if there is no stream (SkGifCodec needs to clear its
decoded state so it will decode from the beginning).
Add a method to SkSwizzler to access the offset into the dst, taking
subsetting into account.
Add a GM that animates a GIF.
Add tests for the new APIs.
*** Behavior changes:
* Previously, we reported that an image with a subset frame and no transparent
index was opaque and used the background index (if present) to fill the
background. This is necessary in order to support index 8, but it does not
match viewers/browsers I have seen. Examples:
- Chromium and Gimp render the background transparent
- Firefox, Safari, Linux Image Viewer, Safari Preview clip to the frame (for
a single frame image)
This CL matches Chromium's behavior and renders the background transparent.
This allows us to have consistent behavior across products and simplifies
the code (relative to what we would have to do to continue the old behavior
on Android). It also means that we will no longer support index 8 for some
GIFs.
* Stop checking for GIFSTAMP - all GIFs should be either 89a or 87a.
This matches Chromium. I suspect that bugs would have been reported if valid
GIFs started with "GIFVER" instead of "GIF89a" or "GIF87a" (but did not decode
in Chromium).
*** Future work not included in this CL:
* Move some checks out of haveDecodedRow, since they are the same for the
entire frame e.g.
- intersecting the frameRect with the full image size
- whether there is a color table
* Change when we write transparent pixels
- In some cases, Chromium deemed this unnecessary, but I suspect it is slower
than the fallback case. There will continue to be cases where we should
*not* write them, but for e.g. the first pass where we have already
cleared to transparent (which we may also be able to skip) writing the
transparent pixels will not make anything incorrect.
* Report color type and alpha type per frame
- Depending on alpha values, disposal methods, frame rects, etc, subsequent
frames may have different properties than the first.
* Skip copies of the encoded data
- We copy the encoded data in case the stream is one that cannot be rewound,
so we can parse and then decode (possibly not immediately). For some input
streams, this is unnecessary.
- I was concerned this cause a performance regression, but on average the
new code is faster than the old for the images I tested [1].
- It may cause a performance regression for Chromium, though, where we can
always move back in the stream, so this should be addressed.
Design doc:
https://docs.google.com/a/google.com/document/d/12Qhf9T92MWfdWujQwCIjhCO3sw6pTJB5pJBwDM1T7Kc/
[1] https://docs.google.com/a/google.com/spreadsheets/d/19V-t9BfbFw5eiwBTKA1qOBkZbchjlTC5EIz6HFy-6RI/
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=2045293002
Review-Url: https://codereview.chromium.org/2045293002
2016-10-24 16:03:26 +00:00
|
|
|
REPORTER_ASSERT(r, bm.getColor(0, 0) == 0x00000000);
|
GIF decode: optional error messages and fault tolerance.
Add new runtime configuration variable,
images.gif.suppressDecoderWarnings, which suppresses warning and
errors from the GIF library. It defaults to "true", which is current
behavior.
(This setting can be changed by setting the environment variable
skia_images_gif_suppressDecoderWarnings="false".)
Some conditions which were errors before are now warnings:
- If the image width or height is greater than the GIF screen width or
height (respectively) we expand the screen to hold the image.
- If the offset of the image inside the screen would place the
image outside of the screen, we shift the image to fix this.
- If the image lacks a color table, we create a default color table.
- If the image is truncated, then the rest of the image is filled with
the fill color.
In all four cases, if images.gif.suppressDecoderWarnings is set to
false, then a warning message is printed via SkDebugf.
In the event of another kind of error, SkGIFImageDecoder::onDecode()
will still return false. But with this change, if
images.gif.suppressDecoderWarnings is set to false, a description of
the error is printed via SkDebugf.
Also, added a new unit test GifTest, which tests the deconing of both
good GIf files and corrupted files that should now work with this
change. This unit test is disabled on Win32, iOS, and Mac.
BUG=skia:1689
R=scroggo@google.com
Review URL: https://codereview.chromium.org/26743002
git-svn-id: http://skia.googlecode.com/svn/trunk@11734 2bbb7eff-a529-9590-31e7-b0007b416f81
2013-10-11 18:21:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
static void test_gif_data(skiatest::Reporter* r, void* data, size_t size) {
|
|
|
|
SkBitmap bm;
|
2016-03-01 20:12:27 +00:00
|
|
|
bool imageDecodeSuccess = decode_memory(data, size, &bm);
|
GIF decode: optional error messages and fault tolerance.
Add new runtime configuration variable,
images.gif.suppressDecoderWarnings, which suppresses warning and
errors from the GIF library. It defaults to "true", which is current
behavior.
(This setting can be changed by setting the environment variable
skia_images_gif_suppressDecoderWarnings="false".)
Some conditions which were errors before are now warnings:
- If the image width or height is greater than the GIF screen width or
height (respectively) we expand the screen to hold the image.
- If the offset of the image inside the screen would place the
image outside of the screen, we shift the image to fix this.
- If the image lacks a color table, we create a default color table.
- If the image is truncated, then the rest of the image is filled with
the fill color.
In all four cases, if images.gif.suppressDecoderWarnings is set to
false, then a warning message is printed via SkDebugf.
In the event of another kind of error, SkGIFImageDecoder::onDecode()
will still return false. But with this change, if
images.gif.suppressDecoderWarnings is set to false, a description of
the error is printed via SkDebugf.
Also, added a new unit test GifTest, which tests the deconing of both
good GIf files and corrupted files that should now work with this
change. This unit test is disabled on Win32, iOS, and Mac.
BUG=skia:1689
R=scroggo@google.com
Review URL: https://codereview.chromium.org/26743002
git-svn-id: http://skia.googlecode.com/svn/trunk@11734 2bbb7eff-a529-9590-31e7-b0007b416f81
2013-10-11 18:21:56 +00:00
|
|
|
REPORTER_ASSERT(r, imageDecodeSuccess);
|
|
|
|
REPORTER_ASSERT(r, bm.width() == 3);
|
|
|
|
REPORTER_ASSERT(r, bm.height() == 3);
|
|
|
|
REPORTER_ASSERT(r, !(bm.empty()));
|
|
|
|
if (!(bm.empty())) {
|
|
|
|
REPORTER_ASSERT(r, bm.getColor(0, 0) == 0xffff0000);
|
|
|
|
REPORTER_ASSERT(r, bm.getColor(1, 0) == 0xffffff00);
|
|
|
|
REPORTER_ASSERT(r, bm.getColor(2, 0) == 0xff00ffff);
|
|
|
|
REPORTER_ASSERT(r, bm.getColor(0, 1) == 0xff808080);
|
|
|
|
REPORTER_ASSERT(r, bm.getColor(1, 1) == 0xff000000);
|
|
|
|
REPORTER_ASSERT(r, bm.getColor(2, 1) == 0xff00ff00);
|
|
|
|
REPORTER_ASSERT(r, bm.getColor(0, 2) == 0xffffffff);
|
|
|
|
REPORTER_ASSERT(r, bm.getColor(1, 2) == 0xffff00ff);
|
|
|
|
REPORTER_ASSERT(r, bm.getColor(2, 2) == 0xff0000ff);
|
|
|
|
}
|
|
|
|
}
|
2016-03-01 20:12:27 +00:00
|
|
|
static void test_gif_data_dims(skiatest::Reporter* r, void* data, size_t size, int width,
|
|
|
|
int height) {
|
|
|
|
SkBitmap bm;
|
|
|
|
bool imageDecodeSuccess = decode_memory(data, size, &bm);
|
|
|
|
REPORTER_ASSERT(r, imageDecodeSuccess);
|
|
|
|
REPORTER_ASSERT(r, bm.width() == width);
|
|
|
|
REPORTER_ASSERT(r, bm.height() == height);
|
|
|
|
REPORTER_ASSERT(r, !(bm.empty()));
|
|
|
|
}
|
GIF decode: optional error messages and fault tolerance.
Add new runtime configuration variable,
images.gif.suppressDecoderWarnings, which suppresses warning and
errors from the GIF library. It defaults to "true", which is current
behavior.
(This setting can be changed by setting the environment variable
skia_images_gif_suppressDecoderWarnings="false".)
Some conditions which were errors before are now warnings:
- If the image width or height is greater than the GIF screen width or
height (respectively) we expand the screen to hold the image.
- If the offset of the image inside the screen would place the
image outside of the screen, we shift the image to fix this.
- If the image lacks a color table, we create a default color table.
- If the image is truncated, then the rest of the image is filled with
the fill color.
In all four cases, if images.gif.suppressDecoderWarnings is set to
false, then a warning message is printed via SkDebugf.
In the event of another kind of error, SkGIFImageDecoder::onDecode()
will still return false. But with this change, if
images.gif.suppressDecoderWarnings is set to false, a description of
the error is printed via SkDebugf.
Also, added a new unit test GifTest, which tests the deconing of both
good GIf files and corrupted files that should now work with this
change. This unit test is disabled on Win32, iOS, and Mac.
BUG=skia:1689
R=scroggo@google.com
Review URL: https://codereview.chromium.org/26743002
git-svn-id: http://skia.googlecode.com/svn/trunk@11734 2bbb7eff-a529-9590-31e7-b0007b416f81
2013-10-11 18:21:56 +00:00
|
|
|
static void test_interlaced_gif_data(skiatest::Reporter* r,
|
|
|
|
void* data,
|
|
|
|
size_t size) {
|
|
|
|
SkBitmap bm;
|
2016-03-01 20:12:27 +00:00
|
|
|
bool imageDecodeSuccess = decode_memory(data, size, &bm);
|
GIF decode: optional error messages and fault tolerance.
Add new runtime configuration variable,
images.gif.suppressDecoderWarnings, which suppresses warning and
errors from the GIF library. It defaults to "true", which is current
behavior.
(This setting can be changed by setting the environment variable
skia_images_gif_suppressDecoderWarnings="false".)
Some conditions which were errors before are now warnings:
- If the image width or height is greater than the GIF screen width or
height (respectively) we expand the screen to hold the image.
- If the offset of the image inside the screen would place the
image outside of the screen, we shift the image to fix this.
- If the image lacks a color table, we create a default color table.
- If the image is truncated, then the rest of the image is filled with
the fill color.
In all four cases, if images.gif.suppressDecoderWarnings is set to
false, then a warning message is printed via SkDebugf.
In the event of another kind of error, SkGIFImageDecoder::onDecode()
will still return false. But with this change, if
images.gif.suppressDecoderWarnings is set to false, a description of
the error is printed via SkDebugf.
Also, added a new unit test GifTest, which tests the deconing of both
good GIf files and corrupted files that should now work with this
change. This unit test is disabled on Win32, iOS, and Mac.
BUG=skia:1689
R=scroggo@google.com
Review URL: https://codereview.chromium.org/26743002
git-svn-id: http://skia.googlecode.com/svn/trunk@11734 2bbb7eff-a529-9590-31e7-b0007b416f81
2013-10-11 18:21:56 +00:00
|
|
|
REPORTER_ASSERT(r, imageDecodeSuccess);
|
|
|
|
REPORTER_ASSERT(r, bm.width() == 9);
|
|
|
|
REPORTER_ASSERT(r, bm.height() == 9);
|
|
|
|
REPORTER_ASSERT(r, !(bm.empty()));
|
|
|
|
if (!(bm.empty())) {
|
|
|
|
REPORTER_ASSERT(r, bm.getColor(0, 0) == 0xffff0000);
|
|
|
|
REPORTER_ASSERT(r, bm.getColor(1, 0) == 0xffffff00);
|
|
|
|
REPORTER_ASSERT(r, bm.getColor(2, 0) == 0xff00ffff);
|
|
|
|
|
|
|
|
REPORTER_ASSERT(r, bm.getColor(0, 2) == 0xffffffff);
|
|
|
|
REPORTER_ASSERT(r, bm.getColor(1, 2) == 0xffff00ff);
|
|
|
|
REPORTER_ASSERT(r, bm.getColor(2, 2) == 0xff0000ff);
|
|
|
|
|
|
|
|
REPORTER_ASSERT(r, bm.getColor(0, 4) == 0xff808080);
|
|
|
|
REPORTER_ASSERT(r, bm.getColor(1, 4) == 0xff000000);
|
|
|
|
REPORTER_ASSERT(r, bm.getColor(2, 4) == 0xff00ff00);
|
|
|
|
|
|
|
|
REPORTER_ASSERT(r, bm.getColor(0, 6) == 0xffff0000);
|
|
|
|
REPORTER_ASSERT(r, bm.getColor(1, 6) == 0xffffff00);
|
|
|
|
REPORTER_ASSERT(r, bm.getColor(2, 6) == 0xff00ffff);
|
|
|
|
|
|
|
|
REPORTER_ASSERT(r, bm.getColor(0, 8) == 0xffffffff);
|
|
|
|
REPORTER_ASSERT(r, bm.getColor(1, 8) == 0xffff00ff);
|
|
|
|
REPORTER_ASSERT(r, bm.getColor(2, 8) == 0xff0000ff);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_gif_data_short(skiatest::Reporter* r,
|
|
|
|
void* data,
|
|
|
|
size_t size) {
|
|
|
|
SkBitmap bm;
|
2016-03-01 20:12:27 +00:00
|
|
|
bool imageDecodeSuccess = decode_memory(data, size, &bm);
|
GIF decode: optional error messages and fault tolerance.
Add new runtime configuration variable,
images.gif.suppressDecoderWarnings, which suppresses warning and
errors from the GIF library. It defaults to "true", which is current
behavior.
(This setting can be changed by setting the environment variable
skia_images_gif_suppressDecoderWarnings="false".)
Some conditions which were errors before are now warnings:
- If the image width or height is greater than the GIF screen width or
height (respectively) we expand the screen to hold the image.
- If the offset of the image inside the screen would place the
image outside of the screen, we shift the image to fix this.
- If the image lacks a color table, we create a default color table.
- If the image is truncated, then the rest of the image is filled with
the fill color.
In all four cases, if images.gif.suppressDecoderWarnings is set to
false, then a warning message is printed via SkDebugf.
In the event of another kind of error, SkGIFImageDecoder::onDecode()
will still return false. But with this change, if
images.gif.suppressDecoderWarnings is set to false, a description of
the error is printed via SkDebugf.
Also, added a new unit test GifTest, which tests the deconing of both
good GIf files and corrupted files that should now work with this
change. This unit test is disabled on Win32, iOS, and Mac.
BUG=skia:1689
R=scroggo@google.com
Review URL: https://codereview.chromium.org/26743002
git-svn-id: http://skia.googlecode.com/svn/trunk@11734 2bbb7eff-a529-9590-31e7-b0007b416f81
2013-10-11 18:21:56 +00:00
|
|
|
REPORTER_ASSERT(r, imageDecodeSuccess);
|
|
|
|
REPORTER_ASSERT(r, bm.width() == 3);
|
|
|
|
REPORTER_ASSERT(r, bm.height() == 3);
|
|
|
|
REPORTER_ASSERT(r, !(bm.empty()));
|
|
|
|
if (!(bm.empty())) {
|
|
|
|
REPORTER_ASSERT(r, bm.getColor(0, 0) == 0xffff0000);
|
|
|
|
REPORTER_ASSERT(r, bm.getColor(1, 0) == 0xffffff00);
|
|
|
|
REPORTER_ASSERT(r, bm.getColor(2, 0) == 0xff00ffff);
|
|
|
|
REPORTER_ASSERT(r, bm.getColor(0, 1) == 0xff808080);
|
|
|
|
REPORTER_ASSERT(r, bm.getColor(1, 1) == 0xff000000);
|
|
|
|
REPORTER_ASSERT(r, bm.getColor(2, 1) == 0xff00ff00);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-03-01 20:12:27 +00:00
|
|
|
This test will test the ability of the SkCodec to deal with
|
GIF decode: optional error messages and fault tolerance.
Add new runtime configuration variable,
images.gif.suppressDecoderWarnings, which suppresses warning and
errors from the GIF library. It defaults to "true", which is current
behavior.
(This setting can be changed by setting the environment variable
skia_images_gif_suppressDecoderWarnings="false".)
Some conditions which were errors before are now warnings:
- If the image width or height is greater than the GIF screen width or
height (respectively) we expand the screen to hold the image.
- If the offset of the image inside the screen would place the
image outside of the screen, we shift the image to fix this.
- If the image lacks a color table, we create a default color table.
- If the image is truncated, then the rest of the image is filled with
the fill color.
In all four cases, if images.gif.suppressDecoderWarnings is set to
false, then a warning message is printed via SkDebugf.
In the event of another kind of error, SkGIFImageDecoder::onDecode()
will still return false. But with this change, if
images.gif.suppressDecoderWarnings is set to false, a description of
the error is printed via SkDebugf.
Also, added a new unit test GifTest, which tests the deconing of both
good GIf files and corrupted files that should now work with this
change. This unit test is disabled on Win32, iOS, and Mac.
BUG=skia:1689
R=scroggo@google.com
Review URL: https://codereview.chromium.org/26743002
git-svn-id: http://skia.googlecode.com/svn/trunk@11734 2bbb7eff-a529-9590-31e7-b0007b416f81
2013-10-11 18:21:56 +00:00
|
|
|
GIF files which have been mangled somehow. We want to display as
|
|
|
|
much of the GIF as possible.
|
|
|
|
*/
|
2013-12-12 21:11:12 +00:00
|
|
|
DEF_TEST(Gif, reporter) {
|
GIF decode: optional error messages and fault tolerance.
Add new runtime configuration variable,
images.gif.suppressDecoderWarnings, which suppresses warning and
errors from the GIF library. It defaults to "true", which is current
behavior.
(This setting can be changed by setting the environment variable
skia_images_gif_suppressDecoderWarnings="false".)
Some conditions which were errors before are now warnings:
- If the image width or height is greater than the GIF screen width or
height (respectively) we expand the screen to hold the image.
- If the offset of the image inside the screen would place the
image outside of the screen, we shift the image to fix this.
- If the image lacks a color table, we create a default color table.
- If the image is truncated, then the rest of the image is filled with
the fill color.
In all four cases, if images.gif.suppressDecoderWarnings is set to
false, then a warning message is printed via SkDebugf.
In the event of another kind of error, SkGIFImageDecoder::onDecode()
will still return false. But with this change, if
images.gif.suppressDecoderWarnings is set to false, a description of
the error is printed via SkDebugf.
Also, added a new unit test GifTest, which tests the deconing of both
good GIf files and corrupted files that should now work with this
change. This unit test is disabled on Win32, iOS, and Mac.
BUG=skia:1689
R=scroggo@google.com
Review URL: https://codereview.chromium.org/26743002
git-svn-id: http://skia.googlecode.com/svn/trunk@11734 2bbb7eff-a529-9590-31e7-b0007b416f81
2013-10-11 18:21:56 +00:00
|
|
|
// test perfectly good images.
|
2014-01-21 23:39:22 +00:00
|
|
|
test_gif_data(reporter, static_cast<void *>(gGIFData), sizeof(gGIFData));
|
|
|
|
test_interlaced_gif_data(reporter, static_cast<void *>(gInterlacedGIF),
|
|
|
|
sizeof(gInterlacedGIF));
|
GIF decode: optional error messages and fault tolerance.
Add new runtime configuration variable,
images.gif.suppressDecoderWarnings, which suppresses warning and
errors from the GIF library. It defaults to "true", which is current
behavior.
(This setting can be changed by setting the environment variable
skia_images_gif_suppressDecoderWarnings="false".)
Some conditions which were errors before are now warnings:
- If the image width or height is greater than the GIF screen width or
height (respectively) we expand the screen to hold the image.
- If the offset of the image inside the screen would place the
image outside of the screen, we shift the image to fix this.
- If the image lacks a color table, we create a default color table.
- If the image is truncated, then the rest of the image is filled with
the fill color.
In all four cases, if images.gif.suppressDecoderWarnings is set to
false, then a warning message is printed via SkDebugf.
In the event of another kind of error, SkGIFImageDecoder::onDecode()
will still return false. But with this change, if
images.gif.suppressDecoderWarnings is set to false, a description of
the error is printed via SkDebugf.
Also, added a new unit test GifTest, which tests the deconing of both
good GIf files and corrupted files that should now work with this
change. This unit test is disabled on Win32, iOS, and Mac.
BUG=skia:1689
R=scroggo@google.com
Review URL: https://codereview.chromium.org/26743002
git-svn-id: http://skia.googlecode.com/svn/trunk@11734 2bbb7eff-a529-9590-31e7-b0007b416f81
2013-10-11 18:21:56 +00:00
|
|
|
|
2014-01-21 23:39:22 +00:00
|
|
|
unsigned char badData[sizeof(gGIFData)];
|
GIF decode: optional error messages and fault tolerance.
Add new runtime configuration variable,
images.gif.suppressDecoderWarnings, which suppresses warning and
errors from the GIF library. It defaults to "true", which is current
behavior.
(This setting can be changed by setting the environment variable
skia_images_gif_suppressDecoderWarnings="false".)
Some conditions which were errors before are now warnings:
- If the image width or height is greater than the GIF screen width or
height (respectively) we expand the screen to hold the image.
- If the offset of the image inside the screen would place the
image outside of the screen, we shift the image to fix this.
- If the image lacks a color table, we create a default color table.
- If the image is truncated, then the rest of the image is filled with
the fill color.
In all four cases, if images.gif.suppressDecoderWarnings is set to
false, then a warning message is printed via SkDebugf.
In the event of another kind of error, SkGIFImageDecoder::onDecode()
will still return false. But with this change, if
images.gif.suppressDecoderWarnings is set to false, a description of
the error is printed via SkDebugf.
Also, added a new unit test GifTest, which tests the deconing of both
good GIf files and corrupted files that should now work with this
change. This unit test is disabled on Win32, iOS, and Mac.
BUG=skia:1689
R=scroggo@google.com
Review URL: https://codereview.chromium.org/26743002
git-svn-id: http://skia.googlecode.com/svn/trunk@11734 2bbb7eff-a529-9590-31e7-b0007b416f81
2013-10-11 18:21:56 +00:00
|
|
|
|
2014-01-21 23:39:22 +00:00
|
|
|
memcpy(badData, gGIFData, sizeof(gGIFData));
|
GIF decode: optional error messages and fault tolerance.
Add new runtime configuration variable,
images.gif.suppressDecoderWarnings, which suppresses warning and
errors from the GIF library. It defaults to "true", which is current
behavior.
(This setting can be changed by setting the environment variable
skia_images_gif_suppressDecoderWarnings="false".)
Some conditions which were errors before are now warnings:
- If the image width or height is greater than the GIF screen width or
height (respectively) we expand the screen to hold the image.
- If the offset of the image inside the screen would place the
image outside of the screen, we shift the image to fix this.
- If the image lacks a color table, we create a default color table.
- If the image is truncated, then the rest of the image is filled with
the fill color.
In all four cases, if images.gif.suppressDecoderWarnings is set to
false, then a warning message is printed via SkDebugf.
In the event of another kind of error, SkGIFImageDecoder::onDecode()
will still return false. But with this change, if
images.gif.suppressDecoderWarnings is set to false, a description of
the error is printed via SkDebugf.
Also, added a new unit test GifTest, which tests the deconing of both
good GIf files and corrupted files that should now work with this
change. This unit test is disabled on Win32, iOS, and Mac.
BUG=skia:1689
R=scroggo@google.com
Review URL: https://codereview.chromium.org/26743002
git-svn-id: http://skia.googlecode.com/svn/trunk@11734 2bbb7eff-a529-9590-31e7-b0007b416f81
2013-10-11 18:21:56 +00:00
|
|
|
badData[6] = 0x01; // image too wide
|
2014-01-21 23:39:22 +00:00
|
|
|
test_gif_data(reporter, static_cast<void *>(badData), sizeof(gGIFData));
|
GIF decode: optional error messages and fault tolerance.
Add new runtime configuration variable,
images.gif.suppressDecoderWarnings, which suppresses warning and
errors from the GIF library. It defaults to "true", which is current
behavior.
(This setting can be changed by setting the environment variable
skia_images_gif_suppressDecoderWarnings="false".)
Some conditions which were errors before are now warnings:
- If the image width or height is greater than the GIF screen width or
height (respectively) we expand the screen to hold the image.
- If the offset of the image inside the screen would place the
image outside of the screen, we shift the image to fix this.
- If the image lacks a color table, we create a default color table.
- If the image is truncated, then the rest of the image is filled with
the fill color.
In all four cases, if images.gif.suppressDecoderWarnings is set to
false, then a warning message is printed via SkDebugf.
In the event of another kind of error, SkGIFImageDecoder::onDecode()
will still return false. But with this change, if
images.gif.suppressDecoderWarnings is set to false, a description of
the error is printed via SkDebugf.
Also, added a new unit test GifTest, which tests the deconing of both
good GIf files and corrupted files that should now work with this
change. This unit test is disabled on Win32, iOS, and Mac.
BUG=skia:1689
R=scroggo@google.com
Review URL: https://codereview.chromium.org/26743002
git-svn-id: http://skia.googlecode.com/svn/trunk@11734 2bbb7eff-a529-9590-31e7-b0007b416f81
2013-10-11 18:21:56 +00:00
|
|
|
// "libgif warning [image too wide, expanding output to size]"
|
|
|
|
|
2014-01-21 23:39:22 +00:00
|
|
|
memcpy(badData, gGIFData, sizeof(gGIFData));
|
GIF decode: optional error messages and fault tolerance.
Add new runtime configuration variable,
images.gif.suppressDecoderWarnings, which suppresses warning and
errors from the GIF library. It defaults to "true", which is current
behavior.
(This setting can be changed by setting the environment variable
skia_images_gif_suppressDecoderWarnings="false".)
Some conditions which were errors before are now warnings:
- If the image width or height is greater than the GIF screen width or
height (respectively) we expand the screen to hold the image.
- If the offset of the image inside the screen would place the
image outside of the screen, we shift the image to fix this.
- If the image lacks a color table, we create a default color table.
- If the image is truncated, then the rest of the image is filled with
the fill color.
In all four cases, if images.gif.suppressDecoderWarnings is set to
false, then a warning message is printed via SkDebugf.
In the event of another kind of error, SkGIFImageDecoder::onDecode()
will still return false. But with this change, if
images.gif.suppressDecoderWarnings is set to false, a description of
the error is printed via SkDebugf.
Also, added a new unit test GifTest, which tests the deconing of both
good GIf files and corrupted files that should now work with this
change. This unit test is disabled on Win32, iOS, and Mac.
BUG=skia:1689
R=scroggo@google.com
Review URL: https://codereview.chromium.org/26743002
git-svn-id: http://skia.googlecode.com/svn/trunk@11734 2bbb7eff-a529-9590-31e7-b0007b416f81
2013-10-11 18:21:56 +00:00
|
|
|
badData[8] = 0x01; // image too tall
|
2014-01-21 23:39:22 +00:00
|
|
|
test_gif_data(reporter, static_cast<void *>(badData), sizeof(gGIFData));
|
GIF decode: optional error messages and fault tolerance.
Add new runtime configuration variable,
images.gif.suppressDecoderWarnings, which suppresses warning and
errors from the GIF library. It defaults to "true", which is current
behavior.
(This setting can be changed by setting the environment variable
skia_images_gif_suppressDecoderWarnings="false".)
Some conditions which were errors before are now warnings:
- If the image width or height is greater than the GIF screen width or
height (respectively) we expand the screen to hold the image.
- If the offset of the image inside the screen would place the
image outside of the screen, we shift the image to fix this.
- If the image lacks a color table, we create a default color table.
- If the image is truncated, then the rest of the image is filled with
the fill color.
In all four cases, if images.gif.suppressDecoderWarnings is set to
false, then a warning message is printed via SkDebugf.
In the event of another kind of error, SkGIFImageDecoder::onDecode()
will still return false. But with this change, if
images.gif.suppressDecoderWarnings is set to false, a description of
the error is printed via SkDebugf.
Also, added a new unit test GifTest, which tests the deconing of both
good GIf files and corrupted files that should now work with this
change. This unit test is disabled on Win32, iOS, and Mac.
BUG=skia:1689
R=scroggo@google.com
Review URL: https://codereview.chromium.org/26743002
git-svn-id: http://skia.googlecode.com/svn/trunk@11734 2bbb7eff-a529-9590-31e7-b0007b416f81
2013-10-11 18:21:56 +00:00
|
|
|
// "libgif warning [image too tall, expanding output to size]"
|
|
|
|
|
2014-01-21 23:39:22 +00:00
|
|
|
memcpy(badData, gGIFData, sizeof(gGIFData));
|
GIF decode: optional error messages and fault tolerance.
Add new runtime configuration variable,
images.gif.suppressDecoderWarnings, which suppresses warning and
errors from the GIF library. It defaults to "true", which is current
behavior.
(This setting can be changed by setting the environment variable
skia_images_gif_suppressDecoderWarnings="false".)
Some conditions which were errors before are now warnings:
- If the image width or height is greater than the GIF screen width or
height (respectively) we expand the screen to hold the image.
- If the offset of the image inside the screen would place the
image outside of the screen, we shift the image to fix this.
- If the image lacks a color table, we create a default color table.
- If the image is truncated, then the rest of the image is filled with
the fill color.
In all four cases, if images.gif.suppressDecoderWarnings is set to
false, then a warning message is printed via SkDebugf.
In the event of another kind of error, SkGIFImageDecoder::onDecode()
will still return false. But with this change, if
images.gif.suppressDecoderWarnings is set to false, a description of
the error is printed via SkDebugf.
Also, added a new unit test GifTest, which tests the deconing of both
good GIf files and corrupted files that should now work with this
change. This unit test is disabled on Win32, iOS, and Mac.
BUG=skia:1689
R=scroggo@google.com
Review URL: https://codereview.chromium.org/26743002
git-svn-id: http://skia.googlecode.com/svn/trunk@11734 2bbb7eff-a529-9590-31e7-b0007b416f81
2013-10-11 18:21:56 +00:00
|
|
|
badData[62] = 0x01; // image shifted right
|
2016-03-01 20:12:27 +00:00
|
|
|
test_gif_data_dims(reporter, static_cast<void *>(badData), sizeof(gGIFData), 4, 3);
|
GIF decode: optional error messages and fault tolerance.
Add new runtime configuration variable,
images.gif.suppressDecoderWarnings, which suppresses warning and
errors from the GIF library. It defaults to "true", which is current
behavior.
(This setting can be changed by setting the environment variable
skia_images_gif_suppressDecoderWarnings="false".)
Some conditions which were errors before are now warnings:
- If the image width or height is greater than the GIF screen width or
height (respectively) we expand the screen to hold the image.
- If the offset of the image inside the screen would place the
image outside of the screen, we shift the image to fix this.
- If the image lacks a color table, we create a default color table.
- If the image is truncated, then the rest of the image is filled with
the fill color.
In all four cases, if images.gif.suppressDecoderWarnings is set to
false, then a warning message is printed via SkDebugf.
In the event of another kind of error, SkGIFImageDecoder::onDecode()
will still return false. But with this change, if
images.gif.suppressDecoderWarnings is set to false, a description of
the error is printed via SkDebugf.
Also, added a new unit test GifTest, which tests the deconing of both
good GIf files and corrupted files that should now work with this
change. This unit test is disabled on Win32, iOS, and Mac.
BUG=skia:1689
R=scroggo@google.com
Review URL: https://codereview.chromium.org/26743002
git-svn-id: http://skia.googlecode.com/svn/trunk@11734 2bbb7eff-a529-9590-31e7-b0007b416f81
2013-10-11 18:21:56 +00:00
|
|
|
|
2014-01-21 23:39:22 +00:00
|
|
|
memcpy(badData, gGIFData, sizeof(gGIFData));
|
GIF decode: optional error messages and fault tolerance.
Add new runtime configuration variable,
images.gif.suppressDecoderWarnings, which suppresses warning and
errors from the GIF library. It defaults to "true", which is current
behavior.
(This setting can be changed by setting the environment variable
skia_images_gif_suppressDecoderWarnings="false".)
Some conditions which were errors before are now warnings:
- If the image width or height is greater than the GIF screen width or
height (respectively) we expand the screen to hold the image.
- If the offset of the image inside the screen would place the
image outside of the screen, we shift the image to fix this.
- If the image lacks a color table, we create a default color table.
- If the image is truncated, then the rest of the image is filled with
the fill color.
In all four cases, if images.gif.suppressDecoderWarnings is set to
false, then a warning message is printed via SkDebugf.
In the event of another kind of error, SkGIFImageDecoder::onDecode()
will still return false. But with this change, if
images.gif.suppressDecoderWarnings is set to false, a description of
the error is printed via SkDebugf.
Also, added a new unit test GifTest, which tests the deconing of both
good GIf files and corrupted files that should now work with this
change. This unit test is disabled on Win32, iOS, and Mac.
BUG=skia:1689
R=scroggo@google.com
Review URL: https://codereview.chromium.org/26743002
git-svn-id: http://skia.googlecode.com/svn/trunk@11734 2bbb7eff-a529-9590-31e7-b0007b416f81
2013-10-11 18:21:56 +00:00
|
|
|
badData[64] = 0x01; // image shifted down
|
2016-03-01 20:12:27 +00:00
|
|
|
test_gif_data_dims(reporter, static_cast<void *>(badData), sizeof(gGIFData), 3, 4);
|
GIF decode: optional error messages and fault tolerance.
Add new runtime configuration variable,
images.gif.suppressDecoderWarnings, which suppresses warning and
errors from the GIF library. It defaults to "true", which is current
behavior.
(This setting can be changed by setting the environment variable
skia_images_gif_suppressDecoderWarnings="false".)
Some conditions which were errors before are now warnings:
- If the image width or height is greater than the GIF screen width or
height (respectively) we expand the screen to hold the image.
- If the offset of the image inside the screen would place the
image outside of the screen, we shift the image to fix this.
- If the image lacks a color table, we create a default color table.
- If the image is truncated, then the rest of the image is filled with
the fill color.
In all four cases, if images.gif.suppressDecoderWarnings is set to
false, then a warning message is printed via SkDebugf.
In the event of another kind of error, SkGIFImageDecoder::onDecode()
will still return false. But with this change, if
images.gif.suppressDecoderWarnings is set to false, a description of
the error is printed via SkDebugf.
Also, added a new unit test GifTest, which tests the deconing of both
good GIf files and corrupted files that should now work with this
change. This unit test is disabled on Win32, iOS, and Mac.
BUG=skia:1689
R=scroggo@google.com
Review URL: https://codereview.chromium.org/26743002
git-svn-id: http://skia.googlecode.com/svn/trunk@11734 2bbb7eff-a529-9590-31e7-b0007b416f81
2013-10-11 18:21:56 +00:00
|
|
|
|
2014-01-21 23:39:22 +00:00
|
|
|
memcpy(badData, gGIFData, sizeof(gGIFData));
|
2016-03-01 20:12:27 +00:00
|
|
|
badData[62] = 0xff; // image shifted right
|
|
|
|
badData[63] = 0xff;
|
|
|
|
test_gif_data_dims(reporter, static_cast<void *>(badData), sizeof(gGIFData), 3 + 0xFFFF, 3);
|
GIF decode: optional error messages and fault tolerance.
Add new runtime configuration variable,
images.gif.suppressDecoderWarnings, which suppresses warning and
errors from the GIF library. It defaults to "true", which is current
behavior.
(This setting can be changed by setting the environment variable
skia_images_gif_suppressDecoderWarnings="false".)
Some conditions which were errors before are now warnings:
- If the image width or height is greater than the GIF screen width or
height (respectively) we expand the screen to hold the image.
- If the offset of the image inside the screen would place the
image outside of the screen, we shift the image to fix this.
- If the image lacks a color table, we create a default color table.
- If the image is truncated, then the rest of the image is filled with
the fill color.
In all four cases, if images.gif.suppressDecoderWarnings is set to
false, then a warning message is printed via SkDebugf.
In the event of another kind of error, SkGIFImageDecoder::onDecode()
will still return false. But with this change, if
images.gif.suppressDecoderWarnings is set to false, a description of
the error is printed via SkDebugf.
Also, added a new unit test GifTest, which tests the deconing of both
good GIf files and corrupted files that should now work with this
change. This unit test is disabled on Win32, iOS, and Mac.
BUG=skia:1689
R=scroggo@google.com
Review URL: https://codereview.chromium.org/26743002
git-svn-id: http://skia.googlecode.com/svn/trunk@11734 2bbb7eff-a529-9590-31e7-b0007b416f81
2013-10-11 18:21:56 +00:00
|
|
|
|
2014-01-21 23:39:22 +00:00
|
|
|
memcpy(badData, gGIFData, sizeof(gGIFData));
|
2016-03-01 20:12:27 +00:00
|
|
|
badData[64] = 0xff; // image shifted down
|
|
|
|
badData[65] = 0xff;
|
|
|
|
test_gif_data_dims(reporter, static_cast<void *>(badData), sizeof(gGIFData), 3, 3 + 0xFFFF);
|
GIF decode: optional error messages and fault tolerance.
Add new runtime configuration variable,
images.gif.suppressDecoderWarnings, which suppresses warning and
errors from the GIF library. It defaults to "true", which is current
behavior.
(This setting can be changed by setting the environment variable
skia_images_gif_suppressDecoderWarnings="false".)
Some conditions which were errors before are now warnings:
- If the image width or height is greater than the GIF screen width or
height (respectively) we expand the screen to hold the image.
- If the offset of the image inside the screen would place the
image outside of the screen, we shift the image to fix this.
- If the image lacks a color table, we create a default color table.
- If the image is truncated, then the rest of the image is filled with
the fill color.
In all four cases, if images.gif.suppressDecoderWarnings is set to
false, then a warning message is printed via SkDebugf.
In the event of another kind of error, SkGIFImageDecoder::onDecode()
will still return false. But with this change, if
images.gif.suppressDecoderWarnings is set to false, a description of
the error is printed via SkDebugf.
Also, added a new unit test GifTest, which tests the deconing of both
good GIf files and corrupted files that should now work with this
change. This unit test is disabled on Win32, iOS, and Mac.
BUG=skia:1689
R=scroggo@google.com
Review URL: https://codereview.chromium.org/26743002
git-svn-id: http://skia.googlecode.com/svn/trunk@11734 2bbb7eff-a529-9590-31e7-b0007b416f81
2013-10-11 18:21:56 +00:00
|
|
|
|
2014-01-21 23:39:22 +00:00
|
|
|
test_gif_data_no_colormap(reporter, static_cast<void *>(gGIFDataNoColormap),
|
|
|
|
sizeof(gGIFDataNoColormap));
|
Fix SkGifCodec bugs around truncated data
Prior to this CL, if a GIF file was truncated before reading the local
color map of a frame, incremental decode would do the wrong thing. In
onStartIncrementalDecode, we would either create a color table based on
the global color map, or we would create a dummy one with only one
color (transparent). The dummy color table is correct if there is
neither a global nor a local color map, and allows us to fill the frame
with transparent. But if more data is provided, and it includes an
actual color map and image data, one of the following can happen:
- If the created color table is smaller than the actual one, the
decoded data may include indices outside of the range of the created
color table, resulting in a crash.
- If we get lucky, and the created color table is large enough, it may
still be the wrong colors (and most likely is).
To solve this, make onStartIncrementalDecode fail if there is a local
color map that has not been read yet. A future call may read more data
and read the correct color map.
This is done by returning kIncompleteInput in
SkGifCodec::prepareToDecode if there is a local color map that has not
yet been read. (It is possible that there is no color map at all, in
which case we still need to support decoding that frame. Skip
attempting to decode in that case.)
In onGetPixels, if prepareToDecode returned kIncompleteInput, return
kInvalidInput. Although the input is technically incomplete, no future
call will provide more data (unlike in incremental decoding), and there
is nothing interesting for the client to draw. This also prevents
SkCodec from attempting to fill the data with an SkSwizzler, which has
not been created. (An alternative solution would be create the dummy
color table and an SkSwizzler, which would keep the current behavior.
But I think the new behavior of returning kInvalidInput makes more
sense.)
Add tests to verify the intended behavior:
- getPixels fails.
- startIncrementalDecode fails, but after providing more data it will
succeed and incremental decoding matches the image decoded from the
full stream.
- Both succeed if there is no color table at all.
Change-Id: Ifb52fe7f723673406a28e80c8805a552f0ac33b6
Reviewed-on: https://skia-review.googlesource.com/5758
Reviewed-by: Matt Sarett <msarett@google.com>
Commit-Queue: Leon Scroggins <scroggo@google.com>
2016-12-09 21:39:33 +00:00
|
|
|
|
2018-10-26 13:25:51 +00:00
|
|
|
#ifdef SK_HAS_WUFFS_LIBRARY
|
|
|
|
// We are transitioning from an old GIF implementation to a new (Wuffs) GIF
|
|
|
|
// implementation.
|
|
|
|
//
|
|
|
|
// This test (without SK_HAS_WUFFS_LIBRARY) is overly specific to the old
|
|
|
|
// implementation. It claims that, for invalid (truncated) input, we can
|
|
|
|
// still 'decode' all of the pixels because no matter what palette index
|
|
|
|
// each pixel is, they're all equivalently transparent. It's not obvious
|
|
|
|
// that this off-spec behavior is worth preserving. Are real world users
|
|
|
|
// decoding truncated all-transparent GIF images??
|
|
|
|
//
|
|
|
|
// Once the transition is complete, we can remove the #ifdef and delete the
|
|
|
|
// #else branch.
|
|
|
|
#else
|
Fix SkGifCodec bugs around truncated data
Prior to this CL, if a GIF file was truncated before reading the local
color map of a frame, incremental decode would do the wrong thing. In
onStartIncrementalDecode, we would either create a color table based on
the global color map, or we would create a dummy one with only one
color (transparent). The dummy color table is correct if there is
neither a global nor a local color map, and allows us to fill the frame
with transparent. But if more data is provided, and it includes an
actual color map and image data, one of the following can happen:
- If the created color table is smaller than the actual one, the
decoded data may include indices outside of the range of the created
color table, resulting in a crash.
- If we get lucky, and the created color table is large enough, it may
still be the wrong colors (and most likely is).
To solve this, make onStartIncrementalDecode fail if there is a local
color map that has not been read yet. A future call may read more data
and read the correct color map.
This is done by returning kIncompleteInput in
SkGifCodec::prepareToDecode if there is a local color map that has not
yet been read. (It is possible that there is no color map at all, in
which case we still need to support decoding that frame. Skip
attempting to decode in that case.)
In onGetPixels, if prepareToDecode returned kIncompleteInput, return
kInvalidInput. Although the input is technically incomplete, no future
call will provide more data (unlike in incremental decoding), and there
is nothing interesting for the client to draw. This also prevents
SkCodec from attempting to fill the data with an SkSwizzler, which has
not been created. (An alternative solution would be create the dummy
color table and an SkSwizzler, which would keep the current behavior.
But I think the new behavior of returning kInvalidInput makes more
sense.)
Add tests to verify the intended behavior:
- getPixels fails.
- startIncrementalDecode fails, but after providing more data it will
succeed and incremental decoding matches the image decoded from the
full stream.
- Both succeed if there is no color table at all.
Change-Id: Ifb52fe7f723673406a28e80c8805a552f0ac33b6
Reviewed-on: https://skia-review.googlesource.com/5758
Reviewed-by: Matt Sarett <msarett@google.com>
Commit-Queue: Leon Scroggins <scroggo@google.com>
2016-12-09 21:39:33 +00:00
|
|
|
// Since there is no color map, we do not even need to parse the image data
|
|
|
|
// to know that we should draw transparent. Truncate the file before the
|
|
|
|
// data. This should still succeed.
|
|
|
|
test_gif_data_no_colormap(reporter, static_cast<void *>(gGIFDataNoColormap), 31);
|
|
|
|
|
|
|
|
// Likewise, incremental decoding should succeed here.
|
|
|
|
{
|
|
|
|
sk_sp<SkData> data = SkData::MakeWithoutCopy(gGIFDataNoColormap, 31);
|
2017-07-23 19:30:02 +00:00
|
|
|
std::unique_ptr<SkCodec> codec(SkCodec::MakeFromData(data));
|
Fix SkGifCodec bugs around truncated data
Prior to this CL, if a GIF file was truncated before reading the local
color map of a frame, incremental decode would do the wrong thing. In
onStartIncrementalDecode, we would either create a color table based on
the global color map, or we would create a dummy one with only one
color (transparent). The dummy color table is correct if there is
neither a global nor a local color map, and allows us to fill the frame
with transparent. But if more data is provided, and it includes an
actual color map and image data, one of the following can happen:
- If the created color table is smaller than the actual one, the
decoded data may include indices outside of the range of the created
color table, resulting in a crash.
- If we get lucky, and the created color table is large enough, it may
still be the wrong colors (and most likely is).
To solve this, make onStartIncrementalDecode fail if there is a local
color map that has not been read yet. A future call may read more data
and read the correct color map.
This is done by returning kIncompleteInput in
SkGifCodec::prepareToDecode if there is a local color map that has not
yet been read. (It is possible that there is no color map at all, in
which case we still need to support decoding that frame. Skip
attempting to decode in that case.)
In onGetPixels, if prepareToDecode returned kIncompleteInput, return
kInvalidInput. Although the input is technically incomplete, no future
call will provide more data (unlike in incremental decoding), and there
is nothing interesting for the client to draw. This also prevents
SkCodec from attempting to fill the data with an SkSwizzler, which has
not been created. (An alternative solution would be create the dummy
color table and an SkSwizzler, which would keep the current behavior.
But I think the new behavior of returning kInvalidInput makes more
sense.)
Add tests to verify the intended behavior:
- getPixels fails.
- startIncrementalDecode fails, but after providing more data it will
succeed and incremental decoding matches the image decoded from the
full stream.
- Both succeed if there is no color table at all.
Change-Id: Ifb52fe7f723673406a28e80c8805a552f0ac33b6
Reviewed-on: https://skia-review.googlesource.com/5758
Reviewed-by: Matt Sarett <msarett@google.com>
Commit-Queue: Leon Scroggins <scroggo@google.com>
2016-12-09 21:39:33 +00:00
|
|
|
REPORTER_ASSERT(reporter, codec);
|
|
|
|
if (codec) {
|
|
|
|
auto info = codec->getInfo().makeColorType(kN32_SkColorType);
|
|
|
|
SkBitmap bm;
|
|
|
|
bm.allocPixels(info);
|
|
|
|
REPORTER_ASSERT(reporter, SkCodec::kSuccess == codec->startIncrementalDecode(
|
|
|
|
info, bm.getPixels(), bm.rowBytes()));
|
|
|
|
REPORTER_ASSERT(reporter, SkCodec::kSuccess == codec->incrementalDecode());
|
|
|
|
REPORTER_ASSERT(reporter, bm.width() == 1);
|
|
|
|
REPORTER_ASSERT(reporter, bm.height() == 1);
|
|
|
|
REPORTER_ASSERT(reporter, !(bm.empty()));
|
|
|
|
if (!(bm.empty())) {
|
|
|
|
REPORTER_ASSERT(reporter, bm.getColor(0, 0) == 0x00000000);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-10-26 13:25:51 +00:00
|
|
|
#endif
|
GIF decode: optional error messages and fault tolerance.
Add new runtime configuration variable,
images.gif.suppressDecoderWarnings, which suppresses warning and
errors from the GIF library. It defaults to "true", which is current
behavior.
(This setting can be changed by setting the environment variable
skia_images_gif_suppressDecoderWarnings="false".)
Some conditions which were errors before are now warnings:
- If the image width or height is greater than the GIF screen width or
height (respectively) we expand the screen to hold the image.
- If the offset of the image inside the screen would place the
image outside of the screen, we shift the image to fix this.
- If the image lacks a color table, we create a default color table.
- If the image is truncated, then the rest of the image is filled with
the fill color.
In all four cases, if images.gif.suppressDecoderWarnings is set to
false, then a warning message is printed via SkDebugf.
In the event of another kind of error, SkGIFImageDecoder::onDecode()
will still return false. But with this change, if
images.gif.suppressDecoderWarnings is set to false, a description of
the error is printed via SkDebugf.
Also, added a new unit test GifTest, which tests the deconing of both
good GIf files and corrupted files that should now work with this
change. This unit test is disabled on Win32, iOS, and Mac.
BUG=skia:1689
R=scroggo@google.com
Review URL: https://codereview.chromium.org/26743002
git-svn-id: http://skia.googlecode.com/svn/trunk@11734 2bbb7eff-a529-9590-31e7-b0007b416f81
2013-10-11 18:21:56 +00:00
|
|
|
|
|
|
|
// test short Gif. 80 is missing a few bytes.
|
2014-01-21 23:39:22 +00:00
|
|
|
test_gif_data_short(reporter, static_cast<void *>(gGIFData), 80);
|
GIF decode: optional error messages and fault tolerance.
Add new runtime configuration variable,
images.gif.suppressDecoderWarnings, which suppresses warning and
errors from the GIF library. It defaults to "true", which is current
behavior.
(This setting can be changed by setting the environment variable
skia_images_gif_suppressDecoderWarnings="false".)
Some conditions which were errors before are now warnings:
- If the image width or height is greater than the GIF screen width or
height (respectively) we expand the screen to hold the image.
- If the offset of the image inside the screen would place the
image outside of the screen, we shift the image to fix this.
- If the image lacks a color table, we create a default color table.
- If the image is truncated, then the rest of the image is filled with
the fill color.
In all four cases, if images.gif.suppressDecoderWarnings is set to
false, then a warning message is printed via SkDebugf.
In the event of another kind of error, SkGIFImageDecoder::onDecode()
will still return false. But with this change, if
images.gif.suppressDecoderWarnings is set to false, a description of
the error is printed via SkDebugf.
Also, added a new unit test GifTest, which tests the deconing of both
good GIf files and corrupted files that should now work with this
change. This unit test is disabled on Win32, iOS, and Mac.
BUG=skia:1689
R=scroggo@google.com
Review URL: https://codereview.chromium.org/26743002
git-svn-id: http://skia.googlecode.com/svn/trunk@11734 2bbb7eff-a529-9590-31e7-b0007b416f81
2013-10-11 18:21:56 +00:00
|
|
|
// "libgif warning [DGifGetLine]"
|
|
|
|
|
2014-01-21 23:39:22 +00:00
|
|
|
test_interlaced_gif_data(reporter, static_cast<void *>(gInterlacedGIF),
|
GIF decode: optional error messages and fault tolerance.
Add new runtime configuration variable,
images.gif.suppressDecoderWarnings, which suppresses warning and
errors from the GIF library. It defaults to "true", which is current
behavior.
(This setting can be changed by setting the environment variable
skia_images_gif_suppressDecoderWarnings="false".)
Some conditions which were errors before are now warnings:
- If the image width or height is greater than the GIF screen width or
height (respectively) we expand the screen to hold the image.
- If the offset of the image inside the screen would place the
image outside of the screen, we shift the image to fix this.
- If the image lacks a color table, we create a default color table.
- If the image is truncated, then the rest of the image is filled with
the fill color.
In all four cases, if images.gif.suppressDecoderWarnings is set to
false, then a warning message is printed via SkDebugf.
In the event of another kind of error, SkGIFImageDecoder::onDecode()
will still return false. But with this change, if
images.gif.suppressDecoderWarnings is set to false, a description of
the error is printed via SkDebugf.
Also, added a new unit test GifTest, which tests the deconing of both
good GIf files and corrupted files that should now work with this
change. This unit test is disabled on Win32, iOS, and Mac.
BUG=skia:1689
R=scroggo@google.com
Review URL: https://codereview.chromium.org/26743002
git-svn-id: http://skia.googlecode.com/svn/trunk@11734 2bbb7eff-a529-9590-31e7-b0007b416f81
2013-10-11 18:21:56 +00:00
|
|
|
100); // 100 is missing a few bytes
|
|
|
|
// "libgif warning [interlace DGifGetLine]"
|
|
|
|
}
|
|
|
|
|
2015-05-14 21:44:13 +00:00
|
|
|
// Regression test for decoding a gif image with sampleSize of 4, which was
|
|
|
|
// previously crashing.
|
|
|
|
DEF_TEST(Gif_Sampled, r) {
|
2017-12-09 01:27:41 +00:00
|
|
|
auto data = GetResourceAsData("images/test640x479.gif");
|
|
|
|
REPORTER_ASSERT(r, data);
|
|
|
|
if (!data) {
|
2015-05-14 21:44:13 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-12-09 01:27:41 +00:00
|
|
|
std::unique_ptr<SkStreamAsset> stream(new SkMemoryStream(std::move(data)));
|
2017-07-23 19:30:02 +00:00
|
|
|
std::unique_ptr<SkAndroidCodec> codec(SkAndroidCodec::MakeFromStream(std::move(stream)));
|
2016-03-01 20:12:27 +00:00
|
|
|
REPORTER_ASSERT(r, codec);
|
|
|
|
if (!codec) {
|
2015-05-14 21:44:13 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-03-01 20:12:27 +00:00
|
|
|
|
|
|
|
SkAndroidCodec::AndroidOptions options;
|
|
|
|
options.fSampleSize = 4;
|
|
|
|
|
2015-05-14 21:44:13 +00:00
|
|
|
SkBitmap bm;
|
2017-07-11 17:35:31 +00:00
|
|
|
bm.allocPixels(codec->getInfo());
|
2016-03-01 20:12:27 +00:00
|
|
|
const SkCodec::Result result = codec->getAndroidPixels(codec->getInfo(), bm.getPixels(),
|
|
|
|
bm.rowBytes(), &options);
|
|
|
|
REPORTER_ASSERT(r, result == SkCodec::kSuccess);
|
2015-05-14 21:44:13 +00:00
|
|
|
}
|
Do not create SkGifCodec if true size is not known
If there is enough data in the stream to read the reported canvas size,
but not enough to read the first image's header, we do not know the
true canvas size, since we may expand it to fit the first frame. In
that case, return nullptr from NewFromStream.
Add a test.
SkGifCodec.cpp:
Correct a comment - parse returns false if there is a fatal error.
parse() returning true does not guarantee that the size was found.
Instead of checking the width and height, check to see whether the
first frame exists and has its header defined. If not, we do not yet
know the true canvas size. Assert that the canvas size is non-zero,
which is a fatal error from parse.
SkGifImageReader.cpp:
Move the code to set the header defined before the SkGIFSizeQuery exit
condition. This allows SkGifCodec to check the first frame's header to
determine whether the size is known.
GifTest.cpp:
Add a test which truncates the file just before the image header (and
after the global header). Prior to the other changes, this would create
an SkCodec. For an image that needs its canvas size expanded, the
SkCodec would have an incorrect size.
CodecPartialTest.cpp:
randPixels.gif now needs more than half of its data to create an
SkCodec, so set a minimum for test_partial.
Change-Id: I40482f524128b2f1fe59b8f27dd64c7cbe793079
Reviewed-on: https://skia-review.googlesource.com/5701
Reviewed-by: Derek Sollenberger <djsollen@google.com>
Commit-Queue: Leon Scroggins <scroggo@google.com>
2016-12-08 16:54:04 +00:00
|
|
|
|
|
|
|
// If a GIF file is truncated before the header for the first image is defined,
|
|
|
|
// we should not create an SkCodec.
|
|
|
|
DEF_TEST(Codec_GifTruncated, r) {
|
2017-12-08 15:21:31 +00:00
|
|
|
sk_sp<SkData> data(GetResourceAsData("images/test640x479.gif"));
|
2017-07-18 20:22:52 +00:00
|
|
|
if (!data) {
|
|
|
|
return;
|
|
|
|
}
|
Do not create SkGifCodec if true size is not known
If there is enough data in the stream to read the reported canvas size,
but not enough to read the first image's header, we do not know the
true canvas size, since we may expand it to fit the first frame. In
that case, return nullptr from NewFromStream.
Add a test.
SkGifCodec.cpp:
Correct a comment - parse returns false if there is a fatal error.
parse() returning true does not guarantee that the size was found.
Instead of checking the width and height, check to see whether the
first frame exists and has its header defined. If not, we do not yet
know the true canvas size. Assert that the canvas size is non-zero,
which is a fatal error from parse.
SkGifImageReader.cpp:
Move the code to set the header defined before the SkGIFSizeQuery exit
condition. This allows SkGifCodec to check the first frame's header to
determine whether the size is known.
GifTest.cpp:
Add a test which truncates the file just before the image header (and
after the global header). Prior to the other changes, this would create
an SkCodec. For an image that needs its canvas size expanded, the
SkCodec would have an incorrect size.
CodecPartialTest.cpp:
randPixels.gif now needs more than half of its data to create an
SkCodec, so set a minimum for test_partial.
Change-Id: I40482f524128b2f1fe59b8f27dd64c7cbe793079
Reviewed-on: https://skia-review.googlesource.com/5701
Reviewed-by: Derek Sollenberger <djsollen@google.com>
Commit-Queue: Leon Scroggins <scroggo@google.com>
2016-12-08 16:54:04 +00:00
|
|
|
|
|
|
|
// This is right before the header for the first image.
|
|
|
|
data = SkData::MakeSubset(data.get(), 0, 446);
|
2017-07-23 19:30:02 +00:00
|
|
|
std::unique_ptr<SkCodec> codec(SkCodec::MakeFromData(data));
|
Do not create SkGifCodec if true size is not known
If there is enough data in the stream to read the reported canvas size,
but not enough to read the first image's header, we do not know the
true canvas size, since we may expand it to fit the first frame. In
that case, return nullptr from NewFromStream.
Add a test.
SkGifCodec.cpp:
Correct a comment - parse returns false if there is a fatal error.
parse() returning true does not guarantee that the size was found.
Instead of checking the width and height, check to see whether the
first frame exists and has its header defined. If not, we do not yet
know the true canvas size. Assert that the canvas size is non-zero,
which is a fatal error from parse.
SkGifImageReader.cpp:
Move the code to set the header defined before the SkGIFSizeQuery exit
condition. This allows SkGifCodec to check the first frame's header to
determine whether the size is known.
GifTest.cpp:
Add a test which truncates the file just before the image header (and
after the global header). Prior to the other changes, this would create
an SkCodec. For an image that needs its canvas size expanded, the
SkCodec would have an incorrect size.
CodecPartialTest.cpp:
randPixels.gif now needs more than half of its data to create an
SkCodec, so set a minimum for test_partial.
Change-Id: I40482f524128b2f1fe59b8f27dd64c7cbe793079
Reviewed-on: https://skia-review.googlesource.com/5701
Reviewed-by: Derek Sollenberger <djsollen@google.com>
Commit-Queue: Leon Scroggins <scroggo@google.com>
2016-12-08 16:54:04 +00:00
|
|
|
REPORTER_ASSERT(r, !codec);
|
|
|
|
}
|
2017-07-18 20:22:52 +00:00
|
|
|
|
2018-10-26 13:25:51 +00:00
|
|
|
/*
|
|
|
|
For the Codec_GifTruncated2 test, immediately below,
|
|
|
|
resources/images/box.gif's first 23 bytes are:
|
|
|
|
|
|
|
|
00000000: 4749 4638 3961 c800 3700 203f 002c 0000 GIF89a..7. ?.,..
|
|
|
|
00000010: 0000 c800 3700 85 ....7..
|
|
|
|
|
|
|
|
The breakdown:
|
|
|
|
|
|
|
|
@000 6 bytes magic "GIF89a"
|
|
|
|
@006 7 bytes Logical Screen Descriptor: 0xC8 0x00 ... 0x00
|
|
|
|
- width = 200
|
|
|
|
- height = 55
|
|
|
|
- flags = 0x20
|
|
|
|
- background color index, pixel aspect ratio bytes ignored
|
|
|
|
@00D 10 bytes Image Descriptor header: 0x2C 0x00 ... 0x85
|
|
|
|
- origin_x = 0
|
|
|
|
- origin_y = 0
|
|
|
|
- width = 200
|
|
|
|
- height = 55
|
|
|
|
- flags = 0x85, local color table, 64 RGB entries
|
|
|
|
|
|
|
|
In particular, 23 bytes is after the header, but before the color table.
|
|
|
|
*/
|
|
|
|
|
2017-07-18 20:22:52 +00:00
|
|
|
DEF_TEST(Codec_GifTruncated2, r) {
|
2018-10-26 13:25:51 +00:00
|
|
|
// Truncate box.gif at 21, 22 and 23 bytes.
|
|
|
|
//
|
|
|
|
// See also Codec_GifTruncated3 in this file, below.
|
|
|
|
//
|
|
|
|
// See also Codec_trunc in CodecAnimTest.cpp for this magic 23.
|
|
|
|
//
|
|
|
|
// See also Codec_GifPreMap in CodecPartialTest.cpp for this magic 23.
|
|
|
|
for (int i = 21; i < 24; i++) {
|
|
|
|
sk_sp<SkData> data(GetResourceAsData("images/box.gif"));
|
|
|
|
if (!data) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
data = SkData::MakeSubset(data.get(), 0, i);
|
|
|
|
std::unique_ptr<SkCodec> codec(SkCodec::MakeFromData(data));
|
|
|
|
|
|
|
|
if (i <= 21) {
|
|
|
|
if (codec) {
|
|
|
|
ERRORF(r, "Invalid data gave non-nullptr codec");
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!codec) {
|
|
|
|
ERRORF(r, "Failed to create codec with partial data (truncated at %d)", i);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef SK_HAS_WUFFS_LIBRARY
|
|
|
|
// We are transitioning from an old GIF implementation to a new (Wuffs)
|
|
|
|
// GIF implementation.
|
|
|
|
//
|
|
|
|
// The input is truncated in the Image Descriptor, before the local
|
|
|
|
// color table, and before (21) or after (22, 23) the first frame's
|
|
|
|
// XYWH (left / top / width / height) can be decoded. A detailed
|
|
|
|
// breakdown of those 23 bytes is in a comment above this function.
|
|
|
|
//
|
|
|
|
// With the old implementation, this test claimed that "no frame is
|
|
|
|
// complete enough that it has its metadata". In terms of the
|
|
|
|
// underlying file format, this claim is true for truncating at 21
|
|
|
|
// bytes, but not true for 22 or 23.
|
|
|
|
//
|
|
|
|
// At 21 bytes, both the old and new implementation's MakeFromStream
|
|
|
|
// factory method returns a nullptr SkCodec*, because creating a
|
|
|
|
// SkCodec requires knowing the image width and height (as its
|
|
|
|
// constructor takes an SkEncodedInfo argument), and specifically for
|
|
|
|
// GIF, decoding the image width and height requires decoding the first
|
|
|
|
// frame's XYWH, as per
|
|
|
|
// https://raw.githubusercontent.com/google/wuffs/master/test/data/artificial/gif-frame-out-of-bounds.gif.make-artificial.txt
|
|
|
|
//
|
|
|
|
// At 22 or 23 bytes, the first frame is complete enough that we can
|
|
|
|
// fill in all of a SkCodec::FrameInfo's fields (other than
|
|
|
|
// fFullyReceived). Specifically, we can fill in fRequiredFrame and
|
|
|
|
// fAlphaType, even though we haven't yet decoded the frame's RGB
|
|
|
|
// palette entries, as we do know the frame rectangle and that every
|
|
|
|
// palette entry is fully opaque, due to the lack of a Graphic Control
|
|
|
|
// Extension before the Image Descriptor.
|
|
|
|
//
|
|
|
|
// The new implementation correctly reports that the first frame's
|
|
|
|
// metadata is complete enough. The old implementation does not.
|
|
|
|
//
|
|
|
|
// Once the transition is complete, we can remove the #ifdef and delete
|
|
|
|
// the #else code.
|
|
|
|
REPORTER_ASSERT(r, codec->getFrameCount() == 1);
|
|
|
|
#else
|
|
|
|
// The old implementation claimed:
|
|
|
|
//
|
|
|
|
// Although we correctly created a codec, no frame is
|
|
|
|
// complete enough that it has its metadata. Returning 0
|
|
|
|
// ensures that Chromium will not try to create a frame
|
|
|
|
// too early.
|
|
|
|
REPORTER_ASSERT(r, codec->getFrameCount() == 0);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef SK_HAS_WUFFS_LIBRARY
|
|
|
|
// This tests that, after truncating the input, the pixels are still
|
|
|
|
// zero-initialized. If you comment out the SkSampler::Fill call in
|
|
|
|
// SkWuffsCodec::onStartIncrementalDecode, the test could still pass (in a
|
|
|
|
// standard configuration) but should fail with the MSAN memory sanitizer.
|
|
|
|
DEF_TEST(Codec_GifTruncated3, r) {
|
2017-12-08 15:21:31 +00:00
|
|
|
sk_sp<SkData> data(GetResourceAsData("images/box.gif"));
|
2017-07-18 20:22:52 +00:00
|
|
|
if (!data) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
data = SkData::MakeSubset(data.get(), 0, 23);
|
2018-10-26 13:25:51 +00:00
|
|
|
sk_sp<SkImage> image(SkImage::MakeFromEncoded(data));
|
|
|
|
|
|
|
|
if (!image) {
|
|
|
|
ERRORF(r, "Missing image");
|
2018-10-21 05:29:38 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-10-26 13:25:51 +00:00
|
|
|
REPORTER_ASSERT(r, image->width() == 200);
|
|
|
|
REPORTER_ASSERT(r, image->height() == 55);
|
|
|
|
|
|
|
|
SkBitmap bm;
|
|
|
|
if (!bm.tryAllocPixels(SkImageInfo::MakeN32Premul(200, 55))) {
|
|
|
|
ERRORF(r, "Failed to allocate pixels");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bm.eraseColor(SK_ColorTRANSPARENT);
|
|
|
|
|
|
|
|
SkCanvas canvas(bm);
|
|
|
|
canvas.drawImage(image, 0, 0, nullptr);
|
|
|
|
|
|
|
|
for (int i = 0; i < image->width(); ++i)
|
|
|
|
for (int j = 0; j < image->height(); ++j) {
|
|
|
|
SkColor actual = SkUnPreMultiply::PMColorToColor(*bm.getAddr32(i, j));
|
|
|
|
if (actual != SK_ColorTRANSPARENT) {
|
|
|
|
ERRORF(r, "did not initialize pixels! %i, %i is %x", i, j, actual);
|
|
|
|
}
|
|
|
|
}
|
2017-07-18 20:22:52 +00:00
|
|
|
}
|
2018-10-26 13:25:51 +00:00
|
|
|
#endif
|
2018-10-11 17:50:28 +00:00
|
|
|
|
|
|
|
DEF_TEST(Codec_gif_out_of_palette, r) {
|
|
|
|
if (GetResourcePath().isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* path = "images/out-of-palette.gif";
|
|
|
|
auto data = GetResourceAsData(path);
|
|
|
|
if (!data) {
|
|
|
|
ERRORF(r, "failed to find %s", path);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto codec = SkCodec::MakeFromData(std::move(data));
|
|
|
|
if (!codec) {
|
|
|
|
ERRORF(r, "Could not create codec from %s", path);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SkBitmap bm;
|
|
|
|
bm.allocPixels(codec->getInfo());
|
|
|
|
auto result = codec->getPixels(bm.pixmap());
|
|
|
|
REPORTER_ASSERT(r, result == SkCodec::kSuccess, "Failed to decode %s with error %s",
|
|
|
|
path, SkCodec::ResultToString(result));
|
|
|
|
|
|
|
|
struct {
|
|
|
|
int x;
|
|
|
|
int y;
|
|
|
|
SkColor expected;
|
|
|
|
} pixels[] = {
|
|
|
|
{ 0, 0, SK_ColorBLACK },
|
|
|
|
{ 1, 0, SK_ColorWHITE },
|
|
|
|
{ 0, 1, SK_ColorTRANSPARENT },
|
|
|
|
{ 1, 1, SK_ColorTRANSPARENT },
|
|
|
|
};
|
|
|
|
for (auto& pixel : pixels) {
|
|
|
|
auto actual = bm.getColor(pixel.x, pixel.y);
|
|
|
|
REPORTER_ASSERT(r, actual == pixel.expected,
|
|
|
|
"pixel (%i,%i) mismatch! expected: %x actual: %x",
|
|
|
|
pixel.x, pixel.y, pixel.expected, actual);
|
|
|
|
}
|
|
|
|
}
|