2015-03-03 16:59:20 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2015 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SkCodec_DEFINED
|
|
|
|
#define SkCodec_DEFINED
|
|
|
|
|
2015-08-19 18:56:48 +00:00
|
|
|
#include "../private/SkTemplates.h"
|
SkCodec no longer inherits from SkImageGenerator.
SkImageGenerator makes some assumptions that are not necessarily valid
for SkCodec. For example, SkCodec does not assume that it can always be
rewound.
We also have an ongoing question of what an SkCodec should report as
its default settings (i.e. the return from getInfo). It makes sense for
an SkCodec to report that its pixels are unpremultiplied, if that is
the case for the underlying data, but if a client of SkImageGenerator
uses the default settings (as many do), they will receive
unpremultiplied pixels which cannot (currently) be drawn with Skia. We
may ultimately decide to revisit SkCodec reporting an SkImageInfo, but
I have left it unchanged for now.
Import features of SkImageGenerator used by SkCodec into SkCodec.
I have left SkImageGenerator unchanged for now, but it no longer needs
Result or Options. This will require changes to Chromium.
Manually handle the lifetime of fScanlineDecoder, so SkScanlineDecoder.h
can include SkCodec.h (where Result is), and SkCodec.h does not need
to include it (to delete fScanlineDecoder).
In many places, make the following simple changes:
- Now include SkScanlineDecoder.h, which is no longer included by
SkCodec.h
- Use the enums in SkCodec, rather than SkImageGenerator
- Stop including SkImageGenerator.h where no longer needed
Review URL: https://codereview.chromium.org/1220733013
2015-07-09 15:16:03 +00:00
|
|
|
#include "SkColor.h"
|
2015-03-20 18:55:55 +00:00
|
|
|
#include "SkEncodedFormat.h"
|
2016-04-20 18:53:35 +00:00
|
|
|
#include "SkEncodedInfo.h"
|
2015-03-03 16:59:20 +00:00
|
|
|
#include "SkImageInfo.h"
|
|
|
|
#include "SkSize.h"
|
2015-03-18 17:50:37 +00:00
|
|
|
#include "SkStream.h"
|
2015-03-03 16:59:20 +00:00
|
|
|
#include "SkTypes.h"
|
2016-03-10 13:44:43 +00:00
|
|
|
#include "SkYUVSizeInfo.h"
|
2015-03-03 16:59:20 +00:00
|
|
|
|
2016-03-07 15:09:03 +00:00
|
|
|
class SkColorSpace;
|
2015-03-03 16:59:20 +00:00
|
|
|
class SkData;
|
2015-11-23 16:14:40 +00:00
|
|
|
class SkPngChunkReader;
|
2015-10-02 20:14:46 +00:00
|
|
|
class SkSampler;
|
2015-03-03 16:59:20 +00:00
|
|
|
|
2016-06-01 21:47:18 +00:00
|
|
|
namespace DM {
|
|
|
|
class ColorCodecSrc;
|
|
|
|
}
|
2016-06-03 15:25:21 +00:00
|
|
|
class ColorCodecBench;
|
2016-06-01 21:47:18 +00:00
|
|
|
|
Revert of Make SkPngCodec decode progressively. (patchset #26 id:520001 of https://codereview.chromium.org/1997703003/ )
Reason for revert:
Still causing problems in Google3, e.g.
https://test.corp.google.com/ui#cl=124138817&flags=CAMQBQ==&id=OCL:124138817:BASE:124139560:1465227435491:219ffbdb&t=//third_party/skia/HEAD:dm
Original issue's description:
> Make SkPngCodec decode progressively.
>
> This is a step towards using SkCodec in Chromium, where progressive
> decoding is necessary.
>
> Switch from using png_read_row (which expects all the data to be
> available) to png_process_data, which uses callbacks when rows are
> available.
>
> Create a new API for SkCodec, which supports progressive decoding and
> scanline decoding. Future changes will switch the other clients off of
> startScanlineDecode and get/skip-Scanlines to the new API.
>
> Remove SkCodec::kNone_ScanlineOrder, which was only used for interlaced
> PNG images. In the new API, interlaced PNG fits kTopDown. Also remove
> updateCurrScanline(), which was only used by the old implementation for
> interlaced PNG.
>
> DMSrcSink:
> - In CodecSrc::kScanline_Mode, use the new method for scanline decoding
> for the supported formats (just PNG and PNG-in-ICO for now).
>
> fuzz.cpp:
> - Remove reference to kNone_ScanlineOrder
>
> SkCodec:
> - Add new APIs:
> - startIncrementalDecode
> - incrementalDecode
> - Remove kNone_SkScanlineOrder and updateCurrScanline()
>
> SkPngCodec:
> - Implement new APIs
> - Switch from sk_read_fn/png_read_row etc to png_process_data
> - Expand AutoCleanPng's role to decode the header and create the
> SkPngCodec
> - Make the interlaced PNG decoder report how many lines were
> initialized during an incomplete decode
> - Make initializeSwizzler return a bool instead of an SkCodec::Result
> (It only returned kSuccess or kInvalidInput anyway)
>
> SkIcoCodec:
> - Implement the new APIs; supported for PNG in ICO
>
> SkSampledCodec:
> - Call the new method for decoding scanlines, and fall back to the old
> method if the new version is unimplemented
> - Remove references to kNone_SkScanlineOrder
>
> tests/CodecPartial:
> - Add a test which decodes part of an image, then finishes the decode,
> and compares it to the straightforward method
>
> tests/CodecTest:
> - Add a test which decodes all scanlines using the new method
> - Repurpose the Codec_stripes test to decode using the new method in
> sections rather than all at once
> - In the method check(), add a parameter for whether the image supports
> the new method of scanline decoding, and be explicit about whether an
> image supports incomplete
> - Test incomplete PNG decodes. We should have been doing it anyway for
> non-interlaced (except for an image that is too small - one row), but
> the new method supports interlaced incomplete as well
> - Make test_invalid_parameters test the new method
> - Add a test to ensure that it's safe to fall back to scanline decoding without
> rewinding
>
> BUG=skia:4211
>
> The new version was generally faster than the old version (but not significantly so).
>
> Some raw performance differences can be found at https://docs.google.com/a/google.com/spreadsheets/d/1Gis3aRCEa72qBNDRMgGDg3jD-pMgO-FXldlNF9ejo4o/
>
> Design doc can be found at https://docs.google.com/a/google.com/document/d/11Mn8-ePDKwVEMCjs3nWwSjxcSpJ_Cu8DF57KNtUmgLM/
>
> GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1997703003
>
> Committed: https://skia.googlesource.com/skia/+/a4b09a117d4d1ba5dda372e6a2323e653766539e
>
> Committed: https://skia.googlesource.com/skia/+/30e78c9737ff4861dc4e3fa1e4cd010680ed6965
>
> Committed: https://skia.googlesource.com/skia/+/6fb2391b2cc83ee2160b4e994faa8128975acc1f
TBR=reed@google.com,msarett@google.com,scroggo@chromium.org
# Not skipping CQ checks because original CL landed more than 1 days ago.
BUG=skia:4211
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2044573002
Review-Url: https://codereview.chromium.org/2044573002
2016-06-06 18:26:17 +00:00
|
|
|
|
2015-03-03 16:59:20 +00:00
|
|
|
/**
|
|
|
|
* Abstraction layer directly on top of an image codec.
|
|
|
|
*/
|
SkCodec no longer inherits from SkImageGenerator.
SkImageGenerator makes some assumptions that are not necessarily valid
for SkCodec. For example, SkCodec does not assume that it can always be
rewound.
We also have an ongoing question of what an SkCodec should report as
its default settings (i.e. the return from getInfo). It makes sense for
an SkCodec to report that its pixels are unpremultiplied, if that is
the case for the underlying data, but if a client of SkImageGenerator
uses the default settings (as many do), they will receive
unpremultiplied pixels which cannot (currently) be drawn with Skia. We
may ultimately decide to revisit SkCodec reporting an SkImageInfo, but
I have left it unchanged for now.
Import features of SkImageGenerator used by SkCodec into SkCodec.
I have left SkImageGenerator unchanged for now, but it no longer needs
Result or Options. This will require changes to Chromium.
Manually handle the lifetime of fScanlineDecoder, so SkScanlineDecoder.h
can include SkCodec.h (where Result is), and SkCodec.h does not need
to include it (to delete fScanlineDecoder).
In many places, make the following simple changes:
- Now include SkScanlineDecoder.h, which is no longer included by
SkCodec.h
- Use the enums in SkCodec, rather than SkImageGenerator
- Stop including SkImageGenerator.h where no longer needed
Review URL: https://codereview.chromium.org/1220733013
2015-07-09 15:16:03 +00:00
|
|
|
class SkCodec : SkNoncopyable {
|
2015-03-03 16:59:20 +00:00
|
|
|
public:
|
2015-12-09 02:54:13 +00:00
|
|
|
/**
|
|
|
|
* Minimum number of bytes that must be buffered in SkStream input.
|
|
|
|
*
|
|
|
|
* An SkStream passed to NewFromStream must be able to use this many
|
|
|
|
* bytes to determine the image type. Then the same SkStream must be
|
|
|
|
* passed to the correct decoder to read from the beginning.
|
|
|
|
*
|
|
|
|
* This can be accomplished by implementing peek() to support peeking
|
|
|
|
* this many bytes, or by implementing rewind() to be able to rewind()
|
|
|
|
* after reading this many bytes.
|
|
|
|
*/
|
|
|
|
static size_t MinBufferedBytesNeeded();
|
|
|
|
|
2015-03-03 16:59:20 +00:00
|
|
|
/**
|
|
|
|
* If this stream represents an encoded image that we know how to decode,
|
|
|
|
* return an SkCodec that can decode it. Otherwise return NULL.
|
|
|
|
*
|
2015-12-09 02:54:13 +00:00
|
|
|
* As stated above, this call must be able to peek or read
|
|
|
|
* MinBufferedBytesNeeded to determine the correct format, and then start
|
|
|
|
* reading from the beginning. First it will attempt to peek, and it
|
|
|
|
* assumes that if less than MinBufferedBytesNeeded bytes (but more than
|
|
|
|
* zero) are returned, this is because the stream is shorter than this,
|
|
|
|
* so falling back to reading would not provide more data. If peek()
|
|
|
|
* returns zero bytes, this call will instead attempt to read(). This
|
|
|
|
* will require that the stream can be rewind()ed.
|
|
|
|
*
|
|
|
|
* If SkPngChunkReader is not NULL, take a ref and pass it to libpng if
|
|
|
|
* the image is a png.
|
|
|
|
*
|
2015-12-02 15:02:41 +00:00
|
|
|
* If the SkPngChunkReader is not NULL then:
|
|
|
|
* If the image is not a PNG, the SkPngChunkReader will be ignored.
|
|
|
|
* If the image is a PNG, the SkPngChunkReader will be reffed.
|
|
|
|
* If the PNG has unknown chunks, the SkPngChunkReader will be used
|
|
|
|
* to handle these chunks. SkPngChunkReader will be called to read
|
|
|
|
* any unknown chunk at any point during the creation of the codec
|
|
|
|
* or the decode. Note that if SkPngChunkReader fails to read a
|
|
|
|
* chunk, this could result in a failure to create the codec or a
|
|
|
|
* failure to decode the image.
|
|
|
|
* If the PNG does not contain unknown chunks, the SkPngChunkReader
|
|
|
|
* will not be used or modified.
|
2015-11-23 16:14:40 +00:00
|
|
|
*
|
2015-03-03 16:59:20 +00:00
|
|
|
* If NULL is returned, the stream is deleted immediately. Otherwise, the
|
|
|
|
* SkCodec takes ownership of it, and will delete it when done with it.
|
|
|
|
*/
|
2015-11-23 16:14:40 +00:00
|
|
|
static SkCodec* NewFromStream(SkStream*, SkPngChunkReader* = NULL);
|
2015-03-03 16:59:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* If this data represents an encoded image that we know how to decode,
|
|
|
|
* return an SkCodec that can decode it. Otherwise return NULL.
|
|
|
|
*
|
2015-12-02 15:02:41 +00:00
|
|
|
* If the SkPngChunkReader is not NULL then:
|
|
|
|
* If the image is not a PNG, the SkPngChunkReader will be ignored.
|
|
|
|
* If the image is a PNG, the SkPngChunkReader will be reffed.
|
|
|
|
* If the PNG has unknown chunks, the SkPngChunkReader will be used
|
|
|
|
* to handle these chunks. SkPngChunkReader will be called to read
|
|
|
|
* any unknown chunk at any point during the creation of the codec
|
|
|
|
* or the decode. Note that if SkPngChunkReader fails to read a
|
|
|
|
* chunk, this could result in a failure to create the codec or a
|
|
|
|
* failure to decode the image.
|
|
|
|
* If the PNG does not contain unknown chunks, the SkPngChunkReader
|
|
|
|
* will not be used or modified.
|
2015-11-23 16:14:40 +00:00
|
|
|
*
|
2015-03-03 16:59:20 +00:00
|
|
|
* Will take a ref if it returns a codec, else will not affect the data.
|
|
|
|
*/
|
2015-11-23 16:14:40 +00:00
|
|
|
static SkCodec* NewFromData(SkData*, SkPngChunkReader* = NULL);
|
2015-03-03 16:59:20 +00:00
|
|
|
|
SkCodec no longer inherits from SkImageGenerator.
SkImageGenerator makes some assumptions that are not necessarily valid
for SkCodec. For example, SkCodec does not assume that it can always be
rewound.
We also have an ongoing question of what an SkCodec should report as
its default settings (i.e. the return from getInfo). It makes sense for
an SkCodec to report that its pixels are unpremultiplied, if that is
the case for the underlying data, but if a client of SkImageGenerator
uses the default settings (as many do), they will receive
unpremultiplied pixels which cannot (currently) be drawn with Skia. We
may ultimately decide to revisit SkCodec reporting an SkImageInfo, but
I have left it unchanged for now.
Import features of SkImageGenerator used by SkCodec into SkCodec.
I have left SkImageGenerator unchanged for now, but it no longer needs
Result or Options. This will require changes to Chromium.
Manually handle the lifetime of fScanlineDecoder, so SkScanlineDecoder.h
can include SkCodec.h (where Result is), and SkCodec.h does not need
to include it (to delete fScanlineDecoder).
In many places, make the following simple changes:
- Now include SkScanlineDecoder.h, which is no longer included by
SkCodec.h
- Use the enums in SkCodec, rather than SkImageGenerator
- Stop including SkImageGenerator.h where no longer needed
Review URL: https://codereview.chromium.org/1220733013
2015-07-09 15:16:03 +00:00
|
|
|
virtual ~SkCodec();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the ImageInfo associated with this codec.
|
|
|
|
*/
|
Merge SkCodec with SkScanlineDecoder
Benefits:
- This mimics other decoding APIs (including the ones SkCodec relies
on, e.g. a png_struct, which can be used to decode an entire image or
one line at a time).
- It allows a client to ask us to do what we can do efficiently - i.e.
start from encoded data and either decode the whole thing or scanlines.
- It removes the duplicate methods which appeared in both SkCodec and
SkScanlineDecoder (some of which, e.g. in SkJpegScanlineDecoder, just
call fCodec->sameMethod()).
- It simplifies moving more checks into the base class (e.g. the
examples in skbug.com/4284).
BUG=skia:4175
BUG=skia:4284
=====================================================================
SkScanlineDecoder.h/.cpp:
Removed.
SkCodec.h/.cpp:
Add methods, enums, and variables which were previously in
SkScanlineDecoder.
Default fCurrScanline to -1, as a sentinel that start has not been
called.
General changes:
Convert SkScanlineDecoders to SkCodecs.
General changes in SkCodec subclasses:
Merge SkScanlineDecoder implementation into SkCodec. Most (all?) owned
an SkCodec, so they now call this-> instead of fCodec->.
SkBmpCodec.h/.cpp:
Replace the unused rowOrder method with an override for
onGetScanlineOrder.
Make getDstRow const, since it is called by onGetY, which is const.
SkCodec_libpng.h/.cpp:
Make SkPngCodec an abstract class, with two subclasses which handle
scanline decoding separately (they share code for decoding the entire
image). Reimplement onReallyHasAlpha so that it can return the most
recent result (e.g. after a scanline decode which only decoded part
of the image) or a better answer (e.g. if the whole image is known to
be opaque).
Compute fNumberPasses early, so we know which subclass to instantiate.
Make SkPngInterlaceScanlineDecoder use the base class' fCurrScanline
rather than a separate variable.
CodexTest.cpp:
Add tests for the state changes in SkCodec (need to call start before
decoding scanlines; calling getPixels means that start will need to
be called again before decoding more scanlines).
Add a test which decodes in stripes, currently only used for an
interlaced PNG.
TODO: Add tests for onReallyHasAlpha.
Review URL: https://codereview.chromium.org/1365313002
2015-09-30 15:57:13 +00:00
|
|
|
const SkImageInfo& getInfo() const { return fSrcInfo; }
|
SkCodec no longer inherits from SkImageGenerator.
SkImageGenerator makes some assumptions that are not necessarily valid
for SkCodec. For example, SkCodec does not assume that it can always be
rewound.
We also have an ongoing question of what an SkCodec should report as
its default settings (i.e. the return from getInfo). It makes sense for
an SkCodec to report that its pixels are unpremultiplied, if that is
the case for the underlying data, but if a client of SkImageGenerator
uses the default settings (as many do), they will receive
unpremultiplied pixels which cannot (currently) be drawn with Skia. We
may ultimately decide to revisit SkCodec reporting an SkImageInfo, but
I have left it unchanged for now.
Import features of SkImageGenerator used by SkCodec into SkCodec.
I have left SkImageGenerator unchanged for now, but it no longer needs
Result or Options. This will require changes to Chromium.
Manually handle the lifetime of fScanlineDecoder, so SkScanlineDecoder.h
can include SkCodec.h (where Result is), and SkCodec.h does not need
to include it (to delete fScanlineDecoder).
In many places, make the following simple changes:
- Now include SkScanlineDecoder.h, which is no longer included by
SkCodec.h
- Use the enums in SkCodec, rather than SkImageGenerator
- Stop including SkImageGenerator.h where no longer needed
Review URL: https://codereview.chromium.org/1220733013
2015-07-09 15:16:03 +00:00
|
|
|
|
2016-04-20 18:53:35 +00:00
|
|
|
const SkEncodedInfo& getEncodedInfo() const { return fEncodedInfo; }
|
|
|
|
|
2016-03-21 15:04:40 +00:00
|
|
|
enum Origin {
|
|
|
|
kTopLeft_Origin = 1, // Default
|
|
|
|
kTopRight_Origin = 2, // Reflected across y-axis
|
|
|
|
kBottomRight_Origin = 3, // Rotated 180
|
|
|
|
kBottomLeft_Origin = 4, // Reflected across x-axis
|
|
|
|
kLeftTop_Origin = 5, // Reflected across x-axis, Rotated 90 CCW
|
|
|
|
kRightTop_Origin = 6, // Rotated 90 CW
|
|
|
|
kRightBottom_Origin = 7, // Reflected across x-axis, Rotated 90 CW
|
|
|
|
kLeftBottom_Origin = 8, // Rotated 90 CCW
|
|
|
|
kDefault_Origin = kTopLeft_Origin,
|
|
|
|
kLast_Origin = kLeftBottom_Origin,
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the image orientation stored in the EXIF data.
|
|
|
|
* If there is no EXIF data, or if we cannot read the EXIF data, returns kTopLeft.
|
|
|
|
*/
|
|
|
|
Origin getOrigin() const { return fOrigin; }
|
|
|
|
|
2015-03-03 16:59:20 +00:00
|
|
|
/**
|
|
|
|
* Return a size that approximately supports the desired scale factor.
|
|
|
|
* The codec may not be able to scale efficiently to the exact scale
|
|
|
|
* factor requested, so return a size that approximates that scale.
|
2015-08-14 14:44:46 +00:00
|
|
|
* The returned value is the codec's suggestion for the closest valid
|
|
|
|
* scale that it can natively support
|
2015-03-03 16:59:20 +00:00
|
|
|
*/
|
2015-03-18 17:50:37 +00:00
|
|
|
SkISize getScaledDimensions(float desiredScale) const {
|
2015-08-18 20:22:46 +00:00
|
|
|
// Negative and zero scales are errors.
|
|
|
|
SkASSERT(desiredScale > 0.0f);
|
|
|
|
if (desiredScale <= 0.0f) {
|
|
|
|
return SkISize::Make(0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Upscaling is not supported. Return the original size if the client
|
|
|
|
// requests an upscale.
|
|
|
|
if (desiredScale >= 1.0f) {
|
|
|
|
return this->getInfo().dimensions();
|
|
|
|
}
|
2015-03-18 17:50:37 +00:00
|
|
|
return this->onGetScaledDimensions(desiredScale);
|
|
|
|
}
|
2015-03-03 16:59:20 +00:00
|
|
|
|
2015-07-22 14:16:20 +00:00
|
|
|
/**
|
|
|
|
* Return (via desiredSubset) a subset which can decoded from this codec,
|
|
|
|
* or false if this codec cannot decode subsets or anything similar to
|
|
|
|
* desiredSubset.
|
|
|
|
*
|
|
|
|
* @param desiredSubset In/out parameter. As input, a desired subset of
|
|
|
|
* the original bounds (as specified by getInfo). If true is returned,
|
|
|
|
* desiredSubset may have been modified to a subset which is
|
|
|
|
* supported. Although a particular change may have been made to
|
|
|
|
* desiredSubset to create something supported, it is possible other
|
|
|
|
* changes could result in a valid subset.
|
|
|
|
* If false is returned, desiredSubset's value is undefined.
|
|
|
|
* @return true if this codec supports decoding desiredSubset (as
|
|
|
|
* returned, potentially modified)
|
|
|
|
*/
|
|
|
|
bool getValidSubset(SkIRect* desiredSubset) const {
|
|
|
|
return this->onGetValidSubset(desiredSubset);
|
|
|
|
}
|
|
|
|
|
2015-03-20 18:55:55 +00:00
|
|
|
/**
|
|
|
|
* Format of the encoded data.
|
|
|
|
*/
|
|
|
|
SkEncodedFormat getEncodedFormat() const { return this->onGetEncodedFormat(); }
|
|
|
|
|
SkCodec no longer inherits from SkImageGenerator.
SkImageGenerator makes some assumptions that are not necessarily valid
for SkCodec. For example, SkCodec does not assume that it can always be
rewound.
We also have an ongoing question of what an SkCodec should report as
its default settings (i.e. the return from getInfo). It makes sense for
an SkCodec to report that its pixels are unpremultiplied, if that is
the case for the underlying data, but if a client of SkImageGenerator
uses the default settings (as many do), they will receive
unpremultiplied pixels which cannot (currently) be drawn with Skia. We
may ultimately decide to revisit SkCodec reporting an SkImageInfo, but
I have left it unchanged for now.
Import features of SkImageGenerator used by SkCodec into SkCodec.
I have left SkImageGenerator unchanged for now, but it no longer needs
Result or Options. This will require changes to Chromium.
Manually handle the lifetime of fScanlineDecoder, so SkScanlineDecoder.h
can include SkCodec.h (where Result is), and SkCodec.h does not need
to include it (to delete fScanlineDecoder).
In many places, make the following simple changes:
- Now include SkScanlineDecoder.h, which is no longer included by
SkCodec.h
- Use the enums in SkCodec, rather than SkImageGenerator
- Stop including SkImageGenerator.h where no longer needed
Review URL: https://codereview.chromium.org/1220733013
2015-07-09 15:16:03 +00:00
|
|
|
/**
|
|
|
|
* Used to describe the result of a call to getPixels().
|
|
|
|
*
|
|
|
|
* Result is the union of possible results from subclasses.
|
|
|
|
*/
|
|
|
|
enum Result {
|
|
|
|
/**
|
|
|
|
* General return value for success.
|
|
|
|
*/
|
|
|
|
kSuccess,
|
|
|
|
/**
|
|
|
|
* The input is incomplete. A partial image was generated.
|
|
|
|
*/
|
|
|
|
kIncompleteInput,
|
|
|
|
/**
|
|
|
|
* The generator cannot convert to match the request, ignoring
|
|
|
|
* dimensions.
|
|
|
|
*/
|
|
|
|
kInvalidConversion,
|
|
|
|
/**
|
|
|
|
* The generator cannot scale to requested size.
|
|
|
|
*/
|
|
|
|
kInvalidScale,
|
|
|
|
/**
|
|
|
|
* Parameters (besides info) are invalid. e.g. NULL pixels, rowBytes
|
|
|
|
* too small, etc.
|
|
|
|
*/
|
|
|
|
kInvalidParameters,
|
|
|
|
/**
|
|
|
|
* The input did not contain a valid image.
|
|
|
|
*/
|
|
|
|
kInvalidInput,
|
|
|
|
/**
|
|
|
|
* Fulfilling this request requires rewinding the input, which is not
|
|
|
|
* supported for this input.
|
|
|
|
*/
|
|
|
|
kCouldNotRewind,
|
Merge SkCodec with SkScanlineDecoder
Benefits:
- This mimics other decoding APIs (including the ones SkCodec relies
on, e.g. a png_struct, which can be used to decode an entire image or
one line at a time).
- It allows a client to ask us to do what we can do efficiently - i.e.
start from encoded data and either decode the whole thing or scanlines.
- It removes the duplicate methods which appeared in both SkCodec and
SkScanlineDecoder (some of which, e.g. in SkJpegScanlineDecoder, just
call fCodec->sameMethod()).
- It simplifies moving more checks into the base class (e.g. the
examples in skbug.com/4284).
BUG=skia:4175
BUG=skia:4284
=====================================================================
SkScanlineDecoder.h/.cpp:
Removed.
SkCodec.h/.cpp:
Add methods, enums, and variables which were previously in
SkScanlineDecoder.
Default fCurrScanline to -1, as a sentinel that start has not been
called.
General changes:
Convert SkScanlineDecoders to SkCodecs.
General changes in SkCodec subclasses:
Merge SkScanlineDecoder implementation into SkCodec. Most (all?) owned
an SkCodec, so they now call this-> instead of fCodec->.
SkBmpCodec.h/.cpp:
Replace the unused rowOrder method with an override for
onGetScanlineOrder.
Make getDstRow const, since it is called by onGetY, which is const.
SkCodec_libpng.h/.cpp:
Make SkPngCodec an abstract class, with two subclasses which handle
scanline decoding separately (they share code for decoding the entire
image). Reimplement onReallyHasAlpha so that it can return the most
recent result (e.g. after a scanline decode which only decoded part
of the image) or a better answer (e.g. if the whole image is known to
be opaque).
Compute fNumberPasses early, so we know which subclass to instantiate.
Make SkPngInterlaceScanlineDecoder use the base class' fCurrScanline
rather than a separate variable.
CodexTest.cpp:
Add tests for the state changes in SkCodec (need to call start before
decoding scanlines; calling getPixels means that start will need to
be called again before decoding more scanlines).
Add a test which decodes in stripes, currently only used for an
interlaced PNG.
TODO: Add tests for onReallyHasAlpha.
Review URL: https://codereview.chromium.org/1365313002
2015-09-30 15:57:13 +00:00
|
|
|
/**
|
|
|
|
* This method is not implemented by this codec.
|
|
|
|
* FIXME: Perhaps this should be kUnsupported?
|
SkCodec no longer inherits from SkImageGenerator.
SkImageGenerator makes some assumptions that are not necessarily valid
for SkCodec. For example, SkCodec does not assume that it can always be
rewound.
We also have an ongoing question of what an SkCodec should report as
its default settings (i.e. the return from getInfo). It makes sense for
an SkCodec to report that its pixels are unpremultiplied, if that is
the case for the underlying data, but if a client of SkImageGenerator
uses the default settings (as many do), they will receive
unpremultiplied pixels which cannot (currently) be drawn with Skia. We
may ultimately decide to revisit SkCodec reporting an SkImageInfo, but
I have left it unchanged for now.
Import features of SkImageGenerator used by SkCodec into SkCodec.
I have left SkImageGenerator unchanged for now, but it no longer needs
Result or Options. This will require changes to Chromium.
Manually handle the lifetime of fScanlineDecoder, so SkScanlineDecoder.h
can include SkCodec.h (where Result is), and SkCodec.h does not need
to include it (to delete fScanlineDecoder).
In many places, make the following simple changes:
- Now include SkScanlineDecoder.h, which is no longer included by
SkCodec.h
- Use the enums in SkCodec, rather than SkImageGenerator
- Stop including SkImageGenerator.h where no longer needed
Review URL: https://codereview.chromium.org/1220733013
2015-07-09 15:16:03 +00:00
|
|
|
*/
|
|
|
|
kUnimplemented,
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether or not the memory passed to getPixels is zero initialized.
|
|
|
|
*/
|
|
|
|
enum ZeroInitialized {
|
|
|
|
/**
|
|
|
|
* The memory passed to getPixels is zero initialized. The SkCodec
|
|
|
|
* may take advantage of this by skipping writing zeroes.
|
|
|
|
*/
|
|
|
|
kYes_ZeroInitialized,
|
|
|
|
/**
|
|
|
|
* The memory passed to getPixels has not been initialized to zero,
|
|
|
|
* so the SkCodec must write all zeroes to memory.
|
|
|
|
*
|
|
|
|
* This is the default. It will be used if no Options struct is used.
|
|
|
|
*/
|
|
|
|
kNo_ZeroInitialized,
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Additional options to pass to getPixels.
|
|
|
|
*/
|
|
|
|
struct Options {
|
|
|
|
Options()
|
2015-07-22 14:16:20 +00:00
|
|
|
: fZeroInitialized(kNo_ZeroInitialized)
|
|
|
|
, fSubset(NULL)
|
|
|
|
{}
|
SkCodec no longer inherits from SkImageGenerator.
SkImageGenerator makes some assumptions that are not necessarily valid
for SkCodec. For example, SkCodec does not assume that it can always be
rewound.
We also have an ongoing question of what an SkCodec should report as
its default settings (i.e. the return from getInfo). It makes sense for
an SkCodec to report that its pixels are unpremultiplied, if that is
the case for the underlying data, but if a client of SkImageGenerator
uses the default settings (as many do), they will receive
unpremultiplied pixels which cannot (currently) be drawn with Skia. We
may ultimately decide to revisit SkCodec reporting an SkImageInfo, but
I have left it unchanged for now.
Import features of SkImageGenerator used by SkCodec into SkCodec.
I have left SkImageGenerator unchanged for now, but it no longer needs
Result or Options. This will require changes to Chromium.
Manually handle the lifetime of fScanlineDecoder, so SkScanlineDecoder.h
can include SkCodec.h (where Result is), and SkCodec.h does not need
to include it (to delete fScanlineDecoder).
In many places, make the following simple changes:
- Now include SkScanlineDecoder.h, which is no longer included by
SkCodec.h
- Use the enums in SkCodec, rather than SkImageGenerator
- Stop including SkImageGenerator.h where no longer needed
Review URL: https://codereview.chromium.org/1220733013
2015-07-09 15:16:03 +00:00
|
|
|
|
|
|
|
ZeroInitialized fZeroInitialized;
|
2015-07-22 14:16:20 +00:00
|
|
|
/**
|
|
|
|
* If not NULL, represents a subset of the original image to decode.
|
|
|
|
* Must be within the bounds returned by getInfo().
|
|
|
|
* If the EncodedFormat is kWEBP_SkEncodedFormat (the only one which
|
|
|
|
* currently supports subsets), the top and left values must be even.
|
2015-10-13 19:50:14 +00:00
|
|
|
*
|
Revert of Make SkPngCodec decode progressively. (patchset #26 id:520001 of https://codereview.chromium.org/1997703003/ )
Reason for revert:
Still causing problems in Google3, e.g.
https://test.corp.google.com/ui#cl=124138817&flags=CAMQBQ==&id=OCL:124138817:BASE:124139560:1465227435491:219ffbdb&t=//third_party/skia/HEAD:dm
Original issue's description:
> Make SkPngCodec decode progressively.
>
> This is a step towards using SkCodec in Chromium, where progressive
> decoding is necessary.
>
> Switch from using png_read_row (which expects all the data to be
> available) to png_process_data, which uses callbacks when rows are
> available.
>
> Create a new API for SkCodec, which supports progressive decoding and
> scanline decoding. Future changes will switch the other clients off of
> startScanlineDecode and get/skip-Scanlines to the new API.
>
> Remove SkCodec::kNone_ScanlineOrder, which was only used for interlaced
> PNG images. In the new API, interlaced PNG fits kTopDown. Also remove
> updateCurrScanline(), which was only used by the old implementation for
> interlaced PNG.
>
> DMSrcSink:
> - In CodecSrc::kScanline_Mode, use the new method for scanline decoding
> for the supported formats (just PNG and PNG-in-ICO for now).
>
> fuzz.cpp:
> - Remove reference to kNone_ScanlineOrder
>
> SkCodec:
> - Add new APIs:
> - startIncrementalDecode
> - incrementalDecode
> - Remove kNone_SkScanlineOrder and updateCurrScanline()
>
> SkPngCodec:
> - Implement new APIs
> - Switch from sk_read_fn/png_read_row etc to png_process_data
> - Expand AutoCleanPng's role to decode the header and create the
> SkPngCodec
> - Make the interlaced PNG decoder report how many lines were
> initialized during an incomplete decode
> - Make initializeSwizzler return a bool instead of an SkCodec::Result
> (It only returned kSuccess or kInvalidInput anyway)
>
> SkIcoCodec:
> - Implement the new APIs; supported for PNG in ICO
>
> SkSampledCodec:
> - Call the new method for decoding scanlines, and fall back to the old
> method if the new version is unimplemented
> - Remove references to kNone_SkScanlineOrder
>
> tests/CodecPartial:
> - Add a test which decodes part of an image, then finishes the decode,
> and compares it to the straightforward method
>
> tests/CodecTest:
> - Add a test which decodes all scanlines using the new method
> - Repurpose the Codec_stripes test to decode using the new method in
> sections rather than all at once
> - In the method check(), add a parameter for whether the image supports
> the new method of scanline decoding, and be explicit about whether an
> image supports incomplete
> - Test incomplete PNG decodes. We should have been doing it anyway for
> non-interlaced (except for an image that is too small - one row), but
> the new method supports interlaced incomplete as well
> - Make test_invalid_parameters test the new method
> - Add a test to ensure that it's safe to fall back to scanline decoding without
> rewinding
>
> BUG=skia:4211
>
> The new version was generally faster than the old version (but not significantly so).
>
> Some raw performance differences can be found at https://docs.google.com/a/google.com/spreadsheets/d/1Gis3aRCEa72qBNDRMgGDg3jD-pMgO-FXldlNF9ejo4o/
>
> Design doc can be found at https://docs.google.com/a/google.com/document/d/11Mn8-ePDKwVEMCjs3nWwSjxcSpJ_Cu8DF57KNtUmgLM/
>
> GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1997703003
>
> Committed: https://skia.googlesource.com/skia/+/a4b09a117d4d1ba5dda372e6a2323e653766539e
>
> Committed: https://skia.googlesource.com/skia/+/30e78c9737ff4861dc4e3fa1e4cd010680ed6965
>
> Committed: https://skia.googlesource.com/skia/+/6fb2391b2cc83ee2160b4e994faa8128975acc1f
TBR=reed@google.com,msarett@google.com,scroggo@chromium.org
# Not skipping CQ checks because original CL landed more than 1 days ago.
BUG=skia:4211
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2044573002
Review-Url: https://codereview.chromium.org/2044573002
2016-06-06 18:26:17 +00:00
|
|
|
* In getPixels, we will attempt to decode the exact rectangular
|
|
|
|
* subset specified by fSubset.
|
2015-10-13 19:50:14 +00:00
|
|
|
*
|
|
|
|
* In a scanline decode, it does not make sense to specify a subset
|
|
|
|
* top or subset height, since the client already controls which rows
|
|
|
|
* to get and which rows to skip. During scanline decodes, we will
|
|
|
|
* require that the subset top be zero and the subset height be equal
|
|
|
|
* to the full height. We will, however, use the values of
|
|
|
|
* subset left and subset width to decode partial scanlines on calls
|
|
|
|
* to getScanlines().
|
2015-07-22 14:16:20 +00:00
|
|
|
*/
|
|
|
|
SkIRect* fSubset;
|
SkCodec no longer inherits from SkImageGenerator.
SkImageGenerator makes some assumptions that are not necessarily valid
for SkCodec. For example, SkCodec does not assume that it can always be
rewound.
We also have an ongoing question of what an SkCodec should report as
its default settings (i.e. the return from getInfo). It makes sense for
an SkCodec to report that its pixels are unpremultiplied, if that is
the case for the underlying data, but if a client of SkImageGenerator
uses the default settings (as many do), they will receive
unpremultiplied pixels which cannot (currently) be drawn with Skia. We
may ultimately decide to revisit SkCodec reporting an SkImageInfo, but
I have left it unchanged for now.
Import features of SkImageGenerator used by SkCodec into SkCodec.
I have left SkImageGenerator unchanged for now, but it no longer needs
Result or Options. This will require changes to Chromium.
Manually handle the lifetime of fScanlineDecoder, so SkScanlineDecoder.h
can include SkCodec.h (where Result is), and SkCodec.h does not need
to include it (to delete fScanlineDecoder).
In many places, make the following simple changes:
- Now include SkScanlineDecoder.h, which is no longer included by
SkCodec.h
- Use the enums in SkCodec, rather than SkImageGenerator
- Stop including SkImageGenerator.h where no longer needed
Review URL: https://codereview.chromium.org/1220733013
2015-07-09 15:16:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Decode into the given pixels, a block of memory of size at
|
|
|
|
* least (info.fHeight - 1) * rowBytes + (info.fWidth *
|
|
|
|
* bytesPerPixel)
|
|
|
|
*
|
|
|
|
* Repeated calls to this function should give the same results,
|
|
|
|
* allowing the PixelRef to be immutable.
|
|
|
|
*
|
|
|
|
* @param info A description of the format (config, size)
|
|
|
|
* expected by the caller. This can simply be identical
|
|
|
|
* to the info returned by getInfo().
|
|
|
|
*
|
|
|
|
* This contract also allows the caller to specify
|
|
|
|
* different output-configs, which the implementation can
|
|
|
|
* decide to support or not.
|
|
|
|
*
|
|
|
|
* A size that does not match getInfo() implies a request
|
|
|
|
* to scale. If the generator cannot perform this scale,
|
|
|
|
* it will return kInvalidScale.
|
|
|
|
*
|
|
|
|
* If info is kIndex8_SkColorType, then the caller must provide storage for up to 256
|
|
|
|
* SkPMColor values in ctable. On success the generator must copy N colors into that storage,
|
|
|
|
* (where N is the logical number of table entries) and set ctableCount to N.
|
|
|
|
*
|
|
|
|
* If info is not kIndex8_SkColorType, then the last two parameters may be NULL. If ctableCount
|
|
|
|
* is not null, it will be set to 0.
|
|
|
|
*
|
Merge SkCodec with SkScanlineDecoder
Benefits:
- This mimics other decoding APIs (including the ones SkCodec relies
on, e.g. a png_struct, which can be used to decode an entire image or
one line at a time).
- It allows a client to ask us to do what we can do efficiently - i.e.
start from encoded data and either decode the whole thing or scanlines.
- It removes the duplicate methods which appeared in both SkCodec and
SkScanlineDecoder (some of which, e.g. in SkJpegScanlineDecoder, just
call fCodec->sameMethod()).
- It simplifies moving more checks into the base class (e.g. the
examples in skbug.com/4284).
BUG=skia:4175
BUG=skia:4284
=====================================================================
SkScanlineDecoder.h/.cpp:
Removed.
SkCodec.h/.cpp:
Add methods, enums, and variables which were previously in
SkScanlineDecoder.
Default fCurrScanline to -1, as a sentinel that start has not been
called.
General changes:
Convert SkScanlineDecoders to SkCodecs.
General changes in SkCodec subclasses:
Merge SkScanlineDecoder implementation into SkCodec. Most (all?) owned
an SkCodec, so they now call this-> instead of fCodec->.
SkBmpCodec.h/.cpp:
Replace the unused rowOrder method with an override for
onGetScanlineOrder.
Make getDstRow const, since it is called by onGetY, which is const.
SkCodec_libpng.h/.cpp:
Make SkPngCodec an abstract class, with two subclasses which handle
scanline decoding separately (they share code for decoding the entire
image). Reimplement onReallyHasAlpha so that it can return the most
recent result (e.g. after a scanline decode which only decoded part
of the image) or a better answer (e.g. if the whole image is known to
be opaque).
Compute fNumberPasses early, so we know which subclass to instantiate.
Make SkPngInterlaceScanlineDecoder use the base class' fCurrScanline
rather than a separate variable.
CodexTest.cpp:
Add tests for the state changes in SkCodec (need to call start before
decoding scanlines; calling getPixels means that start will need to
be called again before decoding more scanlines).
Add a test which decodes in stripes, currently only used for an
interlaced PNG.
TODO: Add tests for onReallyHasAlpha.
Review URL: https://codereview.chromium.org/1365313002
2015-09-30 15:57:13 +00:00
|
|
|
* If a scanline decode is in progress, scanline mode will end, requiring the client to call
|
|
|
|
* startScanlineDecode() in order to return to decoding scanlines.
|
|
|
|
*
|
SkCodec no longer inherits from SkImageGenerator.
SkImageGenerator makes some assumptions that are not necessarily valid
for SkCodec. For example, SkCodec does not assume that it can always be
rewound.
We also have an ongoing question of what an SkCodec should report as
its default settings (i.e. the return from getInfo). It makes sense for
an SkCodec to report that its pixels are unpremultiplied, if that is
the case for the underlying data, but if a client of SkImageGenerator
uses the default settings (as many do), they will receive
unpremultiplied pixels which cannot (currently) be drawn with Skia. We
may ultimately decide to revisit SkCodec reporting an SkImageInfo, but
I have left it unchanged for now.
Import features of SkImageGenerator used by SkCodec into SkCodec.
I have left SkImageGenerator unchanged for now, but it no longer needs
Result or Options. This will require changes to Chromium.
Manually handle the lifetime of fScanlineDecoder, so SkScanlineDecoder.h
can include SkCodec.h (where Result is), and SkCodec.h does not need
to include it (to delete fScanlineDecoder).
In many places, make the following simple changes:
- Now include SkScanlineDecoder.h, which is no longer included by
SkCodec.h
- Use the enums in SkCodec, rather than SkImageGenerator
- Stop including SkImageGenerator.h where no longer needed
Review URL: https://codereview.chromium.org/1220733013
2015-07-09 15:16:03 +00:00
|
|
|
* @return Result kSuccess, or another value explaining the type of failure.
|
|
|
|
*/
|
|
|
|
Result getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes, const Options*,
|
|
|
|
SkPMColor ctable[], int* ctableCount);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Simplified version of getPixels() that asserts that info is NOT kIndex8_SkColorType and
|
|
|
|
* uses the default Options.
|
|
|
|
*/
|
|
|
|
Result getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes);
|
|
|
|
|
2016-01-22 22:46:42 +00:00
|
|
|
/**
|
|
|
|
* If decoding to YUV is supported, this returns true. Otherwise, this
|
|
|
|
* returns false and does not modify any of the parameters.
|
|
|
|
*
|
|
|
|
* @param sizeInfo Output parameter indicating the sizes and required
|
|
|
|
* allocation widths of the Y, U, and V planes.
|
|
|
|
* @param colorSpace Output parameter. If non-NULL this is set to kJPEG,
|
|
|
|
* otherwise this is ignored.
|
|
|
|
*/
|
2016-03-10 13:44:43 +00:00
|
|
|
bool queryYUV8(SkYUVSizeInfo* sizeInfo, SkYUVColorSpace* colorSpace) const {
|
2016-01-22 22:46:42 +00:00
|
|
|
if (nullptr == sizeInfo) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return this->onQueryYUV8(sizeInfo, colorSpace);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns kSuccess, or another value explaining the type of failure.
|
|
|
|
* This always attempts to perform a full decode. If the client only
|
|
|
|
* wants size, it should call queryYUV8().
|
|
|
|
*
|
|
|
|
* @param sizeInfo Needs to exactly match the values returned by the
|
|
|
|
* query, except the WidthBytes may be larger than the
|
|
|
|
* recommendation (but not smaller).
|
|
|
|
* @param planes Memory for each of the Y, U, and V planes.
|
|
|
|
*/
|
2016-03-10 13:44:43 +00:00
|
|
|
Result getYUV8Planes(const SkYUVSizeInfo& sizeInfo, void* planes[3]) {
|
2016-01-22 22:46:42 +00:00
|
|
|
if (nullptr == planes || nullptr == planes[0] || nullptr == planes[1] ||
|
|
|
|
nullptr == planes[2]) {
|
|
|
|
return kInvalidInput;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!this->rewindIfNeeded()) {
|
|
|
|
return kCouldNotRewind;
|
|
|
|
}
|
|
|
|
|
|
|
|
return this->onGetYUV8Planes(sizeInfo, planes);
|
|
|
|
}
|
|
|
|
|
Merge SkCodec with SkScanlineDecoder
Benefits:
- This mimics other decoding APIs (including the ones SkCodec relies
on, e.g. a png_struct, which can be used to decode an entire image or
one line at a time).
- It allows a client to ask us to do what we can do efficiently - i.e.
start from encoded data and either decode the whole thing or scanlines.
- It removes the duplicate methods which appeared in both SkCodec and
SkScanlineDecoder (some of which, e.g. in SkJpegScanlineDecoder, just
call fCodec->sameMethod()).
- It simplifies moving more checks into the base class (e.g. the
examples in skbug.com/4284).
BUG=skia:4175
BUG=skia:4284
=====================================================================
SkScanlineDecoder.h/.cpp:
Removed.
SkCodec.h/.cpp:
Add methods, enums, and variables which were previously in
SkScanlineDecoder.
Default fCurrScanline to -1, as a sentinel that start has not been
called.
General changes:
Convert SkScanlineDecoders to SkCodecs.
General changes in SkCodec subclasses:
Merge SkScanlineDecoder implementation into SkCodec. Most (all?) owned
an SkCodec, so they now call this-> instead of fCodec->.
SkBmpCodec.h/.cpp:
Replace the unused rowOrder method with an override for
onGetScanlineOrder.
Make getDstRow const, since it is called by onGetY, which is const.
SkCodec_libpng.h/.cpp:
Make SkPngCodec an abstract class, with two subclasses which handle
scanline decoding separately (they share code for decoding the entire
image). Reimplement onReallyHasAlpha so that it can return the most
recent result (e.g. after a scanline decode which only decoded part
of the image) or a better answer (e.g. if the whole image is known to
be opaque).
Compute fNumberPasses early, so we know which subclass to instantiate.
Make SkPngInterlaceScanlineDecoder use the base class' fCurrScanline
rather than a separate variable.
CodexTest.cpp:
Add tests for the state changes in SkCodec (need to call start before
decoding scanlines; calling getPixels means that start will need to
be called again before decoding more scanlines).
Add a test which decodes in stripes, currently only used for an
interlaced PNG.
TODO: Add tests for onReallyHasAlpha.
Review URL: https://codereview.chromium.org/1365313002
2015-09-30 15:57:13 +00:00
|
|
|
/**
|
|
|
|
* The remaining functions revolve around decoding scanlines.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Prepare for a scanline decode with the specified options.
|
|
|
|
*
|
|
|
|
* After this call, this class will be ready to decode the first scanline.
|
|
|
|
*
|
|
|
|
* This must be called in order to call getScanlines or skipScanlines.
|
|
|
|
*
|
|
|
|
* This may require rewinding the stream.
|
|
|
|
*
|
|
|
|
* Not all SkCodecs support this.
|
|
|
|
*
|
|
|
|
* @param dstInfo Info of the destination. If the dimensions do not match
|
|
|
|
* those of getInfo, this implies a scale.
|
|
|
|
* @param options Contains decoding options, including if memory is zero
|
|
|
|
* initialized.
|
|
|
|
* @param ctable A pointer to a color table. When dstInfo.colorType() is
|
|
|
|
* kIndex8, this should be non-NULL and have enough storage for 256
|
|
|
|
* colors. The color table will be populated after decoding the palette.
|
|
|
|
* @param ctableCount A pointer to the size of the color table. When
|
|
|
|
* dstInfo.colorType() is kIndex8, this should be non-NULL. It will
|
|
|
|
* be modified to the true size of the color table (<= 256) after
|
|
|
|
* decoding the palette.
|
|
|
|
* @return Enum representing success or reason for failure.
|
|
|
|
*/
|
|
|
|
Result startScanlineDecode(const SkImageInfo& dstInfo, const SkCodec::Options* options,
|
2015-10-13 19:50:14 +00:00
|
|
|
SkPMColor ctable[], int* ctableCount);
|
Merge SkCodec with SkScanlineDecoder
Benefits:
- This mimics other decoding APIs (including the ones SkCodec relies
on, e.g. a png_struct, which can be used to decode an entire image or
one line at a time).
- It allows a client to ask us to do what we can do efficiently - i.e.
start from encoded data and either decode the whole thing or scanlines.
- It removes the duplicate methods which appeared in both SkCodec and
SkScanlineDecoder (some of which, e.g. in SkJpegScanlineDecoder, just
call fCodec->sameMethod()).
- It simplifies moving more checks into the base class (e.g. the
examples in skbug.com/4284).
BUG=skia:4175
BUG=skia:4284
=====================================================================
SkScanlineDecoder.h/.cpp:
Removed.
SkCodec.h/.cpp:
Add methods, enums, and variables which were previously in
SkScanlineDecoder.
Default fCurrScanline to -1, as a sentinel that start has not been
called.
General changes:
Convert SkScanlineDecoders to SkCodecs.
General changes in SkCodec subclasses:
Merge SkScanlineDecoder implementation into SkCodec. Most (all?) owned
an SkCodec, so they now call this-> instead of fCodec->.
SkBmpCodec.h/.cpp:
Replace the unused rowOrder method with an override for
onGetScanlineOrder.
Make getDstRow const, since it is called by onGetY, which is const.
SkCodec_libpng.h/.cpp:
Make SkPngCodec an abstract class, with two subclasses which handle
scanline decoding separately (they share code for decoding the entire
image). Reimplement onReallyHasAlpha so that it can return the most
recent result (e.g. after a scanline decode which only decoded part
of the image) or a better answer (e.g. if the whole image is known to
be opaque).
Compute fNumberPasses early, so we know which subclass to instantiate.
Make SkPngInterlaceScanlineDecoder use the base class' fCurrScanline
rather than a separate variable.
CodexTest.cpp:
Add tests for the state changes in SkCodec (need to call start before
decoding scanlines; calling getPixels means that start will need to
be called again before decoding more scanlines).
Add a test which decodes in stripes, currently only used for an
interlaced PNG.
TODO: Add tests for onReallyHasAlpha.
Review URL: https://codereview.chromium.org/1365313002
2015-09-30 15:57:13 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Simplified version of startScanlineDecode() that asserts that info is NOT
|
|
|
|
* kIndex8_SkColorType and uses the default Options.
|
|
|
|
*/
|
|
|
|
Result startScanlineDecode(const SkImageInfo& dstInfo);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Write the next countLines scanlines into dst.
|
|
|
|
*
|
|
|
|
* Not valid to call before calling startScanlineDecode().
|
|
|
|
*
|
|
|
|
* @param dst Must be non-null, and large enough to hold countLines
|
|
|
|
* scanlines of size rowBytes.
|
|
|
|
* @param countLines Number of lines to write.
|
|
|
|
* @param rowBytes Number of bytes per row. Must be large enough to hold
|
|
|
|
* a scanline based on the SkImageInfo used to create this object.
|
2015-10-09 18:07:34 +00:00
|
|
|
* @return the number of lines successfully decoded. If this value is
|
|
|
|
* less than countLines, this will fill the remaining lines with a
|
|
|
|
* default value.
|
Merge SkCodec with SkScanlineDecoder
Benefits:
- This mimics other decoding APIs (including the ones SkCodec relies
on, e.g. a png_struct, which can be used to decode an entire image or
one line at a time).
- It allows a client to ask us to do what we can do efficiently - i.e.
start from encoded data and either decode the whole thing or scanlines.
- It removes the duplicate methods which appeared in both SkCodec and
SkScanlineDecoder (some of which, e.g. in SkJpegScanlineDecoder, just
call fCodec->sameMethod()).
- It simplifies moving more checks into the base class (e.g. the
examples in skbug.com/4284).
BUG=skia:4175
BUG=skia:4284
=====================================================================
SkScanlineDecoder.h/.cpp:
Removed.
SkCodec.h/.cpp:
Add methods, enums, and variables which were previously in
SkScanlineDecoder.
Default fCurrScanline to -1, as a sentinel that start has not been
called.
General changes:
Convert SkScanlineDecoders to SkCodecs.
General changes in SkCodec subclasses:
Merge SkScanlineDecoder implementation into SkCodec. Most (all?) owned
an SkCodec, so they now call this-> instead of fCodec->.
SkBmpCodec.h/.cpp:
Replace the unused rowOrder method with an override for
onGetScanlineOrder.
Make getDstRow const, since it is called by onGetY, which is const.
SkCodec_libpng.h/.cpp:
Make SkPngCodec an abstract class, with two subclasses which handle
scanline decoding separately (they share code for decoding the entire
image). Reimplement onReallyHasAlpha so that it can return the most
recent result (e.g. after a scanline decode which only decoded part
of the image) or a better answer (e.g. if the whole image is known to
be opaque).
Compute fNumberPasses early, so we know which subclass to instantiate.
Make SkPngInterlaceScanlineDecoder use the base class' fCurrScanline
rather than a separate variable.
CodexTest.cpp:
Add tests for the state changes in SkCodec (need to call start before
decoding scanlines; calling getPixels means that start will need to
be called again before decoding more scanlines).
Add a test which decodes in stripes, currently only used for an
interlaced PNG.
TODO: Add tests for onReallyHasAlpha.
Review URL: https://codereview.chromium.org/1365313002
2015-09-30 15:57:13 +00:00
|
|
|
*/
|
2015-10-09 18:07:34 +00:00
|
|
|
int getScanlines(void* dst, int countLines, size_t rowBytes);
|
Merge SkCodec with SkScanlineDecoder
Benefits:
- This mimics other decoding APIs (including the ones SkCodec relies
on, e.g. a png_struct, which can be used to decode an entire image or
one line at a time).
- It allows a client to ask us to do what we can do efficiently - i.e.
start from encoded data and either decode the whole thing or scanlines.
- It removes the duplicate methods which appeared in both SkCodec and
SkScanlineDecoder (some of which, e.g. in SkJpegScanlineDecoder, just
call fCodec->sameMethod()).
- It simplifies moving more checks into the base class (e.g. the
examples in skbug.com/4284).
BUG=skia:4175
BUG=skia:4284
=====================================================================
SkScanlineDecoder.h/.cpp:
Removed.
SkCodec.h/.cpp:
Add methods, enums, and variables which were previously in
SkScanlineDecoder.
Default fCurrScanline to -1, as a sentinel that start has not been
called.
General changes:
Convert SkScanlineDecoders to SkCodecs.
General changes in SkCodec subclasses:
Merge SkScanlineDecoder implementation into SkCodec. Most (all?) owned
an SkCodec, so they now call this-> instead of fCodec->.
SkBmpCodec.h/.cpp:
Replace the unused rowOrder method with an override for
onGetScanlineOrder.
Make getDstRow const, since it is called by onGetY, which is const.
SkCodec_libpng.h/.cpp:
Make SkPngCodec an abstract class, with two subclasses which handle
scanline decoding separately (they share code for decoding the entire
image). Reimplement onReallyHasAlpha so that it can return the most
recent result (e.g. after a scanline decode which only decoded part
of the image) or a better answer (e.g. if the whole image is known to
be opaque).
Compute fNumberPasses early, so we know which subclass to instantiate.
Make SkPngInterlaceScanlineDecoder use the base class' fCurrScanline
rather than a separate variable.
CodexTest.cpp:
Add tests for the state changes in SkCodec (need to call start before
decoding scanlines; calling getPixels means that start will need to
be called again before decoding more scanlines).
Add a test which decodes in stripes, currently only used for an
interlaced PNG.
TODO: Add tests for onReallyHasAlpha.
Review URL: https://codereview.chromium.org/1365313002
2015-09-30 15:57:13 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Skip count scanlines.
|
|
|
|
*
|
|
|
|
* Not valid to call before calling startScanlineDecode().
|
|
|
|
*
|
|
|
|
* The default version just calls onGetScanlines and discards the dst.
|
|
|
|
* NOTE: If skipped lines are the only lines with alpha, this default
|
|
|
|
* will make reallyHasAlpha return true, when it could have returned
|
|
|
|
* false.
|
2015-10-09 18:07:34 +00:00
|
|
|
*
|
|
|
|
* @return true if the scanlines were successfully skipped
|
|
|
|
* false on failure, possible reasons for failure include:
|
|
|
|
* An incomplete input image stream.
|
|
|
|
* Calling this function before calling startScanlineDecode().
|
|
|
|
* If countLines is less than zero or so large that it moves
|
|
|
|
* the current scanline past the end of the image.
|
Merge SkCodec with SkScanlineDecoder
Benefits:
- This mimics other decoding APIs (including the ones SkCodec relies
on, e.g. a png_struct, which can be used to decode an entire image or
one line at a time).
- It allows a client to ask us to do what we can do efficiently - i.e.
start from encoded data and either decode the whole thing or scanlines.
- It removes the duplicate methods which appeared in both SkCodec and
SkScanlineDecoder (some of which, e.g. in SkJpegScanlineDecoder, just
call fCodec->sameMethod()).
- It simplifies moving more checks into the base class (e.g. the
examples in skbug.com/4284).
BUG=skia:4175
BUG=skia:4284
=====================================================================
SkScanlineDecoder.h/.cpp:
Removed.
SkCodec.h/.cpp:
Add methods, enums, and variables which were previously in
SkScanlineDecoder.
Default fCurrScanline to -1, as a sentinel that start has not been
called.
General changes:
Convert SkScanlineDecoders to SkCodecs.
General changes in SkCodec subclasses:
Merge SkScanlineDecoder implementation into SkCodec. Most (all?) owned
an SkCodec, so they now call this-> instead of fCodec->.
SkBmpCodec.h/.cpp:
Replace the unused rowOrder method with an override for
onGetScanlineOrder.
Make getDstRow const, since it is called by onGetY, which is const.
SkCodec_libpng.h/.cpp:
Make SkPngCodec an abstract class, with two subclasses which handle
scanline decoding separately (they share code for decoding the entire
image). Reimplement onReallyHasAlpha so that it can return the most
recent result (e.g. after a scanline decode which only decoded part
of the image) or a better answer (e.g. if the whole image is known to
be opaque).
Compute fNumberPasses early, so we know which subclass to instantiate.
Make SkPngInterlaceScanlineDecoder use the base class' fCurrScanline
rather than a separate variable.
CodexTest.cpp:
Add tests for the state changes in SkCodec (need to call start before
decoding scanlines; calling getPixels means that start will need to
be called again before decoding more scanlines).
Add a test which decodes in stripes, currently only used for an
interlaced PNG.
TODO: Add tests for onReallyHasAlpha.
Review URL: https://codereview.chromium.org/1365313002
2015-09-30 15:57:13 +00:00
|
|
|
*/
|
2015-10-09 18:07:34 +00:00
|
|
|
bool skipScanlines(int countLines);
|
Merge SkCodec with SkScanlineDecoder
Benefits:
- This mimics other decoding APIs (including the ones SkCodec relies
on, e.g. a png_struct, which can be used to decode an entire image or
one line at a time).
- It allows a client to ask us to do what we can do efficiently - i.e.
start from encoded data and either decode the whole thing or scanlines.
- It removes the duplicate methods which appeared in both SkCodec and
SkScanlineDecoder (some of which, e.g. in SkJpegScanlineDecoder, just
call fCodec->sameMethod()).
- It simplifies moving more checks into the base class (e.g. the
examples in skbug.com/4284).
BUG=skia:4175
BUG=skia:4284
=====================================================================
SkScanlineDecoder.h/.cpp:
Removed.
SkCodec.h/.cpp:
Add methods, enums, and variables which were previously in
SkScanlineDecoder.
Default fCurrScanline to -1, as a sentinel that start has not been
called.
General changes:
Convert SkScanlineDecoders to SkCodecs.
General changes in SkCodec subclasses:
Merge SkScanlineDecoder implementation into SkCodec. Most (all?) owned
an SkCodec, so they now call this-> instead of fCodec->.
SkBmpCodec.h/.cpp:
Replace the unused rowOrder method with an override for
onGetScanlineOrder.
Make getDstRow const, since it is called by onGetY, which is const.
SkCodec_libpng.h/.cpp:
Make SkPngCodec an abstract class, with two subclasses which handle
scanline decoding separately (they share code for decoding the entire
image). Reimplement onReallyHasAlpha so that it can return the most
recent result (e.g. after a scanline decode which only decoded part
of the image) or a better answer (e.g. if the whole image is known to
be opaque).
Compute fNumberPasses early, so we know which subclass to instantiate.
Make SkPngInterlaceScanlineDecoder use the base class' fCurrScanline
rather than a separate variable.
CodexTest.cpp:
Add tests for the state changes in SkCodec (need to call start before
decoding scanlines; calling getPixels means that start will need to
be called again before decoding more scanlines).
Add a test which decodes in stripes, currently only used for an
interlaced PNG.
TODO: Add tests for onReallyHasAlpha.
Review URL: https://codereview.chromium.org/1365313002
2015-09-30 15:57:13 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The order in which rows are output from the scanline decoder is not the
|
|
|
|
* same for all variations of all image types. This explains the possible
|
|
|
|
* output row orderings.
|
|
|
|
*/
|
|
|
|
enum SkScanlineOrder {
|
|
|
|
/*
|
|
|
|
* By far the most common, this indicates that the image can be decoded
|
|
|
|
* reliably using the scanline decoder, and that rows will be output in
|
|
|
|
* the logical order.
|
|
|
|
*/
|
|
|
|
kTopDown_SkScanlineOrder,
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This indicates that the scanline decoder reliably outputs rows, but
|
|
|
|
* they will be returned in reverse order. If the scanline format is
|
|
|
|
* kBottomUp, the nextScanline() API can be used to determine the actual
|
|
|
|
* y-coordinate of the next output row, but the client is not forced
|
|
|
|
* to take advantage of this, given that it's not too tough to keep
|
|
|
|
* track independently.
|
|
|
|
*
|
|
|
|
* For full image decodes, it is safe to get all of the scanlines at
|
|
|
|
* once, since the decoder will handle inverting the rows as it
|
|
|
|
* decodes.
|
|
|
|
*
|
|
|
|
* For subset decodes and sampling, it is simplest to get and skip
|
|
|
|
* scanlines one at a time, using the nextScanline() API. It is
|
|
|
|
* possible to ask for larger chunks at a time, but this should be used
|
|
|
|
* with caution. As with full image decodes, the decoder will handle
|
|
|
|
* inverting the requested rows, but rows will still be delivered
|
|
|
|
* starting from the bottom of the image.
|
|
|
|
*
|
|
|
|
* Upside down bmps are an example.
|
|
|
|
*/
|
|
|
|
kBottomUp_SkScanlineOrder,
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This indicates that the scanline decoder reliably outputs rows, but
|
|
|
|
* they will not be in logical order. If the scanline format is
|
|
|
|
* kOutOfOrder, the nextScanline() API should be used to determine the
|
|
|
|
* actual y-coordinate of the next output row.
|
|
|
|
*
|
|
|
|
* For this scanline ordering, it is advisable to get and skip
|
|
|
|
* scanlines one at a time.
|
|
|
|
*
|
|
|
|
* Interlaced gifs are an example.
|
|
|
|
*/
|
|
|
|
kOutOfOrder_SkScanlineOrder,
|
Revert of Make SkPngCodec decode progressively. (patchset #26 id:520001 of https://codereview.chromium.org/1997703003/ )
Reason for revert:
Still causing problems in Google3, e.g.
https://test.corp.google.com/ui#cl=124138817&flags=CAMQBQ==&id=OCL:124138817:BASE:124139560:1465227435491:219ffbdb&t=//third_party/skia/HEAD:dm
Original issue's description:
> Make SkPngCodec decode progressively.
>
> This is a step towards using SkCodec in Chromium, where progressive
> decoding is necessary.
>
> Switch from using png_read_row (which expects all the data to be
> available) to png_process_data, which uses callbacks when rows are
> available.
>
> Create a new API for SkCodec, which supports progressive decoding and
> scanline decoding. Future changes will switch the other clients off of
> startScanlineDecode and get/skip-Scanlines to the new API.
>
> Remove SkCodec::kNone_ScanlineOrder, which was only used for interlaced
> PNG images. In the new API, interlaced PNG fits kTopDown. Also remove
> updateCurrScanline(), which was only used by the old implementation for
> interlaced PNG.
>
> DMSrcSink:
> - In CodecSrc::kScanline_Mode, use the new method for scanline decoding
> for the supported formats (just PNG and PNG-in-ICO for now).
>
> fuzz.cpp:
> - Remove reference to kNone_ScanlineOrder
>
> SkCodec:
> - Add new APIs:
> - startIncrementalDecode
> - incrementalDecode
> - Remove kNone_SkScanlineOrder and updateCurrScanline()
>
> SkPngCodec:
> - Implement new APIs
> - Switch from sk_read_fn/png_read_row etc to png_process_data
> - Expand AutoCleanPng's role to decode the header and create the
> SkPngCodec
> - Make the interlaced PNG decoder report how many lines were
> initialized during an incomplete decode
> - Make initializeSwizzler return a bool instead of an SkCodec::Result
> (It only returned kSuccess or kInvalidInput anyway)
>
> SkIcoCodec:
> - Implement the new APIs; supported for PNG in ICO
>
> SkSampledCodec:
> - Call the new method for decoding scanlines, and fall back to the old
> method if the new version is unimplemented
> - Remove references to kNone_SkScanlineOrder
>
> tests/CodecPartial:
> - Add a test which decodes part of an image, then finishes the decode,
> and compares it to the straightforward method
>
> tests/CodecTest:
> - Add a test which decodes all scanlines using the new method
> - Repurpose the Codec_stripes test to decode using the new method in
> sections rather than all at once
> - In the method check(), add a parameter for whether the image supports
> the new method of scanline decoding, and be explicit about whether an
> image supports incomplete
> - Test incomplete PNG decodes. We should have been doing it anyway for
> non-interlaced (except for an image that is too small - one row), but
> the new method supports interlaced incomplete as well
> - Make test_invalid_parameters test the new method
> - Add a test to ensure that it's safe to fall back to scanline decoding without
> rewinding
>
> BUG=skia:4211
>
> The new version was generally faster than the old version (but not significantly so).
>
> Some raw performance differences can be found at https://docs.google.com/a/google.com/spreadsheets/d/1Gis3aRCEa72qBNDRMgGDg3jD-pMgO-FXldlNF9ejo4o/
>
> Design doc can be found at https://docs.google.com/a/google.com/document/d/11Mn8-ePDKwVEMCjs3nWwSjxcSpJ_Cu8DF57KNtUmgLM/
>
> GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1997703003
>
> Committed: https://skia.googlesource.com/skia/+/a4b09a117d4d1ba5dda372e6a2323e653766539e
>
> Committed: https://skia.googlesource.com/skia/+/30e78c9737ff4861dc4e3fa1e4cd010680ed6965
>
> Committed: https://skia.googlesource.com/skia/+/6fb2391b2cc83ee2160b4e994faa8128975acc1f
TBR=reed@google.com,msarett@google.com,scroggo@chromium.org
# Not skipping CQ checks because original CL landed more than 1 days ago.
BUG=skia:4211
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2044573002
Review-Url: https://codereview.chromium.org/2044573002
2016-06-06 18:26:17 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Indicates that the entire image must be decoded in order to output
|
|
|
|
* any amount of scanlines. In this case, it is a REALLY BAD IDEA to
|
|
|
|
* request scanlines 1-by-1 or in small chunks. The client should
|
|
|
|
* determine which scanlines are needed and ask for all of them in
|
|
|
|
* a single call to getScanlines().
|
|
|
|
*
|
|
|
|
* Interlaced pngs are an example.
|
|
|
|
*/
|
|
|
|
kNone_SkScanlineOrder,
|
Merge SkCodec with SkScanlineDecoder
Benefits:
- This mimics other decoding APIs (including the ones SkCodec relies
on, e.g. a png_struct, which can be used to decode an entire image or
one line at a time).
- It allows a client to ask us to do what we can do efficiently - i.e.
start from encoded data and either decode the whole thing or scanlines.
- It removes the duplicate methods which appeared in both SkCodec and
SkScanlineDecoder (some of which, e.g. in SkJpegScanlineDecoder, just
call fCodec->sameMethod()).
- It simplifies moving more checks into the base class (e.g. the
examples in skbug.com/4284).
BUG=skia:4175
BUG=skia:4284
=====================================================================
SkScanlineDecoder.h/.cpp:
Removed.
SkCodec.h/.cpp:
Add methods, enums, and variables which were previously in
SkScanlineDecoder.
Default fCurrScanline to -1, as a sentinel that start has not been
called.
General changes:
Convert SkScanlineDecoders to SkCodecs.
General changes in SkCodec subclasses:
Merge SkScanlineDecoder implementation into SkCodec. Most (all?) owned
an SkCodec, so they now call this-> instead of fCodec->.
SkBmpCodec.h/.cpp:
Replace the unused rowOrder method with an override for
onGetScanlineOrder.
Make getDstRow const, since it is called by onGetY, which is const.
SkCodec_libpng.h/.cpp:
Make SkPngCodec an abstract class, with two subclasses which handle
scanline decoding separately (they share code for decoding the entire
image). Reimplement onReallyHasAlpha so that it can return the most
recent result (e.g. after a scanline decode which only decoded part
of the image) or a better answer (e.g. if the whole image is known to
be opaque).
Compute fNumberPasses early, so we know which subclass to instantiate.
Make SkPngInterlaceScanlineDecoder use the base class' fCurrScanline
rather than a separate variable.
CodexTest.cpp:
Add tests for the state changes in SkCodec (need to call start before
decoding scanlines; calling getPixels means that start will need to
be called again before decoding more scanlines).
Add a test which decodes in stripes, currently only used for an
interlaced PNG.
TODO: Add tests for onReallyHasAlpha.
Review URL: https://codereview.chromium.org/1365313002
2015-09-30 15:57:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* An enum representing the order in which scanlines will be returned by
|
|
|
|
* the scanline decoder.
|
2015-12-04 16:00:50 +00:00
|
|
|
*
|
|
|
|
* This is undefined before startScanlineDecode() is called.
|
Merge SkCodec with SkScanlineDecoder
Benefits:
- This mimics other decoding APIs (including the ones SkCodec relies
on, e.g. a png_struct, which can be used to decode an entire image or
one line at a time).
- It allows a client to ask us to do what we can do efficiently - i.e.
start from encoded data and either decode the whole thing or scanlines.
- It removes the duplicate methods which appeared in both SkCodec and
SkScanlineDecoder (some of which, e.g. in SkJpegScanlineDecoder, just
call fCodec->sameMethod()).
- It simplifies moving more checks into the base class (e.g. the
examples in skbug.com/4284).
BUG=skia:4175
BUG=skia:4284
=====================================================================
SkScanlineDecoder.h/.cpp:
Removed.
SkCodec.h/.cpp:
Add methods, enums, and variables which were previously in
SkScanlineDecoder.
Default fCurrScanline to -1, as a sentinel that start has not been
called.
General changes:
Convert SkScanlineDecoders to SkCodecs.
General changes in SkCodec subclasses:
Merge SkScanlineDecoder implementation into SkCodec. Most (all?) owned
an SkCodec, so they now call this-> instead of fCodec->.
SkBmpCodec.h/.cpp:
Replace the unused rowOrder method with an override for
onGetScanlineOrder.
Make getDstRow const, since it is called by onGetY, which is const.
SkCodec_libpng.h/.cpp:
Make SkPngCodec an abstract class, with two subclasses which handle
scanline decoding separately (they share code for decoding the entire
image). Reimplement onReallyHasAlpha so that it can return the most
recent result (e.g. after a scanline decode which only decoded part
of the image) or a better answer (e.g. if the whole image is known to
be opaque).
Compute fNumberPasses early, so we know which subclass to instantiate.
Make SkPngInterlaceScanlineDecoder use the base class' fCurrScanline
rather than a separate variable.
CodexTest.cpp:
Add tests for the state changes in SkCodec (need to call start before
decoding scanlines; calling getPixels means that start will need to
be called again before decoding more scanlines).
Add a test which decodes in stripes, currently only used for an
interlaced PNG.
TODO: Add tests for onReallyHasAlpha.
Review URL: https://codereview.chromium.org/1365313002
2015-09-30 15:57:13 +00:00
|
|
|
*/
|
|
|
|
SkScanlineOrder getScanlineOrder() const { return this->onGetScanlineOrder(); }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the y-coordinate of the next row to be returned by the scanline
|
2015-10-09 18:07:34 +00:00
|
|
|
* decoder.
|
|
|
|
*
|
|
|
|
* This will equal fCurrScanline, except in the case of strangely
|
|
|
|
* encoded image types (bottom-up bmps, interlaced gifs).
|
Merge SkCodec with SkScanlineDecoder
Benefits:
- This mimics other decoding APIs (including the ones SkCodec relies
on, e.g. a png_struct, which can be used to decode an entire image or
one line at a time).
- It allows a client to ask us to do what we can do efficiently - i.e.
start from encoded data and either decode the whole thing or scanlines.
- It removes the duplicate methods which appeared in both SkCodec and
SkScanlineDecoder (some of which, e.g. in SkJpegScanlineDecoder, just
call fCodec->sameMethod()).
- It simplifies moving more checks into the base class (e.g. the
examples in skbug.com/4284).
BUG=skia:4175
BUG=skia:4284
=====================================================================
SkScanlineDecoder.h/.cpp:
Removed.
SkCodec.h/.cpp:
Add methods, enums, and variables which were previously in
SkScanlineDecoder.
Default fCurrScanline to -1, as a sentinel that start has not been
called.
General changes:
Convert SkScanlineDecoders to SkCodecs.
General changes in SkCodec subclasses:
Merge SkScanlineDecoder implementation into SkCodec. Most (all?) owned
an SkCodec, so they now call this-> instead of fCodec->.
SkBmpCodec.h/.cpp:
Replace the unused rowOrder method with an override for
onGetScanlineOrder.
Make getDstRow const, since it is called by onGetY, which is const.
SkCodec_libpng.h/.cpp:
Make SkPngCodec an abstract class, with two subclasses which handle
scanline decoding separately (they share code for decoding the entire
image). Reimplement onReallyHasAlpha so that it can return the most
recent result (e.g. after a scanline decode which only decoded part
of the image) or a better answer (e.g. if the whole image is known to
be opaque).
Compute fNumberPasses early, so we know which subclass to instantiate.
Make SkPngInterlaceScanlineDecoder use the base class' fCurrScanline
rather than a separate variable.
CodexTest.cpp:
Add tests for the state changes in SkCodec (need to call start before
decoding scanlines; calling getPixels means that start will need to
be called again before decoding more scanlines).
Add a test which decodes in stripes, currently only used for an
interlaced PNG.
TODO: Add tests for onReallyHasAlpha.
Review URL: https://codereview.chromium.org/1365313002
2015-09-30 15:57:13 +00:00
|
|
|
*
|
|
|
|
* Results are undefined when not in scanline decoding mode.
|
|
|
|
*/
|
2015-10-09 18:07:34 +00:00
|
|
|
int nextScanline() const { return this->outputScanline(fCurrScanline); }
|
|
|
|
|
|
|
|
/**
|
2015-12-03 20:23:43 +00:00
|
|
|
* Returns the output y-coordinate of the row that corresponds to an input
|
|
|
|
* y-coordinate. The input y-coordinate represents where the scanline
|
|
|
|
* is located in the encoded data.
|
2015-10-09 18:07:34 +00:00
|
|
|
*
|
|
|
|
* This will equal inputScanline, except in the case of strangely
|
|
|
|
* encoded image types (bottom-up bmps, interlaced gifs).
|
|
|
|
*/
|
|
|
|
int outputScanline(int inputScanline) const;
|
Merge SkCodec with SkScanlineDecoder
Benefits:
- This mimics other decoding APIs (including the ones SkCodec relies
on, e.g. a png_struct, which can be used to decode an entire image or
one line at a time).
- It allows a client to ask us to do what we can do efficiently - i.e.
start from encoded data and either decode the whole thing or scanlines.
- It removes the duplicate methods which appeared in both SkCodec and
SkScanlineDecoder (some of which, e.g. in SkJpegScanlineDecoder, just
call fCodec->sameMethod()).
- It simplifies moving more checks into the base class (e.g. the
examples in skbug.com/4284).
BUG=skia:4175
BUG=skia:4284
=====================================================================
SkScanlineDecoder.h/.cpp:
Removed.
SkCodec.h/.cpp:
Add methods, enums, and variables which were previously in
SkScanlineDecoder.
Default fCurrScanline to -1, as a sentinel that start has not been
called.
General changes:
Convert SkScanlineDecoders to SkCodecs.
General changes in SkCodec subclasses:
Merge SkScanlineDecoder implementation into SkCodec. Most (all?) owned
an SkCodec, so they now call this-> instead of fCodec->.
SkBmpCodec.h/.cpp:
Replace the unused rowOrder method with an override for
onGetScanlineOrder.
Make getDstRow const, since it is called by onGetY, which is const.
SkCodec_libpng.h/.cpp:
Make SkPngCodec an abstract class, with two subclasses which handle
scanline decoding separately (they share code for decoding the entire
image). Reimplement onReallyHasAlpha so that it can return the most
recent result (e.g. after a scanline decode which only decoded part
of the image) or a better answer (e.g. if the whole image is known to
be opaque).
Compute fNumberPasses early, so we know which subclass to instantiate.
Make SkPngInterlaceScanlineDecoder use the base class' fCurrScanline
rather than a separate variable.
CodexTest.cpp:
Add tests for the state changes in SkCodec (need to call start before
decoding scanlines; calling getPixels means that start will need to
be called again before decoding more scanlines).
Add a test which decodes in stripes, currently only used for an
interlaced PNG.
TODO: Add tests for onReallyHasAlpha.
Review URL: https://codereview.chromium.org/1365313002
2015-09-30 15:57:13 +00:00
|
|
|
|
2015-03-03 16:59:20 +00:00
|
|
|
protected:
|
2016-03-04 21:27:35 +00:00
|
|
|
/**
|
|
|
|
* Takes ownership of SkStream*
|
|
|
|
*/
|
2016-04-20 18:53:35 +00:00
|
|
|
SkCodec(int width,
|
|
|
|
int height,
|
|
|
|
const SkEncodedInfo&,
|
2016-03-21 15:04:40 +00:00
|
|
|
SkStream*,
|
|
|
|
sk_sp<SkColorSpace> = nullptr,
|
|
|
|
Origin = kTopLeft_Origin);
|
2015-03-03 16:59:20 +00:00
|
|
|
|
2016-01-22 22:46:42 +00:00
|
|
|
virtual SkISize onGetScaledDimensions(float /*desiredScale*/) const {
|
2015-03-03 16:59:20 +00:00
|
|
|
// By default, scaling is not supported.
|
2015-03-26 13:29:03 +00:00
|
|
|
return this->getInfo().dimensions();
|
2015-03-03 16:59:20 +00:00
|
|
|
}
|
|
|
|
|
2015-10-02 20:14:46 +00:00
|
|
|
// FIXME: What to do about subsets??
|
|
|
|
/**
|
|
|
|
* Subclasses should override if they support dimensions other than the
|
|
|
|
* srcInfo's.
|
|
|
|
*/
|
|
|
|
virtual bool onDimensionsSupported(const SkISize&) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-03-20 18:55:55 +00:00
|
|
|
virtual SkEncodedFormat onGetEncodedFormat() const = 0;
|
|
|
|
|
2015-10-09 18:07:34 +00:00
|
|
|
/**
|
|
|
|
* @param rowsDecoded When the encoded image stream is incomplete, this function
|
|
|
|
* will return kIncompleteInput and rowsDecoded will be set to
|
|
|
|
* the number of scanlines that were successfully decoded.
|
|
|
|
* This will allow getPixels() to fill the uninitialized memory.
|
|
|
|
*/
|
SkCodec no longer inherits from SkImageGenerator.
SkImageGenerator makes some assumptions that are not necessarily valid
for SkCodec. For example, SkCodec does not assume that it can always be
rewound.
We also have an ongoing question of what an SkCodec should report as
its default settings (i.e. the return from getInfo). It makes sense for
an SkCodec to report that its pixels are unpremultiplied, if that is
the case for the underlying data, but if a client of SkImageGenerator
uses the default settings (as many do), they will receive
unpremultiplied pixels which cannot (currently) be drawn with Skia. We
may ultimately decide to revisit SkCodec reporting an SkImageInfo, but
I have left it unchanged for now.
Import features of SkImageGenerator used by SkCodec into SkCodec.
I have left SkImageGenerator unchanged for now, but it no longer needs
Result or Options. This will require changes to Chromium.
Manually handle the lifetime of fScanlineDecoder, so SkScanlineDecoder.h
can include SkCodec.h (where Result is), and SkCodec.h does not need
to include it (to delete fScanlineDecoder).
In many places, make the following simple changes:
- Now include SkScanlineDecoder.h, which is no longer included by
SkCodec.h
- Use the enums in SkCodec, rather than SkImageGenerator
- Stop including SkImageGenerator.h where no longer needed
Review URL: https://codereview.chromium.org/1220733013
2015-07-09 15:16:03 +00:00
|
|
|
virtual Result onGetPixels(const SkImageInfo& info,
|
|
|
|
void* pixels, size_t rowBytes, const Options&,
|
2015-10-09 18:07:34 +00:00
|
|
|
SkPMColor ctable[], int* ctableCount,
|
|
|
|
int* rowsDecoded) = 0;
|
SkCodec no longer inherits from SkImageGenerator.
SkImageGenerator makes some assumptions that are not necessarily valid
for SkCodec. For example, SkCodec does not assume that it can always be
rewound.
We also have an ongoing question of what an SkCodec should report as
its default settings (i.e. the return from getInfo). It makes sense for
an SkCodec to report that its pixels are unpremultiplied, if that is
the case for the underlying data, but if a client of SkImageGenerator
uses the default settings (as many do), they will receive
unpremultiplied pixels which cannot (currently) be drawn with Skia. We
may ultimately decide to revisit SkCodec reporting an SkImageInfo, but
I have left it unchanged for now.
Import features of SkImageGenerator used by SkCodec into SkCodec.
I have left SkImageGenerator unchanged for now, but it no longer needs
Result or Options. This will require changes to Chromium.
Manually handle the lifetime of fScanlineDecoder, so SkScanlineDecoder.h
can include SkCodec.h (where Result is), and SkCodec.h does not need
to include it (to delete fScanlineDecoder).
In many places, make the following simple changes:
- Now include SkScanlineDecoder.h, which is no longer included by
SkCodec.h
- Use the enums in SkCodec, rather than SkImageGenerator
- Stop including SkImageGenerator.h where no longer needed
Review URL: https://codereview.chromium.org/1220733013
2015-07-09 15:16:03 +00:00
|
|
|
|
2016-03-10 13:44:43 +00:00
|
|
|
virtual bool onQueryYUV8(SkYUVSizeInfo*, SkYUVColorSpace*) const {
|
2016-01-22 22:46:42 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-03-10 13:44:43 +00:00
|
|
|
virtual Result onGetYUV8Planes(const SkYUVSizeInfo&, void*[3] /*planes*/) {
|
2016-01-22 22:46:42 +00:00
|
|
|
return kUnimplemented;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool onGetValidSubset(SkIRect* /*desiredSubset*/) const {
|
2015-07-22 14:16:20 +00:00
|
|
|
// By default, subsets are not supported.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-03-03 16:59:20 +00:00
|
|
|
/**
|
|
|
|
* If the stream was previously read, attempt to rewind.
|
2015-08-12 14:24:13 +00:00
|
|
|
*
|
|
|
|
* If the stream needed to be rewound, call onRewind.
|
|
|
|
* @returns true if the codec is at the right position and can be used.
|
|
|
|
* false if there was a failure to rewind.
|
2015-03-27 19:16:53 +00:00
|
|
|
*
|
2015-09-30 16:15:14 +00:00
|
|
|
* This is called by getPixels() and start(). Subclasses may call if they
|
|
|
|
* need to rewind at another time.
|
2015-03-03 16:59:20 +00:00
|
|
|
*/
|
2015-08-12 14:24:13 +00:00
|
|
|
bool SK_WARN_UNUSED_RESULT rewindIfNeeded();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called by rewindIfNeeded, if the stream needed to be rewound.
|
|
|
|
*
|
|
|
|
* Subclasses should do any set up needed after a rewind.
|
|
|
|
*/
|
|
|
|
virtual bool onRewind() {
|
|
|
|
return true;
|
|
|
|
}
|
2015-03-03 16:59:20 +00:00
|
|
|
|
2015-10-09 18:07:34 +00:00
|
|
|
/**
|
|
|
|
* On an incomplete input, getPixels() and getScanlines() will fill any uninitialized
|
|
|
|
* scanlines. This allows the subclass to indicate what value to fill with.
|
|
|
|
*
|
|
|
|
* @param colorType Destination color type.
|
|
|
|
* @return The value with which to fill uninitialized pixels.
|
|
|
|
*
|
|
|
|
* Note that we can interpret the return value as an SkPMColor, a 16-bit 565 color,
|
|
|
|
* an 8-bit gray color, or an 8-bit index into a color table, depending on the color
|
|
|
|
* type.
|
|
|
|
*/
|
2016-02-03 17:42:42 +00:00
|
|
|
uint32_t getFillValue(SkColorType colorType) const {
|
|
|
|
return this->onGetFillValue(colorType);
|
2015-10-09 18:07:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Some subclasses will override this function, but this is a useful default for the color
|
|
|
|
* types that we support. Note that for color types that do not use the full 32-bits,
|
|
|
|
* we will simply take the low bits of the fill value.
|
|
|
|
*
|
2016-02-03 17:42:42 +00:00
|
|
|
* kN32_SkColorType: Transparent or Black, depending on the src alpha type
|
2015-10-09 18:07:34 +00:00
|
|
|
* kRGB_565_SkColorType: Black
|
|
|
|
* kGray_8_SkColorType: Black
|
|
|
|
* kIndex_8_SkColorType: First color in color table
|
|
|
|
*/
|
2016-02-03 17:42:42 +00:00
|
|
|
virtual uint32_t onGetFillValue(SkColorType /*colorType*/) const {
|
|
|
|
return kOpaque_SkAlphaType == fSrcInfo.alphaType() ? SK_ColorBLACK : SK_ColorTRANSPARENT;
|
2015-10-09 18:07:34 +00:00
|
|
|
}
|
|
|
|
|
2015-07-01 13:50:35 +00:00
|
|
|
/**
|
2015-03-16 18:55:18 +00:00
|
|
|
* Get method for the input stream
|
|
|
|
*/
|
|
|
|
SkStream* stream() {
|
|
|
|
return fStream.get();
|
|
|
|
}
|
|
|
|
|
Merge SkCodec with SkScanlineDecoder
Benefits:
- This mimics other decoding APIs (including the ones SkCodec relies
on, e.g. a png_struct, which can be used to decode an entire image or
one line at a time).
- It allows a client to ask us to do what we can do efficiently - i.e.
start from encoded data and either decode the whole thing or scanlines.
- It removes the duplicate methods which appeared in both SkCodec and
SkScanlineDecoder (some of which, e.g. in SkJpegScanlineDecoder, just
call fCodec->sameMethod()).
- It simplifies moving more checks into the base class (e.g. the
examples in skbug.com/4284).
BUG=skia:4175
BUG=skia:4284
=====================================================================
SkScanlineDecoder.h/.cpp:
Removed.
SkCodec.h/.cpp:
Add methods, enums, and variables which were previously in
SkScanlineDecoder.
Default fCurrScanline to -1, as a sentinel that start has not been
called.
General changes:
Convert SkScanlineDecoders to SkCodecs.
General changes in SkCodec subclasses:
Merge SkScanlineDecoder implementation into SkCodec. Most (all?) owned
an SkCodec, so they now call this-> instead of fCodec->.
SkBmpCodec.h/.cpp:
Replace the unused rowOrder method with an override for
onGetScanlineOrder.
Make getDstRow const, since it is called by onGetY, which is const.
SkCodec_libpng.h/.cpp:
Make SkPngCodec an abstract class, with two subclasses which handle
scanline decoding separately (they share code for decoding the entire
image). Reimplement onReallyHasAlpha so that it can return the most
recent result (e.g. after a scanline decode which only decoded part
of the image) or a better answer (e.g. if the whole image is known to
be opaque).
Compute fNumberPasses early, so we know which subclass to instantiate.
Make SkPngInterlaceScanlineDecoder use the base class' fCurrScanline
rather than a separate variable.
CodexTest.cpp:
Add tests for the state changes in SkCodec (need to call start before
decoding scanlines; calling getPixels means that start will need to
be called again before decoding more scanlines).
Add a test which decodes in stripes, currently only used for an
interlaced PNG.
TODO: Add tests for onReallyHasAlpha.
Review URL: https://codereview.chromium.org/1365313002
2015-09-30 15:57:13 +00:00
|
|
|
/**
|
|
|
|
* The remaining functions revolve around decoding scanlines.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Most images types will be kTopDown and will not need to override this function.
|
|
|
|
*/
|
|
|
|
virtual SkScanlineOrder onGetScanlineOrder() const { return kTopDown_SkScanlineOrder; }
|
|
|
|
|
Revert of Make SkPngCodec decode progressively. (patchset #26 id:520001 of https://codereview.chromium.org/1997703003/ )
Reason for revert:
Still causing problems in Google3, e.g.
https://test.corp.google.com/ui#cl=124138817&flags=CAMQBQ==&id=OCL:124138817:BASE:124139560:1465227435491:219ffbdb&t=//third_party/skia/HEAD:dm
Original issue's description:
> Make SkPngCodec decode progressively.
>
> This is a step towards using SkCodec in Chromium, where progressive
> decoding is necessary.
>
> Switch from using png_read_row (which expects all the data to be
> available) to png_process_data, which uses callbacks when rows are
> available.
>
> Create a new API for SkCodec, which supports progressive decoding and
> scanline decoding. Future changes will switch the other clients off of
> startScanlineDecode and get/skip-Scanlines to the new API.
>
> Remove SkCodec::kNone_ScanlineOrder, which was only used for interlaced
> PNG images. In the new API, interlaced PNG fits kTopDown. Also remove
> updateCurrScanline(), which was only used by the old implementation for
> interlaced PNG.
>
> DMSrcSink:
> - In CodecSrc::kScanline_Mode, use the new method for scanline decoding
> for the supported formats (just PNG and PNG-in-ICO for now).
>
> fuzz.cpp:
> - Remove reference to kNone_ScanlineOrder
>
> SkCodec:
> - Add new APIs:
> - startIncrementalDecode
> - incrementalDecode
> - Remove kNone_SkScanlineOrder and updateCurrScanline()
>
> SkPngCodec:
> - Implement new APIs
> - Switch from sk_read_fn/png_read_row etc to png_process_data
> - Expand AutoCleanPng's role to decode the header and create the
> SkPngCodec
> - Make the interlaced PNG decoder report how many lines were
> initialized during an incomplete decode
> - Make initializeSwizzler return a bool instead of an SkCodec::Result
> (It only returned kSuccess or kInvalidInput anyway)
>
> SkIcoCodec:
> - Implement the new APIs; supported for PNG in ICO
>
> SkSampledCodec:
> - Call the new method for decoding scanlines, and fall back to the old
> method if the new version is unimplemented
> - Remove references to kNone_SkScanlineOrder
>
> tests/CodecPartial:
> - Add a test which decodes part of an image, then finishes the decode,
> and compares it to the straightforward method
>
> tests/CodecTest:
> - Add a test which decodes all scanlines using the new method
> - Repurpose the Codec_stripes test to decode using the new method in
> sections rather than all at once
> - In the method check(), add a parameter for whether the image supports
> the new method of scanline decoding, and be explicit about whether an
> image supports incomplete
> - Test incomplete PNG decodes. We should have been doing it anyway for
> non-interlaced (except for an image that is too small - one row), but
> the new method supports interlaced incomplete as well
> - Make test_invalid_parameters test the new method
> - Add a test to ensure that it's safe to fall back to scanline decoding without
> rewinding
>
> BUG=skia:4211
>
> The new version was generally faster than the old version (but not significantly so).
>
> Some raw performance differences can be found at https://docs.google.com/a/google.com/spreadsheets/d/1Gis3aRCEa72qBNDRMgGDg3jD-pMgO-FXldlNF9ejo4o/
>
> Design doc can be found at https://docs.google.com/a/google.com/document/d/11Mn8-ePDKwVEMCjs3nWwSjxcSpJ_Cu8DF57KNtUmgLM/
>
> GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1997703003
>
> Committed: https://skia.googlesource.com/skia/+/a4b09a117d4d1ba5dda372e6a2323e653766539e
>
> Committed: https://skia.googlesource.com/skia/+/30e78c9737ff4861dc4e3fa1e4cd010680ed6965
>
> Committed: https://skia.googlesource.com/skia/+/6fb2391b2cc83ee2160b4e994faa8128975acc1f
TBR=reed@google.com,msarett@google.com,scroggo@chromium.org
# Not skipping CQ checks because original CL landed more than 1 days ago.
BUG=skia:4211
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2044573002
Review-Url: https://codereview.chromium.org/2044573002
2016-06-06 18:26:17 +00:00
|
|
|
/**
|
|
|
|
* Update the current scanline. Used by interlaced png.
|
|
|
|
*/
|
|
|
|
void updateCurrScanline(int newY) { fCurrScanline = newY; }
|
|
|
|
|
Merge SkCodec with SkScanlineDecoder
Benefits:
- This mimics other decoding APIs (including the ones SkCodec relies
on, e.g. a png_struct, which can be used to decode an entire image or
one line at a time).
- It allows a client to ask us to do what we can do efficiently - i.e.
start from encoded data and either decode the whole thing or scanlines.
- It removes the duplicate methods which appeared in both SkCodec and
SkScanlineDecoder (some of which, e.g. in SkJpegScanlineDecoder, just
call fCodec->sameMethod()).
- It simplifies moving more checks into the base class (e.g. the
examples in skbug.com/4284).
BUG=skia:4175
BUG=skia:4284
=====================================================================
SkScanlineDecoder.h/.cpp:
Removed.
SkCodec.h/.cpp:
Add methods, enums, and variables which were previously in
SkScanlineDecoder.
Default fCurrScanline to -1, as a sentinel that start has not been
called.
General changes:
Convert SkScanlineDecoders to SkCodecs.
General changes in SkCodec subclasses:
Merge SkScanlineDecoder implementation into SkCodec. Most (all?) owned
an SkCodec, so they now call this-> instead of fCodec->.
SkBmpCodec.h/.cpp:
Replace the unused rowOrder method with an override for
onGetScanlineOrder.
Make getDstRow const, since it is called by onGetY, which is const.
SkCodec_libpng.h/.cpp:
Make SkPngCodec an abstract class, with two subclasses which handle
scanline decoding separately (they share code for decoding the entire
image). Reimplement onReallyHasAlpha so that it can return the most
recent result (e.g. after a scanline decode which only decoded part
of the image) or a better answer (e.g. if the whole image is known to
be opaque).
Compute fNumberPasses early, so we know which subclass to instantiate.
Make SkPngInterlaceScanlineDecoder use the base class' fCurrScanline
rather than a separate variable.
CodexTest.cpp:
Add tests for the state changes in SkCodec (need to call start before
decoding scanlines; calling getPixels means that start will need to
be called again before decoding more scanlines).
Add a test which decodes in stripes, currently only used for an
interlaced PNG.
TODO: Add tests for onReallyHasAlpha.
Review URL: https://codereview.chromium.org/1365313002
2015-09-30 15:57:13 +00:00
|
|
|
const SkImageInfo& dstInfo() const { return fDstInfo; }
|
|
|
|
|
|
|
|
const SkCodec::Options& options() const { return fOptions; }
|
|
|
|
|
2015-12-03 20:23:43 +00:00
|
|
|
/**
|
|
|
|
* Returns the number of scanlines that have been decoded so far.
|
|
|
|
* This is unaffected by the SkScanlineOrder.
|
|
|
|
*
|
|
|
|
* Returns -1 if we have not started a scanline decode.
|
|
|
|
*/
|
|
|
|
int currScanline() const { return fCurrScanline; }
|
|
|
|
|
2015-10-09 18:07:34 +00:00
|
|
|
virtual int onOutputScanline(int inputScanline) const;
|
|
|
|
|
2016-06-01 21:47:18 +00:00
|
|
|
/**
|
|
|
|
* Used for testing with qcms.
|
|
|
|
* FIXME: Remove this when we are done comparing with qcms.
|
|
|
|
*/
|
|
|
|
virtual sk_sp<SkData> getICCData() const { return nullptr; }
|
2015-03-03 16:59:20 +00:00
|
|
|
private:
|
2016-04-20 18:53:35 +00:00
|
|
|
const SkEncodedInfo fEncodedInfo;
|
2016-03-04 21:27:35 +00:00
|
|
|
const SkImageInfo fSrcInfo;
|
|
|
|
SkAutoTDelete<SkStream> fStream;
|
|
|
|
bool fNeedsRewind;
|
2016-03-21 15:04:40 +00:00
|
|
|
const Origin fOrigin;
|
2016-03-04 21:27:35 +00:00
|
|
|
|
Merge SkCodec with SkScanlineDecoder
Benefits:
- This mimics other decoding APIs (including the ones SkCodec relies
on, e.g. a png_struct, which can be used to decode an entire image or
one line at a time).
- It allows a client to ask us to do what we can do efficiently - i.e.
start from encoded data and either decode the whole thing or scanlines.
- It removes the duplicate methods which appeared in both SkCodec and
SkScanlineDecoder (some of which, e.g. in SkJpegScanlineDecoder, just
call fCodec->sameMethod()).
- It simplifies moving more checks into the base class (e.g. the
examples in skbug.com/4284).
BUG=skia:4175
BUG=skia:4284
=====================================================================
SkScanlineDecoder.h/.cpp:
Removed.
SkCodec.h/.cpp:
Add methods, enums, and variables which were previously in
SkScanlineDecoder.
Default fCurrScanline to -1, as a sentinel that start has not been
called.
General changes:
Convert SkScanlineDecoders to SkCodecs.
General changes in SkCodec subclasses:
Merge SkScanlineDecoder implementation into SkCodec. Most (all?) owned
an SkCodec, so they now call this-> instead of fCodec->.
SkBmpCodec.h/.cpp:
Replace the unused rowOrder method with an override for
onGetScanlineOrder.
Make getDstRow const, since it is called by onGetY, which is const.
SkCodec_libpng.h/.cpp:
Make SkPngCodec an abstract class, with two subclasses which handle
scanline decoding separately (they share code for decoding the entire
image). Reimplement onReallyHasAlpha so that it can return the most
recent result (e.g. after a scanline decode which only decoded part
of the image) or a better answer (e.g. if the whole image is known to
be opaque).
Compute fNumberPasses early, so we know which subclass to instantiate.
Make SkPngInterlaceScanlineDecoder use the base class' fCurrScanline
rather than a separate variable.
CodexTest.cpp:
Add tests for the state changes in SkCodec (need to call start before
decoding scanlines; calling getPixels means that start will need to
be called again before decoding more scanlines).
Add a test which decodes in stripes, currently only used for an
interlaced PNG.
TODO: Add tests for onReallyHasAlpha.
Review URL: https://codereview.chromium.org/1365313002
2015-09-30 15:57:13 +00:00
|
|
|
// These fields are only meaningful during scanline decodes.
|
2016-03-04 21:27:35 +00:00
|
|
|
SkImageInfo fDstInfo;
|
|
|
|
SkCodec::Options fOptions;
|
|
|
|
int fCurrScanline;
|
Merge SkCodec with SkScanlineDecoder
Benefits:
- This mimics other decoding APIs (including the ones SkCodec relies
on, e.g. a png_struct, which can be used to decode an entire image or
one line at a time).
- It allows a client to ask us to do what we can do efficiently - i.e.
start from encoded data and either decode the whole thing or scanlines.
- It removes the duplicate methods which appeared in both SkCodec and
SkScanlineDecoder (some of which, e.g. in SkJpegScanlineDecoder, just
call fCodec->sameMethod()).
- It simplifies moving more checks into the base class (e.g. the
examples in skbug.com/4284).
BUG=skia:4175
BUG=skia:4284
=====================================================================
SkScanlineDecoder.h/.cpp:
Removed.
SkCodec.h/.cpp:
Add methods, enums, and variables which were previously in
SkScanlineDecoder.
Default fCurrScanline to -1, as a sentinel that start has not been
called.
General changes:
Convert SkScanlineDecoders to SkCodecs.
General changes in SkCodec subclasses:
Merge SkScanlineDecoder implementation into SkCodec. Most (all?) owned
an SkCodec, so they now call this-> instead of fCodec->.
SkBmpCodec.h/.cpp:
Replace the unused rowOrder method with an override for
onGetScanlineOrder.
Make getDstRow const, since it is called by onGetY, which is const.
SkCodec_libpng.h/.cpp:
Make SkPngCodec an abstract class, with two subclasses which handle
scanline decoding separately (they share code for decoding the entire
image). Reimplement onReallyHasAlpha so that it can return the most
recent result (e.g. after a scanline decode which only decoded part
of the image) or a better answer (e.g. if the whole image is known to
be opaque).
Compute fNumberPasses early, so we know which subclass to instantiate.
Make SkPngInterlaceScanlineDecoder use the base class' fCurrScanline
rather than a separate variable.
CodexTest.cpp:
Add tests for the state changes in SkCodec (need to call start before
decoding scanlines; calling getPixels means that start will need to
be called again before decoding more scanlines).
Add a test which decodes in stripes, currently only used for an
interlaced PNG.
TODO: Add tests for onReallyHasAlpha.
Review URL: https://codereview.chromium.org/1365313002
2015-09-30 15:57:13 +00:00
|
|
|
|
2015-10-02 20:14:46 +00:00
|
|
|
/**
|
|
|
|
* Return whether these dimensions are supported as a scale.
|
|
|
|
*
|
|
|
|
* The codec may choose to cache the information about scale and subset.
|
|
|
|
* Either way, the same information will be passed to onGetPixels/onStart
|
|
|
|
* on success.
|
|
|
|
*
|
|
|
|
* This must return true for a size returned from getScaledDimensions.
|
|
|
|
*/
|
|
|
|
bool dimensionsSupported(const SkISize& dim) {
|
|
|
|
return dim == fSrcInfo.dimensions() || this->onDimensionsSupported(dim);
|
|
|
|
}
|
|
|
|
|
Merge SkCodec with SkScanlineDecoder
Benefits:
- This mimics other decoding APIs (including the ones SkCodec relies
on, e.g. a png_struct, which can be used to decode an entire image or
one line at a time).
- It allows a client to ask us to do what we can do efficiently - i.e.
start from encoded data and either decode the whole thing or scanlines.
- It removes the duplicate methods which appeared in both SkCodec and
SkScanlineDecoder (some of which, e.g. in SkJpegScanlineDecoder, just
call fCodec->sameMethod()).
- It simplifies moving more checks into the base class (e.g. the
examples in skbug.com/4284).
BUG=skia:4175
BUG=skia:4284
=====================================================================
SkScanlineDecoder.h/.cpp:
Removed.
SkCodec.h/.cpp:
Add methods, enums, and variables which were previously in
SkScanlineDecoder.
Default fCurrScanline to -1, as a sentinel that start has not been
called.
General changes:
Convert SkScanlineDecoders to SkCodecs.
General changes in SkCodec subclasses:
Merge SkScanlineDecoder implementation into SkCodec. Most (all?) owned
an SkCodec, so they now call this-> instead of fCodec->.
SkBmpCodec.h/.cpp:
Replace the unused rowOrder method with an override for
onGetScanlineOrder.
Make getDstRow const, since it is called by onGetY, which is const.
SkCodec_libpng.h/.cpp:
Make SkPngCodec an abstract class, with two subclasses which handle
scanline decoding separately (they share code for decoding the entire
image). Reimplement onReallyHasAlpha so that it can return the most
recent result (e.g. after a scanline decode which only decoded part
of the image) or a better answer (e.g. if the whole image is known to
be opaque).
Compute fNumberPasses early, so we know which subclass to instantiate.
Make SkPngInterlaceScanlineDecoder use the base class' fCurrScanline
rather than a separate variable.
CodexTest.cpp:
Add tests for the state changes in SkCodec (need to call start before
decoding scanlines; calling getPixels means that start will need to
be called again before decoding more scanlines).
Add a test which decodes in stripes, currently only used for an
interlaced PNG.
TODO: Add tests for onReallyHasAlpha.
Review URL: https://codereview.chromium.org/1365313002
2015-09-30 15:57:13 +00:00
|
|
|
// Methods for scanline decoding.
|
2015-11-11 20:43:07 +00:00
|
|
|
virtual SkCodec::Result onStartScanlineDecode(const SkImageInfo& /*dstInfo*/,
|
|
|
|
const SkCodec::Options& /*options*/, SkPMColor* /*ctable*/, int* /*ctableCount*/) {
|
Merge SkCodec with SkScanlineDecoder
Benefits:
- This mimics other decoding APIs (including the ones SkCodec relies
on, e.g. a png_struct, which can be used to decode an entire image or
one line at a time).
- It allows a client to ask us to do what we can do efficiently - i.e.
start from encoded data and either decode the whole thing or scanlines.
- It removes the duplicate methods which appeared in both SkCodec and
SkScanlineDecoder (some of which, e.g. in SkJpegScanlineDecoder, just
call fCodec->sameMethod()).
- It simplifies moving more checks into the base class (e.g. the
examples in skbug.com/4284).
BUG=skia:4175
BUG=skia:4284
=====================================================================
SkScanlineDecoder.h/.cpp:
Removed.
SkCodec.h/.cpp:
Add methods, enums, and variables which were previously in
SkScanlineDecoder.
Default fCurrScanline to -1, as a sentinel that start has not been
called.
General changes:
Convert SkScanlineDecoders to SkCodecs.
General changes in SkCodec subclasses:
Merge SkScanlineDecoder implementation into SkCodec. Most (all?) owned
an SkCodec, so they now call this-> instead of fCodec->.
SkBmpCodec.h/.cpp:
Replace the unused rowOrder method with an override for
onGetScanlineOrder.
Make getDstRow const, since it is called by onGetY, which is const.
SkCodec_libpng.h/.cpp:
Make SkPngCodec an abstract class, with two subclasses which handle
scanline decoding separately (they share code for decoding the entire
image). Reimplement onReallyHasAlpha so that it can return the most
recent result (e.g. after a scanline decode which only decoded part
of the image) or a better answer (e.g. if the whole image is known to
be opaque).
Compute fNumberPasses early, so we know which subclass to instantiate.
Make SkPngInterlaceScanlineDecoder use the base class' fCurrScanline
rather than a separate variable.
CodexTest.cpp:
Add tests for the state changes in SkCodec (need to call start before
decoding scanlines; calling getPixels means that start will need to
be called again before decoding more scanlines).
Add a test which decodes in stripes, currently only used for an
interlaced PNG.
TODO: Add tests for onReallyHasAlpha.
Review URL: https://codereview.chromium.org/1365313002
2015-09-30 15:57:13 +00:00
|
|
|
return kUnimplemented;
|
|
|
|
}
|
|
|
|
|
2016-02-11 21:29:36 +00:00
|
|
|
virtual bool onSkipScanlines(int /*countLines*/) { return false; }
|
Merge SkCodec with SkScanlineDecoder
Benefits:
- This mimics other decoding APIs (including the ones SkCodec relies
on, e.g. a png_struct, which can be used to decode an entire image or
one line at a time).
- It allows a client to ask us to do what we can do efficiently - i.e.
start from encoded data and either decode the whole thing or scanlines.
- It removes the duplicate methods which appeared in both SkCodec and
SkScanlineDecoder (some of which, e.g. in SkJpegScanlineDecoder, just
call fCodec->sameMethod()).
- It simplifies moving more checks into the base class (e.g. the
examples in skbug.com/4284).
BUG=skia:4175
BUG=skia:4284
=====================================================================
SkScanlineDecoder.h/.cpp:
Removed.
SkCodec.h/.cpp:
Add methods, enums, and variables which were previously in
SkScanlineDecoder.
Default fCurrScanline to -1, as a sentinel that start has not been
called.
General changes:
Convert SkScanlineDecoders to SkCodecs.
General changes in SkCodec subclasses:
Merge SkScanlineDecoder implementation into SkCodec. Most (all?) owned
an SkCodec, so they now call this-> instead of fCodec->.
SkBmpCodec.h/.cpp:
Replace the unused rowOrder method with an override for
onGetScanlineOrder.
Make getDstRow const, since it is called by onGetY, which is const.
SkCodec_libpng.h/.cpp:
Make SkPngCodec an abstract class, with two subclasses which handle
scanline decoding separately (they share code for decoding the entire
image). Reimplement onReallyHasAlpha so that it can return the most
recent result (e.g. after a scanline decode which only decoded part
of the image) or a better answer (e.g. if the whole image is known to
be opaque).
Compute fNumberPasses early, so we know which subclass to instantiate.
Make SkPngInterlaceScanlineDecoder use the base class' fCurrScanline
rather than a separate variable.
CodexTest.cpp:
Add tests for the state changes in SkCodec (need to call start before
decoding scanlines; calling getPixels means that start will need to
be called again before decoding more scanlines).
Add a test which decodes in stripes, currently only used for an
interlaced PNG.
TODO: Add tests for onReallyHasAlpha.
Review URL: https://codereview.chromium.org/1365313002
2015-09-30 15:57:13 +00:00
|
|
|
|
2015-11-11 20:43:07 +00:00
|
|
|
virtual int onGetScanlines(void* /*dst*/, int /*countLines*/, size_t /*rowBytes*/) { return 0; }
|
2015-10-09 18:07:34 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* On an incomplete decode, getPixels() and getScanlines() will call this function
|
|
|
|
* to fill any uinitialized memory.
|
|
|
|
*
|
|
|
|
* @param dstInfo Contains the destination color type
|
|
|
|
* Contains the destination alpha type
|
|
|
|
* Contains the destination width
|
|
|
|
* The height stored in this info is unused
|
|
|
|
* @param dst Pointer to the start of destination pixel memory
|
|
|
|
* @param rowBytes Stride length in destination pixel memory
|
|
|
|
* @param zeroInit Indicates if memory is zero initialized
|
|
|
|
* @param linesRequested Number of lines that the client requested
|
|
|
|
* @param linesDecoded Number of lines that were successfully decoded
|
|
|
|
*/
|
|
|
|
void fillIncompleteImage(const SkImageInfo& dstInfo, void* dst, size_t rowBytes,
|
|
|
|
ZeroInitialized zeroInit, int linesRequested, int linesDecoded);
|
Merge SkCodec with SkScanlineDecoder
Benefits:
- This mimics other decoding APIs (including the ones SkCodec relies
on, e.g. a png_struct, which can be used to decode an entire image or
one line at a time).
- It allows a client to ask us to do what we can do efficiently - i.e.
start from encoded data and either decode the whole thing or scanlines.
- It removes the duplicate methods which appeared in both SkCodec and
SkScanlineDecoder (some of which, e.g. in SkJpegScanlineDecoder, just
call fCodec->sameMethod()).
- It simplifies moving more checks into the base class (e.g. the
examples in skbug.com/4284).
BUG=skia:4175
BUG=skia:4284
=====================================================================
SkScanlineDecoder.h/.cpp:
Removed.
SkCodec.h/.cpp:
Add methods, enums, and variables which were previously in
SkScanlineDecoder.
Default fCurrScanline to -1, as a sentinel that start has not been
called.
General changes:
Convert SkScanlineDecoders to SkCodecs.
General changes in SkCodec subclasses:
Merge SkScanlineDecoder implementation into SkCodec. Most (all?) owned
an SkCodec, so they now call this-> instead of fCodec->.
SkBmpCodec.h/.cpp:
Replace the unused rowOrder method with an override for
onGetScanlineOrder.
Make getDstRow const, since it is called by onGetY, which is const.
SkCodec_libpng.h/.cpp:
Make SkPngCodec an abstract class, with two subclasses which handle
scanline decoding separately (they share code for decoding the entire
image). Reimplement onReallyHasAlpha so that it can return the most
recent result (e.g. after a scanline decode which only decoded part
of the image) or a better answer (e.g. if the whole image is known to
be opaque).
Compute fNumberPasses early, so we know which subclass to instantiate.
Make SkPngInterlaceScanlineDecoder use the base class' fCurrScanline
rather than a separate variable.
CodexTest.cpp:
Add tests for the state changes in SkCodec (need to call start before
decoding scanlines; calling getPixels means that start will need to
be called again before decoding more scanlines).
Add a test which decodes in stripes, currently only used for an
interlaced PNG.
TODO: Add tests for onReallyHasAlpha.
Review URL: https://codereview.chromium.org/1365313002
2015-09-30 15:57:13 +00:00
|
|
|
|
2015-10-02 20:14:46 +00:00
|
|
|
/**
|
|
|
|
* Return an object which will allow forcing scanline decodes to sample in X.
|
|
|
|
*
|
|
|
|
* May create a sampler, if one is not currently being used. Otherwise, does
|
|
|
|
* not affect ownership.
|
|
|
|
*
|
|
|
|
* Only valid during scanline decoding.
|
|
|
|
*/
|
2015-11-11 20:43:07 +00:00
|
|
|
virtual SkSampler* getSampler(bool /*createIfNecessary*/) { return nullptr; }
|
2015-10-02 20:14:46 +00:00
|
|
|
|
2016-06-01 21:47:18 +00:00
|
|
|
// For testing with qcms
|
2016-06-03 15:25:21 +00:00
|
|
|
// FIXME: Remove these when we are done comparing with qcms.
|
2016-06-01 21:47:18 +00:00
|
|
|
friend class DM::ColorCodecSrc;
|
2016-06-03 15:25:21 +00:00
|
|
|
friend class ColorCodecBench;
|
|
|
|
|
2015-10-21 17:27:10 +00:00
|
|
|
friend class SkSampledCodec;
|
2015-12-04 16:00:50 +00:00
|
|
|
friend class SkIcoCodec;
|
2015-03-03 16:59:20 +00:00
|
|
|
};
|
|
|
|
#endif // SkCodec_DEFINED
|