Improved codec link-forcing system by adding Encoder/Decoder creation entry points
http://codereview.appspot.com/5881055/ git-svn-id: http://skia.googlecode.com/svn/trunk@3481 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
parent
34f10260ad
commit
ec51cb8634
@ -61,6 +61,10 @@ private:
|
||||
typedef GM INHERITED;
|
||||
};
|
||||
|
||||
void forceLinking() {
|
||||
SkImageDecoder *creator = CreateJPEGImageDecoder();
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static GM* MyFactory(void*) { return new CMYKJpegGM; }
|
||||
|
@ -332,5 +332,25 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
// This macro declares a global (i.e., non-class owned) creation entry point
|
||||
// for each decoder (e.g., CreateJPEGImageDecoder)
|
||||
#define DECLARE_DECODER_CREATOR(codec) \
|
||||
SkImageDecoder *Create ## codec ();
|
||||
|
||||
// This macro defines the global creation entry point for each decoder. Each
|
||||
// decoder implementation that registers with the decoder factory must call it.
|
||||
#define DEFINE_DECODER_CREATOR(codec) \
|
||||
SkImageDecoder *Create ## codec () { \
|
||||
return SkNEW( Sk ## codec ); \
|
||||
}
|
||||
|
||||
// All the decoders known by Skia. Note that, depending on the compiler settings,
|
||||
// not all of these will be available
|
||||
DECLARE_DECODER_CREATOR(BMPImageDecoder);
|
||||
DECLARE_DECODER_CREATOR(GIFImageDecoder);
|
||||
DECLARE_DECODER_CREATOR(ICOImageDecoder);
|
||||
DECLARE_DECODER_CREATOR(JPEGImageDecoder);
|
||||
DECLARE_DECODER_CREATOR(PNGImageDecoder);
|
||||
DECLARE_DECODER_CREATOR(WBMPImageDecoder);
|
||||
|
||||
#endif
|
||||
|
@ -40,4 +40,21 @@ protected:
|
||||
virtual bool onEncode(SkWStream*, const SkBitmap&, int quality) = 0;
|
||||
};
|
||||
|
||||
// This macro declares a global (i.e., non-class owned) creation entry point
|
||||
// for each encoder (e.g., CreateJPEGImageEncoder)
|
||||
#define DECLARE_ENCODER_CREATOR(codec) \
|
||||
SkImageEncoder *Create ## codec ();
|
||||
|
||||
// This macro defines the global creation entry point for each encoder. Each
|
||||
// encoder implementation that registers with the encoder factory must call it.
|
||||
#define DEFINE_ENCODER_CREATOR(codec) \
|
||||
SkImageEncoder *Create ## codec () { \
|
||||
return SkNEW( Sk ## codec ); \
|
||||
}
|
||||
|
||||
// All the encoders known by Skia. Note that, depending on the compiler settings,
|
||||
// not all of these will be available
|
||||
DECLARE_ENCODER_CREATOR(JPEGImageEncoder);
|
||||
DECLARE_ENCODER_CREATOR(PNGImageEncoder);
|
||||
|
||||
#endif
|
||||
|
@ -12,37 +12,6 @@
|
||||
#include "SkStream.h"
|
||||
#include "SkTRegistry.h"
|
||||
|
||||
//extern SkImageDecoder* sk_libbmp_dfactory(SkStream*);
|
||||
//extern SkImageDecoder* sk_libgif_dfactory(SkStream*);
|
||||
//extern SkImageDecoder* sk_libico_dfactory(SkStream*);
|
||||
//extern SkImageDecoder* sk_libjpeg_dfactory(SkStream*);
|
||||
//extern SkImageDecoder* sk_libpng_dfactory(SkStream*);
|
||||
//extern SkImageDecoder* sk_wbmp_dfactory(SkStream*);
|
||||
|
||||
// To get the various image decoding classes to register themselves
|
||||
// pre-main we need to ensure they are linked into the application.
|
||||
// Ultimately we need to move to using DLLs rather than tightly
|
||||
// coupling the factory with the file format classes.
|
||||
void ForceLinking()
|
||||
{
|
||||
SkImageDecoder* codec = NULL;
|
||||
|
||||
// TODO: rather than force the linking here expose a
|
||||
// "Sk*ImageDecoderCreate" function for each codec
|
||||
// and let the app add these calls to force the linking.
|
||||
// Besides decoupling the codecs from the factory this
|
||||
// will also give the app the ability to circumvent the
|
||||
// factory and explicitly create a decoder w/o reaching
|
||||
// into Skia's guts
|
||||
|
||||
// codec = sk_libbmp_dfactory(NULL);
|
||||
// codec = sk_libgif_dfactory(NULL);
|
||||
// codec = sk_libico_dfactory(NULL);
|
||||
// codec = sk_libjpeg_dfactory(NULL);
|
||||
// codec = sk_libpng_dfactory(NULL);
|
||||
// codec = sk_wbmp_dfactory(NULL);
|
||||
}
|
||||
|
||||
typedef SkTRegistry<SkImageDecoder*, SkStream*> DecodeReg;
|
||||
|
||||
// N.B. You can't use "DecodeReg::gHead here" due to complex C++
|
||||
|
@ -27,6 +27,10 @@ protected:
|
||||
virtual bool onDecode(SkStream* stream, SkBitmap* bm, Mode mode);
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
DEFINE_DECODER_CREATOR(BMPImageDecoder);
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
SkImageDecoder* sk_libbmp_dfactory(SkStream* stream) {
|
||||
static const char kBmpMagic[] = { 'B', 'M' };
|
||||
|
||||
|
@ -326,6 +326,8 @@ DONE:
|
||||
return true;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
DEFINE_DECODER_CREATOR(GIFImageDecoder);
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "SkTRegistry.h"
|
||||
|
@ -366,6 +366,8 @@ static void editPixelBit32(const int pixelNo, const unsigned char* buf,
|
||||
*address = SkPreMultiplyARGB(alpha, red, green, blue);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
DEFINE_DECODER_CREATOR(ICOImageDecoder);
|
||||
/////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "SkTRegistry.h"
|
||||
|
@ -652,12 +652,15 @@ protected:
|
||||
}
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
DEFINE_DECODER_CREATOR(JPEGImageDecoder);
|
||||
DEFINE_ENCODER_CREATOR(JPEGImageEncoder);
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "SkTRegistry.h"
|
||||
|
||||
SkImageDecoder* sk_libjpeg_dfactory(SkStream* stream) {
|
||||
static const char gHeader[] = { 0xFF, 0xD8, 0xFF };
|
||||
static const unsigned char gHeader[] = { 0xFF, 0xD8, 0xFF };
|
||||
static const size_t HEADER_SIZE = sizeof(gHeader);
|
||||
|
||||
char buffer[HEADER_SIZE];
|
||||
|
@ -851,6 +851,9 @@ bool SkPNGImageEncoder::doEncode(SkWStream* stream, const SkBitmap& bitmap,
|
||||
return true;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
DEFINE_DECODER_CREATOR(PNGImageDecoder);
|
||||
DEFINE_ENCODER_CREATOR(PNGImageEncoder);
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "SkTRegistry.h"
|
||||
|
@ -147,6 +147,8 @@ bool SkWBMPImageDecoder::onDecode(SkStream* stream, SkBitmap* decodedBitmap,
|
||||
return true;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
DEFINE_DECODER_CREATOR(WBMPImageDecoder);
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "SkTRegistry.h"
|
||||
|
Loading…
Reference in New Issue
Block a user