#include "SkTypes.h"
class SkStream;
+class SkStreamRewindable;
/** \class SkImageDecoder
*/
virtual Format getFormat() const;
- /** Return the format of the SkStream or kUnknown_Format if it cannot be determined. Rewinds the
- stream before returning.
+ /** Return the format of the SkStreamRewindable or kUnknown_Format if it cannot be determined.
+ Rewinds the stream before returning.
*/
- static Format GetStreamFormat(SkStream*);
+ static Format GetStreamFormat(SkStreamRewindable*);
/** Return a readable string of the Format provided.
*/
*
* Return true for success or false on failure.
*/
- bool buildTileIndex(SkStream*, int *width, int *height);
+ bool buildTileIndex(SkStreamRewindable*, int *width, int *height);
/**
* Decode a rectangle subset in the image.
/** Given a stream, this will try to find an appropriate decoder object.
If none is found, the method returns NULL.
*/
- static SkImageDecoder* Factory(SkStream*);
+ static SkImageDecoder* Factory(SkStreamRewindable*);
/** Decode the image stored in the specified file, and store the result
in bitmap. Return true for success or false on failure.
static bool DecodeMemoryToTarget(const void* buffer, size_t size, SkImage::Info* info,
const SkBitmapFactory::Target* target);
- /** Decode the image stored in the specified SkStream, and store the result
+ /** Decode the image stored in the specified SkStreamRewindable, and store the result
in bitmap. Return true for success or false on failure.
@param prefConfig If the PrefConfigTable is not set, prefer this config.
@param format On success, if format is non-null, it is set to the format
of the decoded stream. On failure it is ignored.
*/
- static bool DecodeStream(SkStream* stream, SkBitmap* bitmap,
+ static bool DecodeStream(SkStreamRewindable* stream, SkBitmap* bitmap,
SkBitmap::Config prefConfig, Mode,
Format* format = NULL);
- static bool DecodeStream(SkStream* stream, SkBitmap* bitmap) {
+ static bool DecodeStream(SkStreamRewindable* stream, SkBitmap* bitmap) {
return DecodeStream(stream, bitmap, SkBitmap::kNo_Config,
kDecodePixels_Mode, NULL);
}
// If the decoder wants to support tiled based decoding,
// this method must be overridden. This guy is called by buildTileIndex(...)
- virtual bool onBuildTileIndex(SkStream*, int *width, int *height) {
+ virtual bool onBuildTileIndex(SkStreamRewindable*, int *width, int *height) {
return false;
}
public:
SK_DECLARE_INST_COUNT(SkImageDecoderFactory)
- virtual SkImageDecoder* newDecoder(SkStream*) = 0;
+ virtual SkImageDecoder* newDecoder(SkStreamRewindable*) = 0;
private:
typedef SkRefCnt INHERITED;
class SkDefaultImageDecoderFactory : SkImageDecoderFactory {
public:
// calls SkImageDecoder::Factory(stream)
- virtual SkImageDecoder* newDecoder(SkStream* stream) {
+ virtual SkImageDecoder* newDecoder(SkStreamRewindable* stream) {
return SkImageDecoder::Factory(stream);
}
};
// Typedefs to make registering decoder and formatter callbacks easier.
// These have to be defined outside SkImageDecoder. :(
-typedef SkTRegistry<SkImageDecoder*(*)(SkStream*)> SkImageDecoder_DecodeReg;
-typedef SkTRegistry<SkImageDecoder::Format(*)(SkStream*)> SkImageDecoder_FormatReg;
+typedef SkTRegistry<SkImageDecoder*(*)(SkStreamRewindable*)> SkImageDecoder_DecodeReg;
+typedef SkTRegistry<SkImageDecoder::Format(*)(SkStreamRewindable*)> SkImageDecoder_FormatReg;
#endif
#include "SkString.h"
class SkImageRefPool;
-class SkStream;
+class SkStreamRewindable;
// define this to enable dumping whenever we add/remove/purge an imageref
//#define DUMP_IMAGEREF_LIFECYCLE
@param config The preferred config of the decoded bitmap.
@param sampleSize Requested sampleSize for decoding. Defaults to 1.
*/
- SkImageRef(SkStream*, SkBitmap::Config config, int sampleSize = 1, SkBaseMutex* mutex = NULL);
+ SkImageRef(SkStreamRewindable*, SkBitmap::Config config, int sampleSize = 1,
+ SkBaseMutex* mutex = NULL);
virtual ~SkImageRef();
/** this value is passed onto the decoder. Default is true
/** Override if you want to install a custom allocator.
When this is called we will have already acquired the mutex!
*/
- virtual bool onDecode(SkImageDecoder* codec, SkStream*, SkBitmap*,
+ virtual bool onDecode(SkImageDecoder* codec, SkStreamRewindable*, SkBitmap*,
SkBitmap::Config, SkImageDecoder::Mode);
/* Overrides from SkPixelRef
SkBitmap fBitmap;
private:
- SkStream* setStream(SkStream*);
+ SkStreamRewindable* setStream(SkStreamRewindable*);
// called with mutex already held. returns true if the bitmap is in the
// requested state (or further, i.e. has pixels)
bool prepareBitmap(SkImageDecoder::Mode);
SkImageDecoderFactory* fFactory; // may be null
- SkStream* fStream;
+ SkStreamRewindable* fStream;
SkBitmap::Config fConfig;
int fSampleSize;
bool fDoDither;
class SkImageRef_GlobalPool : public SkImageRef {
public:
// if pool is null, use the global pool
- SkImageRef_GlobalPool(SkStream*, SkBitmap::Config, int sampleSize = 1);
+ SkImageRef_GlobalPool(SkStreamRewindable*, SkBitmap::Config,
+ int sampleSize = 1);
virtual ~SkImageRef_GlobalPool();
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkImageRef_GlobalPool)
static void DumpPool();
protected:
- virtual bool onDecode(SkImageDecoder* codec, SkStream* stream,
+ virtual bool onDecode(SkImageDecoder* codec, SkStreamRewindable* stream,
SkBitmap* bitmap, SkBitmap::Config config,
SkImageDecoder::Mode mode);
#include "SkRefCnt.h"
#include "SkCanvas.h"
-class SkStream;
+class SkStreamRewindable;
class SkMovie : public SkRefCnt {
public:
/** Try to create a movie from the stream. If the stream format is not
supported, return NULL.
*/
- static SkMovie* DecodeStream(SkStream*);
+ static SkMovie* DecodeStream(SkStreamRewindable*);
/** Try to create a movie from the specified file path. If the file is not
found, or the format is not supported, return NULL. If a movie is
returned, the stream may be retained by the movie (via ref()) until
static SkBitmap load_bitmap() {
SkBitmap bm;
- SkStream* stream = SkStream::NewFromFile("/skimages/sesame_street_ensemble-hp.jpg");
+ SkStreamAsset* stream = SkStream::NewFromFile("/skimages/sesame_street_ensemble-hp.jpg");
if (stream) {
SkAutoUnref aur(stream);
fBitmap.reset();
//SkStream* stream = SkStream::GetURIStream(fUriBase, src.c_str());
- SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(src.c_str()));
+ SkAutoTUnref<SkStreamAsset> stream(SkStream::NewFromFile(src.c_str()));
if (stream.get()) {
SkImageDecoder::DecodeStream(stream, &fBitmap);
}
return this->onDecodeSubset(bm, rect);
}
-bool SkImageDecoder::buildTileIndex(SkStream* stream,
- int *width, int *height) {
+bool SkImageDecoder::buildTileIndex(SkStreamRewindable* stream,
+ int *width, int *height) {
// we reset this to false before calling onBuildTileIndex
fShouldCancelDecode = false;
SkASSERT(file);
SkASSERT(bm);
- SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(file));
+ SkAutoTUnref<SkStreamRewindable> stream(SkStream::NewFromFile(file));
if (stream.get()) {
if (SkImageDecoder::DecodeStream(stream, bm, pref, mode, format)) {
bm->pixelRef()->setURI(file);
}
-bool SkImageDecoder::DecodeStream(SkStream* stream, SkBitmap* bm,
- SkBitmap::Config pref, Mode mode, Format* format) {
+bool SkImageDecoder::DecodeStream(SkStreamRewindable* stream, SkBitmap* bm,
+ SkBitmap::Config pref, Mode mode,
+ Format* format) {
SkASSERT(stream);
SkASSERT(bm);
#include "SkMovie.h"
#include "SkStream.h"
-extern SkImageDecoder* image_decoder_from_stream(SkStream*);
+extern SkImageDecoder* image_decoder_from_stream(SkStreamRewindable*);
-SkImageDecoder* SkImageDecoder::Factory(SkStream* stream) {
+SkImageDecoder* SkImageDecoder::Factory(SkStreamRewindable* stream) {
return image_decoder_from_stream(stream);
}
/////////////////////////////////////////////////////////////////////////
-typedef SkTRegistry<SkMovie*(*)(SkStream*)> MovieReg;
+typedef SkTRegistry<SkMovie*(*)(SkStreamRewindable*)> MovieReg;
-SkMovie* SkMovie::DecodeStream(SkStream* stream) {
+SkMovie* SkMovie::DecodeStream(SkStreamRewindable* stream) {
const MovieReg* curr = MovieReg::Head();
while (curr) {
SkMovie* movie = curr->factory()(stream);
// This file is used for registration of SkImageDecoders. It also holds a function
// for checking all the the registered SkImageDecoders for one that matches an
-// input SkStream.
+// input SkStreamRewindable.
template SkImageDecoder_DecodeReg* SkImageDecoder_DecodeReg::gHead;
-SkImageDecoder* image_decoder_from_stream(SkStream*);
+SkImageDecoder* image_decoder_from_stream(SkStreamRewindable*);
-SkImageDecoder* image_decoder_from_stream(SkStream* stream) {
+SkImageDecoder* image_decoder_from_stream(SkStreamRewindable* stream) {
SkImageDecoder* codec = NULL;
const SkImageDecoder_DecodeReg* curr = SkImageDecoder_DecodeReg::Head();
while (curr) {
template SkImageDecoder_FormatReg* SkImageDecoder_FormatReg::gHead;
-SkImageDecoder::Format SkImageDecoder::GetStreamFormat(SkStream* stream) {
+SkImageDecoder::Format SkImageDecoder::GetStreamFormat(SkStreamRewindable* stream) {
const SkImageDecoder_FormatReg* curr = SkImageDecoder_FormatReg::Head();
while (curr != NULL) {
Format format = curr->factory()(stream);
DEFINE_DECODER_CREATOR(BMPImageDecoder);
///////////////////////////////////////////////////////////////////////////////
-static bool is_bmp(SkStream* stream) {
+static bool is_bmp(SkStreamRewindable* stream) {
static const char kBmpMagic[] = { 'B', 'M' };
!memcmp(buffer, kBmpMagic, sizeof(kBmpMagic));
}
-static SkImageDecoder* sk_libbmp_dfactory(SkStream* stream) {
+static SkImageDecoder* sk_libbmp_dfactory(SkStreamRewindable* stream) {
if (is_bmp(stream)) {
return SkNEW(SkBMPImageDecoder);
}
static SkImageDecoder_DecodeReg gReg(sk_libbmp_dfactory);
-static SkImageDecoder::Format get_format_bmp(SkStream* stream) {
+static SkImageDecoder::Format get_format_bmp(SkStreamRewindable* stream) {
if (is_bmp(stream)) {
return SkImageDecoder::kBMP_Format;
}
DEFINE_DECODER_CREATOR(GIFImageDecoder);
///////////////////////////////////////////////////////////////////////////////
-static bool is_gif(SkStream* stream) {
+static bool is_gif(SkStreamRewindable* stream) {
char buf[GIF_STAMP_LEN];
if (stream->read(buf, GIF_STAMP_LEN) == GIF_STAMP_LEN) {
if (memcmp(GIF_STAMP, buf, GIF_STAMP_LEN) == 0 ||
return false;
}
-static SkImageDecoder* sk_libgif_dfactory(SkStream* stream) {
+static SkImageDecoder* sk_libgif_dfactory(SkStreamRewindable* stream) {
if (is_gif(stream)) {
return SkNEW(SkGIFImageDecoder);
}
static SkImageDecoder_DecodeReg gReg(sk_libgif_dfactory);
-static SkImageDecoder::Format get_format_gif(SkStream* stream) {
+static SkImageDecoder::Format get_format_gif(SkStreamRewindable* stream) {
if (is_gif(stream)) {
return SkImageDecoder::kGIF_Format;
}
DEFINE_DECODER_CREATOR(ICOImageDecoder);
/////////////////////////////////////////////////////////////////////////////////////////
-static bool is_ico(SkStream* stream) {
+static bool is_ico(SkStreamRewindable* stream) {
// Check to see if the first four bytes are 0,0,1,0
// FIXME: Is that required and sufficient?
SkAutoMalloc autoMal(4);
return true;
}
-static SkImageDecoder* sk_libico_dfactory(SkStream* stream) {
+static SkImageDecoder* sk_libico_dfactory(SkStreamRewindable* stream) {
if (is_ico(stream)) {
return SkNEW(SkICOImageDecoder);
}
static SkImageDecoder_DecodeReg gReg(sk_libico_dfactory);
-static SkImageDecoder::Format get_format_ico(SkStream* stream) {
+static SkImageDecoder::Format get_format_ico(SkStreamRewindable* stream) {
if (is_ico(stream)) {
return SkImageDecoder::kICO_Format;
}
#ifdef SK_BUILD_FOR_ANDROID
class SkJPEGImageIndex {
public:
- SkJPEGImageIndex(SkStream* stream, SkImageDecoder* decoder)
+ SkJPEGImageIndex(SkStreamRewindable* stream, SkImageDecoder* decoder)
: fSrcMgr(stream, decoder)
, fInfoInitialized(false)
, fHuffmanCreated(false)
protected:
#ifdef SK_BUILD_FOR_ANDROID
- virtual bool onBuildTileIndex(SkStream *stream, int *width, int *height) SK_OVERRIDE;
+ virtual bool onBuildTileIndex(SkStreamRewindable *stream, int *width, int *height) SK_OVERRIDE;
virtual bool onDecodeSubset(SkBitmap* bitmap, const SkIRect& rect) SK_OVERRIDE;
#endif
virtual bool onDecode(SkStream* stream, SkBitmap* bm, Mode) SK_OVERRIDE;
}
#ifdef SK_BUILD_FOR_ANDROID
-bool SkJPEGImageDecoder::onBuildTileIndex(SkStream* stream, int *width, int *height) {
+bool SkJPEGImageDecoder::onBuildTileIndex(SkStreamRewindable* stream, int *width, int *height) {
SkAutoTDelete<SkJPEGImageIndex> imageIndex(SkNEW_ARGS(SkJPEGImageIndex, (stream, this)));
jpeg_decompress_struct* cinfo = imageIndex->cinfo();
DEFINE_ENCODER_CREATOR(JPEGImageEncoder);
///////////////////////////////////////////////////////////////////////////////
-static bool is_jpeg(SkStream* stream) {
+static bool is_jpeg(SkStreamRewindable* stream) {
static const unsigned char gHeader[] = { 0xFF, 0xD8, 0xFF };
static const size_t HEADER_SIZE = sizeof(gHeader);
return true;
}
-static SkImageDecoder* sk_libjpeg_dfactory(SkStream* stream) {
+
+static SkImageDecoder* sk_libjpeg_dfactory(SkStreamRewindable* stream) {
if (is_jpeg(stream)) {
return SkNEW(SkJPEGImageDecoder);
}
return NULL;
}
-static SkImageDecoder::Format get_format_jpeg(SkStream* stream) {
+static SkImageDecoder::Format get_format_jpeg(SkStreamRewindable* stream) {
if (is_jpeg(stream)) {
return SkImageDecoder::kJPEG_Format;
}
return (SkImageEncoder::kJPEG_Type == t) ? SkNEW(SkJPEGImageEncoder) : NULL;
}
-
static SkImageDecoder_DecodeReg gDReg(sk_libjpeg_dfactory);
static SkImageDecoder_FormatReg gFormatReg(get_format_jpeg);
static SkImageEncoder_EncodeReg gEReg(sk_libjpeg_efactory);
class SkPNGImageIndex {
public:
- SkPNGImageIndex(SkStream* stream, png_structp png_ptr, png_infop info_ptr)
+ SkPNGImageIndex(SkStreamRewindable* stream, png_structp png_ptr, png_infop info_ptr)
: fStream(stream)
, fPng_ptr(png_ptr)
, fInfo_ptr(info_ptr)
}
}
- SkAutoTUnref<SkStream> fStream;
- png_structp fPng_ptr;
- png_infop fInfo_ptr;
- SkBitmap::Config fConfig;
+ SkAutoTUnref<SkStreamRewindable> fStream;
+ png_structp fPng_ptr;
+ png_infop fInfo_ptr;
+ SkBitmap::Config fConfig;
};
class SkPNGImageDecoder : public SkImageDecoder {
protected:
#ifdef SK_BUILD_FOR_ANDROID
- virtual bool onBuildTileIndex(SkStream *stream, int *width, int *height) SK_OVERRIDE;
+ virtual bool onBuildTileIndex(SkStreamRewindable *stream, int *width, int *height) SK_OVERRIDE;
virtual bool onDecodeSubset(SkBitmap* bitmap, const SkIRect& region) SK_OVERRIDE;
#endif
virtual bool onDecode(SkStream* stream, SkBitmap* bm, Mode) SK_OVERRIDE;
#ifdef SK_BUILD_FOR_ANDROID
static void sk_seek_fn(png_structp png_ptr, png_uint_32 offset) {
- SkStream* sk_stream = (SkStream*) png_get_io_ptr(png_ptr);
+ SkStreamRewindable* sk_stream = (SkStreamRewindable*) png_get_io_ptr(png_ptr);
if (!sk_stream->rewind()) {
png_error(png_ptr, "Failed to rewind stream!");
}
#ifdef SK_BUILD_FOR_ANDROID
-bool SkPNGImageDecoder::onBuildTileIndex(SkStream* sk_stream, int *width, int *height) {
+bool SkPNGImageDecoder::onBuildTileIndex(SkStreamRewindable* sk_stream, int *width, int *height) {
png_structp png_ptr;
png_infop info_ptr;
DEFINE_ENCODER_CREATOR(PNGImageEncoder);
///////////////////////////////////////////////////////////////////////////////
-static bool is_png(SkStream* stream) {
+static bool is_png(SkStreamRewindable* stream) {
char buf[PNG_BYTES_TO_CHECK];
if (stream->read(buf, PNG_BYTES_TO_CHECK) == PNG_BYTES_TO_CHECK &&
!png_sig_cmp((png_bytep) buf, (png_size_t)0, PNG_BYTES_TO_CHECK)) {
return false;
}
-SkImageDecoder* sk_libpng_dfactory(SkStream* stream) {
+SkImageDecoder* sk_libpng_dfactory(SkStreamRewindable* stream) {
if (is_png(stream)) {
return SkNEW(SkPNGImageDecoder);
}
return NULL;
}
-static SkImageDecoder::Format get_format_png(SkStream* stream) {
+static SkImageDecoder::Format get_format_png(SkStreamRewindable* stream) {
if (is_png(stream)) {
return SkImageDecoder::kPNG_Format;
}
}
protected:
- virtual bool onBuildTileIndex(SkStream *stream, int *width, int *height) SK_OVERRIDE;
+ virtual bool onBuildTileIndex(SkStreamRewindable *stream, int *width, int *height) SK_OVERRIDE;
virtual bool onDecodeSubset(SkBitmap* bitmap, const SkIRect& rect) SK_OVERRIDE;
virtual bool onDecode(SkStream* stream, SkBitmap* bm, Mode) SK_OVERRIDE;
return true;
}
-bool SkWEBPImageDecoder::onBuildTileIndex(SkStream* stream,
+bool SkWEBPImageDecoder::onBuildTileIndex(SkStreamRewindable* stream,
int *width, int *height) {
int origWidth, origHeight, hasAlpha;
if (!webp_parse_header(stream, &origWidth, &origHeight, &hasAlpha)) {
DEFINE_ENCODER_CREATOR(WEBPImageEncoder);
///////////////////////////////////////////////////////////////////////////////
-static SkImageDecoder* sk_libwebp_dfactory(SkStream* stream) {
+static SkImageDecoder* sk_libwebp_dfactory(SkStreamRewindable* stream) {
int width, height, hasAlpha;
if (!webp_parse_header(stream, &width, &height, &hasAlpha)) {
return NULL;
return SkNEW(SkWEBPImageDecoder);
}
-static SkImageDecoder::Format get_format_webp(SkStream* stream) {
+static SkImageDecoder::Format get_format_webp(SkStreamRewindable* stream) {
int width, height, hasAlpha;
if (webp_parse_header(stream, &width, &height, &hasAlpha)) {
return SkImageDecoder::kWEBP_Format;
DEFINE_DECODER_CREATOR(WBMPImageDecoder);
///////////////////////////////////////////////////////////////////////////////
-static SkImageDecoder* sk_wbmp_dfactory(SkStream* stream) {
+static SkImageDecoder* sk_wbmp_dfactory(SkStreamRewindable* stream) {
wbmp_head head;
if (head.init(stream)) {
return NULL;
}
-static SkImageDecoder::Format get_format_wbmp(SkStream* stream) {
+static SkImageDecoder::Format get_format_wbmp(SkStreamRewindable* stream) {
wbmp_head head;
if (head.init(stream)) {
return SkImageDecoder::kWBMP_Format;
///////////////////////////////////////////////////////////////////////////////
-SkImageRef::SkImageRef(SkStream* stream, SkBitmap::Config config,
+SkImageRef::SkImageRef(SkStreamRewindable* stream, SkBitmap::Config config,
int sampleSize, SkBaseMutex* mutex)
: SkPixelRef(mutex), fErrorInDecoding(false) {
SkASSERT(stream);
///////////////////////////////////////////////////////////////////////////////
-bool SkImageRef::onDecode(SkImageDecoder* codec, SkStream* stream,
+bool SkImageRef::onDecode(SkImageDecoder* codec, SkStreamRewindable* stream,
SkBitmap* bitmap, SkBitmap::Config config,
SkImageDecoder::Mode mode) {
return codec->decode(stream, bitmap, config, mode);
return gPool;
}
-SkImageRef_GlobalPool::SkImageRef_GlobalPool(SkStream* stream,
+SkImageRef_GlobalPool::SkImageRef_GlobalPool(SkStreamRewindable* stream,
SkBitmap::Config config,
int sampleSize)
: SkImageRef(stream, config, sampleSize, &gGlobalPoolMutex) {
* that we also are already inside the mutex. Hence, we can reference
* the global-pool directly.
*/
-bool SkImageRef_GlobalPool::onDecode(SkImageDecoder* codec, SkStream* stream,
+bool SkImageRef_GlobalPool::onDecode(SkImageDecoder* codec, SkStreamRewindable* stream,
SkBitmap* bitmap, SkBitmap::Config config,
SkImageDecoder::Mode mode) {
if (!this->INHERITED::onDecode(codec, stream, bitmap, config, mode)) {
return newsize;
}
-SkImageRef_ashmem::SkImageRef_ashmem(SkStream* stream,
+SkImageRef_ashmem::SkImageRef_ashmem(SkStreamRewindable* stream,
SkBitmap::Config config,
int sampleSize)
: SkImageRef(stream, config, sampleSize) {
const char* fName;
};
-bool SkImageRef_ashmem::onDecode(SkImageDecoder* codec, SkStream* stream,
+bool SkImageRef_ashmem::onDecode(SkImageDecoder* codec, SkStreamRewindable* stream,
SkBitmap* bitmap, SkBitmap::Config config,
SkImageDecoder::Mode mode) {
class SkImageRef_ashmem : public SkImageRef {
public:
- SkImageRef_ashmem(SkStream*, SkBitmap::Config, int sampleSize = 1);
+ SkImageRef_ashmem(SkStreamRewindable*, SkBitmap::Config, int sampleSize = 1);
virtual ~SkImageRef_ashmem();
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkImageRef_ashmem)
SkImageRef_ashmem(SkFlattenableReadBuffer&);
virtual void flatten(SkFlattenableWriteBuffer&) const SK_OVERRIDE;
- virtual bool onDecode(SkImageDecoder* codec, SkStream* stream,
+ virtual bool onDecode(SkImageDecoder* codec, SkStreamRewindable* stream,
SkBitmap* bitmap, SkBitmap::Config config,
SkImageDecoder::Mode mode);
}
SkMovie* SkMovie::DecodeFile(const char path[]) {
- SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path));
+ SkAutoTUnref<SkStreamRewindable> stream(SkStream::NewFromFile(path));
return stream.get() ? SkMovie::DecodeStream(stream) : NULL;
}
#include "SkTRegistry.h"
-SkMovie* Factory(SkStream* stream) {
+SkMovie* Factory(SkStreamRewindable* stream) {
char buf[GIF_STAMP_LEN];
if (stream->read(buf, GIF_STAMP_LEN) == GIF_STAMP_LEN) {
if (memcmp(GIF_STAMP, buf, GIF_STAMP_LEN) == 0 ||
return NULL;
}
-static SkTRegistry<SkMovie*(*)(SkStream*)> gReg(Factory);
+static SkTRegistry<SkMovie*(*)(SkStreamRewindable*)> gReg(Factory);
///////////////////////////////////////////////////////////////////////////////
-extern SkImageDecoder* image_decoder_from_stream(SkStream*);
+extern SkImageDecoder* image_decoder_from_stream(SkStreamRewindable*);
-SkImageDecoder* SkImageDecoder::Factory(SkStream* stream) {
+SkImageDecoder* SkImageDecoder::Factory(SkStreamRewindable* stream) {
SkImageDecoder* decoder = image_decoder_from_stream(stream);
if (NULL == decoder) {
// If no image decoder specific to the stream exists, use SkImageDecoder_CG.
/////////////////////////////////////////////////////////////////////////
-SkMovie* SkMovie::DecodeStream(SkStream* stream) {
+SkMovie* SkMovie::DecodeStream(SkStreamRewindable* stream) {
return NULL;
}
///////////////////////////////////////////////////////////////////////////////
-#include "SkTRegistry.h"
-
static SkImageEncoder* sk_imageencoder_cg_factory(SkImageEncoder::Type t) {
switch (t) {
case SkImageEncoder::kICO_Type:
return SkNEW_ARGS(SkImageEncoder_CG, (t));
}
-static SkTRegistry<SkImageEncoder*(*)(SkImageEncoder::Type)> gEReg(sk_imageencoder_cg_factory);
+static SkImageEncoder_EncodeReg gEReg(sk_imageencoder_cg_factory);
struct FormatConversion {
CFStringRef fUTType;
return SkImageDecoder::kUnknown_Format;
}
-static SkImageDecoder::Format get_format_cg(SkStream *stream) {
+static SkImageDecoder::Format get_format_cg(SkStreamRewindable* stream) {
CGImageSourceRef imageSrc = SkStreamToCGImageSource(stream);
if (NULL == imageSrc) {
return UTType_to_Format(name);
}
-static SkTRegistry<SkImageDecoder::Format(*)(SkStream*)> gFormatReg(get_format_cg);
+static SkImageDecoder_FormatReg gFormatReg(get_format_cg);
/////////////////////////////////////////////////////////////////////////
-extern SkImageDecoder* image_decoder_from_stream(SkStream*);
+extern SkImageDecoder* image_decoder_from_stream(SkStreamRewindable*);
-SkImageDecoder* SkImageDecoder::Factory(SkStream* stream) {
+SkImageDecoder* SkImageDecoder::Factory(SkStreamRewindable* stream) {
SkImageDecoder* decoder = image_decoder_from_stream(stream);
if (NULL == decoder) {
// If no image decoder specific to the stream exists, use SkImageDecoder_WIC.
/////////////////////////////////////////////////////////////////////////
-SkMovie* SkMovie::DecodeStream(SkStream* stream) {
+SkMovie* SkMovie::DecodeStream(SkStreamRewindable* stream) {
return NULL;
}
///////////////////////////////////////////////////////////////////////////////
-#include "SkTRegistry.h"
-
static SkImageEncoder* sk_imageencoder_wic_factory(SkImageEncoder::Type t) {
switch (t) {
case SkImageEncoder::kBMP_Type:
return SkNEW_ARGS(SkImageEncoder_WIC, (t));
}
-static SkTRegistry<SkImageEncoder*(*)(SkImageEncoder::Type)> gEReg(sk_imageencoder_wic_factory);
+static SkImageEncoder_EncodeReg gEReg(sk_imageencoder_wic_factory);
-static SkImageDecoder::Format get_format_wic(SkStream* stream) {
+static SkImageDecoder::Format get_format_wic(SkStreamRewindable* stream) {
SkImageDecoder::Format format;
SkImageDecoder_WIC codec;
if (!codec.decodeStream(stream, NULL, SkImageDecoder_WIC::kDecodeFormat_WICMode, &format)) {
return format;
}
-static SkTRegistry<SkImageDecoder::Format(*)(SkStream*)> gFormatReg(get_format_wic);
+static SkImageDecoder_FormatReg gFormatReg(get_format_wic);
class SkColorTable;
class SkStream;
+class SkStreamRewindable;
// Empty implementations for SkImageDecoder.
-SkImageDecoder* SkImageDecoder::Factory(SkStream*) {
+SkImageDecoder* SkImageDecoder::Factory(SkStreamRewindable*) {
return NULL;
}
return false;
}
-bool SkImageDecoder::DecodeStream(SkStream*, SkBitmap*, SkBitmap::Config,
+bool SkImageDecoder::DecodeStream(SkStreamRewindable*, SkBitmap*, SkBitmap::Config,
SkImageDecoder::Mode,
SkImageDecoder::Format*) {
return false;
return false;
}
-bool SkImageDecoder::buildTileIndex(SkStream*, int *width, int *height) {
+bool SkImageDecoder::buildTileIndex(SkStreamRewindable*, int *width, int *height) {
return false;
}
return kUnknown_Format;
}
-SkImageDecoder::Format SkImageDecoder::GetStreamFormat(SkStream*) {
+SkImageDecoder::Format SkImageDecoder::GetStreamFormat(SkStreamRewindable*) {
return kUnknown_Format;
}
// Empty implementation for SkMovie.
-SkMovie* SkMovie::DecodeStream(SkStream* stream) {
+SkMovie* SkMovie::DecodeStream(SkStreamRewindable* stream) {
return NULL;
}
if (!this->fSkStream->rewind()) {
hr = E_FAIL;
} else {
+ // FIXME: Should not depend on getLength.
+ // See https://code.google.com/p/skia/issues/detail?id=1570
LONGLONG skip = this->fSkStream->getLength()
+ liDistanceToMove.QuadPart;
size_t skipped = this->fSkStream->skip(static_cast<size_t>(skip));
return STG_E_INVALIDFLAG;
}
pStatstg->pwcsName = NULL;
+ // FIXME: Should not depend on getLength
+ // See https://code.google.com/p/skia/issues/detail?id=1570
pStatstg->cbSize.QuadPart = this->fSkStream->getLength();
pStatstg->clsid = CLSID_NULL;
pStatstg->type = STGTY_STREAM;
#ifdef SK_DEBUG
// Create a stream containing a bitmap encoded to Type type.
-static SkStream* create_image_stream(SkImageEncoder::Type type) {
+static SkMemoryStream* create_image_stream(SkImageEncoder::Type type) {
SkBitmap bm;
const int size = 50;
bm.setConfig(SkBitmap::kARGB_8888_Config, size, size);
};
for (size_t i = 0; i < SK_ARRAY_COUNT(gTypes); ++i) {
//SkDebugf("encoding to %i\n", i);
- SkAutoTUnref<SkStream> stream(create_image_stream(gTypes[i]));
+ SkAutoTUnref<SkMemoryStream> stream(create_image_stream(gTypes[i]));
if (NULL == stream.get()) {
SkDebugf("no stream\n");
continue;