reverting to 3437

git-svn-id: http://skia.googlecode.com/svn/trunk@3439 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
robertphillips@google.com 2012-03-20 15:13:04 +00:00
parent d5c9e996df
commit 0a89c90d18
14 changed files with 96 additions and 193 deletions

View File

@ -8,8 +8,6 @@
#include "gm.h" #include "gm.h"
using namespace skiagm; using namespace skiagm;
SkString GM::gResourcePath;
GM::GM() { GM::GM() {
fBGColor = SK_ColorWHITE; fBGColor = SK_ColorWHITE;
} }

30
gm/gm.h
View File

@ -18,18 +18,18 @@
#include "SkTRegistry.h" #include "SkTRegistry.h"
namespace skiagm { namespace skiagm {
static inline SkISize make_isize(int w, int h) { static inline SkISize make_isize(int w, int h) {
SkISize sz; SkISize sz;
sz.set(w, h); sz.set(w, h);
return sz; return sz;
} }
class GM { class GM {
public: public:
GM(); GM();
virtual ~GM(); virtual ~GM();
enum Flags { enum Flags {
kSkipPDF_Flag = 1 << 0, kSkipPDF_Flag = 1 << 0,
kSkipPicture_Flag = 1 << 1 kSkipPicture_Flag = 1 << 1
@ -39,7 +39,7 @@ namespace skiagm {
void drawBackground(SkCanvas*); void drawBackground(SkCanvas*);
void drawContent(SkCanvas*); void drawContent(SkCanvas*);
SkISize getISize() { return this->onISize(); } SkISize getISize() { return this->onISize(); }
const char* shortName(); const char* shortName();
uint32_t getFlags() const { uint32_t getFlags() const {
@ -53,16 +53,10 @@ namespace skiagm {
// GM's getISize bounds. // GM's getISize bounds.
void drawSizeBounds(SkCanvas*, SkColor); void drawSizeBounds(SkCanvas*, SkColor);
static void SetResourcePath(const char* resourcePath) { protected:
gResourcePath = resourcePath; virtual void onDraw(SkCanvas*) = 0;
} virtual void onDrawBackground(SkCanvas*);
virtual SkISize onISize() = 0;
protected:
static SkString gResourcePath;
virtual void onDraw(SkCanvas*) = 0;
virtual void onDrawBackground(SkCanvas*);
virtual SkISize onISize() = 0;
virtual SkString onShortName() = 0; virtual SkString onShortName() = 0;
virtual uint32_t onGetFlags() const { return 0; } virtual uint32_t onGetFlags() const { return 0; }

View File

@ -589,9 +589,9 @@ static ErrorBitfield test_picture_serialization(GM* gm,
static void usage(const char * argv0) { static void usage(const char * argv0) {
SkDebugf( SkDebugf(
"%s [-w writePath] [-r readPath] [-d diffPath] [-i resourcePath]\n" "%s [-w writePath] [-r readPath] [-d diffPath] [--noreplay]\n"
" [--noreplay] [--serialize] [--forceBWtext] [--nopdf] \n" " [--serialize] [--forceBWtext] [--nopdf] [--nodeferred]\n"
" [--nodeferred] [--match substring] [--notexturecache]" " [--match substring] [--notexturecache]"
#if SK_MESA #if SK_MESA
" [--mesagl]" " [--mesagl]"
#endif #endif
@ -601,7 +601,6 @@ static void usage(const char * argv0) {
" readPath: directory to read reference images from;\n" " readPath: directory to read reference images from;\n"
" reports if any pixels mismatch between reference and new images\n"); " reports if any pixels mismatch between reference and new images\n");
SkDebugf(" diffPath: directory to write difference images in.\n"); SkDebugf(" diffPath: directory to write difference images in.\n");
SkDebugf(" resourcePath: directory that stores image resources.\n");
SkDebugf(" --noreplay: do not exercise SkPicture replay.\n"); SkDebugf(" --noreplay: do not exercise SkPicture replay.\n");
SkDebugf( SkDebugf(
" --serialize: exercise SkPicture serialization & deserialization.\n"); " --serialize: exercise SkPicture serialization & deserialization.\n");
@ -661,7 +660,6 @@ int main(int argc, char * const argv[]) {
const char* writePath = NULL; // if non-null, where we write the originals const char* writePath = NULL; // if non-null, where we write the originals
const char* readPath = NULL; // if non-null, were we read from to compare const char* readPath = NULL; // if non-null, were we read from to compare
const char* diffPath = NULL; // if non-null, where we write our diffs (from compare) const char* diffPath = NULL; // if non-null, where we write our diffs (from compare)
const char* resourcePath = NULL;// if non-null, where we read from for image resources
SkTDArray<const char*> fMatches; SkTDArray<const char*> fMatches;
@ -690,11 +688,6 @@ int main(int argc, char * const argv[]) {
if (argv < stop && **argv) { if (argv < stop && **argv) {
diffPath = *argv; diffPath = *argv;
} }
} else if (strcmp(*argv, "-i") == 0) {
argv++;
if (argv < stop && **argv) {
resourcePath = *argv;
}
} else if (strcmp(*argv, "--forceBWtext") == 0) { } else if (strcmp(*argv, "--forceBWtext") == 0) {
gForceBWtext = true; gForceBWtext = true;
} else if (strcmp(*argv, "--noreplay") == 0) { } else if (strcmp(*argv, "--noreplay") == 0) {
@ -716,19 +709,17 @@ int main(int argc, char * const argv[]) {
useMesa = true; useMesa = true;
#endif #endif
} else if (strcmp(*argv, "--notexturecache") == 0) { } else if (strcmp(*argv, "--notexturecache") == 0) {
disableTextureCache = true; disableTextureCache = true;
} else { } else {
usage(commandName); usage(commandName);
return -1; return -1;
} }
} }
if (argv != stop) { if (argv != stop) {
usage(commandName); usage(commandName);
return -1; return -1;
} }
GM::SetResourcePath(resourcePath);
int maxW = -1; int maxW = -1;
int maxH = -1; int maxH = -1;
Iter iter; Iter iter;
@ -772,10 +763,6 @@ int main(int argc, char * const argv[]) {
fprintf(stderr, "writing to %s\n", writePath); fprintf(stderr, "writing to %s\n", writePath);
} }
if (resourcePath) {
fprintf(stderr, "reading resources from %s\n", resourcePath);
}
// Accumulate success of all tests. // Accumulate success of all tests.
int testsRun = 0; int testsRun = 0;
int testsPassed = 0; int testsPassed = 0;
@ -841,10 +828,10 @@ int main(int argc, char * const argv[]) {
if (doDeferred && !testErrors && if (doDeferred && !testErrors &&
(kGPU_Backend == gRec[i].fBackend || (kGPU_Backend == gRec[i].fBackend ||
kRaster_Backend == gRec[i].fBackend)) { kRaster_Backend == gRec[i].fBackend)) {
testErrors |= test_deferred_drawing(gm, gRec[i], testErrors |= test_deferred_drawing(gm, gRec[i],
forwardRenderedBitmap, forwardRenderedBitmap,
diffPath, gGrContext, rt.get()); diffPath, gGrContext, rt.get());
} }
if ((ERROR_NONE == testErrors) && doReplay && if ((ERROR_NONE == testErrors) && doReplay &&

View File

@ -9,7 +9,6 @@
'../gm/bitmapfilters.cpp', '../gm/bitmapfilters.cpp',
'../gm/bitmapscroll.cpp', '../gm/bitmapscroll.cpp',
'../gm/blurs.cpp', '../gm/blurs.cpp',
'../gm/cmykjpeg.cpp',
'../gm/colormatrix.cpp', '../gm/colormatrix.cpp',
'../gm/complexclip.cpp', '../gm/complexclip.cpp',
'../gm/complexclip2.cpp', '../gm/complexclip2.cpp',

View File

@ -5,7 +5,6 @@
'type': 'static_library', 'type': 'static_library',
'dependencies': [ 'dependencies': [
'utils.gyp:utils', 'utils.gyp:utils',
'libjpeg.gyp:libjpeg',
], ],
'include_dirs': [ 'include_dirs': [
'../include/config', '../include/config',
@ -34,7 +33,6 @@
'../src/images/SkImageDecoder_libgif.cpp', '../src/images/SkImageDecoder_libgif.cpp',
'../src/images/SkImageDecoder_libico.cpp', '../src/images/SkImageDecoder_libico.cpp',
'../src/images/SkImageDecoder_libpng.cpp', '../src/images/SkImageDecoder_libpng.cpp',
'../src/images/SkImageDecoder_libjpeg.cpp',
'../src/images/SkImageDecoder_wbmp.cpp', '../src/images/SkImageDecoder_wbmp.cpp',
'../src/images/SkImageEncoder.cpp', '../src/images/SkImageEncoder.cpp',
'../src/images/SkImageEncoder_Factory.cpp', '../src/images/SkImageEncoder_Factory.cpp',
@ -55,11 +53,14 @@
'conditions': [ 'conditions': [
[ 'skia_os == "win"', { [ 'skia_os == "win"', {
'sources!': [ 'sources!': [
'../include/images/SkJpegUtility.h',
'../src/images/SkFDStream.cpp', '../src/images/SkFDStream.cpp',
'../src/images/SkImageDecoder_Factory.cpp', '../src/images/SkImageDecoder_Factory.cpp',
'../src/images/SkImageDecoder_libgif.cpp', '../src/images/SkImageDecoder_libgif.cpp',
'../src/images/SkImageDecoder_libpng.cpp', '../src/images/SkImageDecoder_libpng.cpp',
'../src/images/SkImageEncoder_Factory.cpp', '../src/images/SkImageEncoder_Factory.cpp',
'../src/images/SkJpegUtility.cpp',
'../src/images/SkMovie_gif.cpp', '../src/images/SkMovie_gif.cpp',
], ],
'link_settings': { 'link_settings': {
@ -74,10 +75,13 @@
}], }],
[ 'skia_os == "mac"', { [ 'skia_os == "mac"', {
'sources!': [ 'sources!': [
'../include/images/SkJpegUtility.h',
'../src/images/SkImageDecoder_Factory.cpp', '../src/images/SkImageDecoder_Factory.cpp',
'../src/images/SkImageDecoder_libpng.cpp', '../src/images/SkImageDecoder_libpng.cpp',
'../src/images/SkImageDecoder_libgif.cpp', '../src/images/SkImageDecoder_libgif.cpp',
'../src/images/SkImageEncoder_Factory.cpp', '../src/images/SkImageEncoder_Factory.cpp',
'../src/images/SkJpegUtility.cpp',
'../src/images/SkMovie_gif.cpp', '../src/images/SkMovie_gif.cpp',
], ],
},{ #else if skia_os != mac },{ #else if skia_os != mac
@ -87,7 +91,10 @@
}], }],
[ 'skia_os in ["linux", "freebsd", "openbsd", "solaris"]', { [ 'skia_os in ["linux", "freebsd", "openbsd", "solaris"]', {
'sources!': [ 'sources!': [
'../include/images/SkJpegUtility.h',
'../src/images/SkImageDecoder_libgif.cpp', '../src/images/SkImageDecoder_libgif.cpp',
'../src/images/SkJpegUtility.cpp',
'../src/images/SkMovie_gif.cpp', '../src/images/SkMovie_gif.cpp',
], ],
# libpng stuff: # libpng stuff:
@ -106,6 +113,7 @@
}], }],
[ 'skia_os == "android"', { [ 'skia_os == "android"', {
'sources!': [ 'sources!': [
'../src/images/SkJpegUtility.cpp',
], ],
'dependencies': [ 'dependencies': [
'android_system.gyp:gif', 'android_system.gyp:gif',

View File

@ -13,19 +13,6 @@
'dependencies': [ 'dependencies': [
'../third_party/externals/libjpeg/libjpeg.gyp:libjpeg', '../third_party/externals/libjpeg/libjpeg.gyp:libjpeg',
], ],
'conditions': [
[ 'os_posix != 1 or OS == "mac"', {
# need to set include path when using our own version
'direct_dependent_settings': {
'include_dirs': [
'../third_party/externals/libjpeg',
],
},
},],
],
}, },
], ],
} }

View File

@ -590,44 +590,7 @@ static inline SampleWindow::DeviceType cycle_devicetype(SampleWindow::DeviceType
return gCT[ct]; return gCT[ct];
} }
static void usage(const char * argv0) {
SkDebugf("%s [sampleName] [-i resourcePath]\n", argv0);
SkDebugf(" sampleName: sample at which to start.\n");
SkDebugf(" resourcePath: directory that stores image resources.\n");
}
SampleWindow::SampleWindow(void* hwnd, int argc, char** argv, DeviceManager* devManager) : INHERITED(hwnd) { SampleWindow::SampleWindow(void* hwnd, int argc, char** argv, DeviceManager* devManager) : INHERITED(hwnd) {
const char* resourcePath = NULL;
fCurrIndex = -1;
const char* const commandName = argv[0];
char* const* stop = argv + argc;
for (++argv; argv < stop; ++argv) {
if (strcmp(*argv, "-i") == 0) {
argv++;
if (argv < stop && **argv) {
resourcePath = *argv;
}
} else {
fCurrIndex = findByTitle(*argv);
if (fCurrIndex < 0) {
fprintf(stderr, "Unknown sample \"%s\"\n", *argv);
}
}
}
if (fCurrIndex < 0) {
SkString title;
if (readTitleFromPrefs(&title)) {
fCurrIndex = findByTitle(title.c_str());
}
}
if (fCurrIndex < 0) {
fCurrIndex = 0;
}
gSampleWindow = this; gSampleWindow = this;
#ifdef PIPE_FILE #ifdef PIPE_FILE
@ -731,8 +694,6 @@ SampleWindow::SampleWindow(void* hwnd, int argc, char** argv, DeviceManager* dev
this->setVisibleP(true); this->setVisibleP(true);
this->setClipToBounds(false); this->setClipToBounds(false);
skiagm::GM::SetResourcePath(resourcePath);
SkGMRegistyToSampleRegistry(); SkGMRegistyToSampleRegistry();
{ {
const SkViewRegister* reg = SkViewRegister::Head(); const SkViewRegister* reg = SkViewRegister::Head();
@ -741,7 +702,22 @@ SampleWindow::SampleWindow(void* hwnd, int argc, char** argv, DeviceManager* dev
reg = reg->next(); reg = reg->next();
} }
} }
fCurrIndex = 0;
if (argc > 1) {
fCurrIndex = findByTitle(argv[1]);
if (fCurrIndex < 0) {
fprintf(stderr, "Unknown sample \"%s\"\n", argv[1]);
}
} else {
SkString title;
if (readTitleFromPrefs(&title)) {
fCurrIndex = findByTitle(title.c_str());
}
}
if (fCurrIndex < 0) {
fCurrIndex = 0;
}
this->loadView((*fSamples[fCurrIndex])()); this->loadView((*fSamples[fCurrIndex])());
fPDFData = NULL; fPDFData = NULL;

View File

@ -12,37 +12,6 @@
#include "SkStream.h" #include "SkStream.h"
#include "SkTRegistry.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; typedef SkTRegistry<SkImageDecoder*, SkStream*> DecodeReg;
// N.B. You can't use "DecodeReg::gHead here" due to complex C++ // N.B. You can't use "DecodeReg::gHead here" due to complex C++

View File

@ -27,7 +27,7 @@ protected:
virtual bool onDecode(SkStream* stream, SkBitmap* bm, Mode mode); virtual bool onDecode(SkStream* stream, SkBitmap* bm, Mode mode);
}; };
SkImageDecoder* sk_libbmp_dfactory(SkStream* stream) { static SkImageDecoder* Factory(SkStream* stream) {
static const char kBmpMagic[] = { 'B', 'M' }; static const char kBmpMagic[] = { 'B', 'M' };
size_t len = stream->getLength(); size_t len = stream->getLength();
@ -41,7 +41,7 @@ SkImageDecoder* sk_libbmp_dfactory(SkStream* stream) {
return NULL; return NULL;
} }
static SkTRegistry<SkImageDecoder*, SkStream*> gReg(sk_libbmp_dfactory); static SkTRegistry<SkImageDecoder*, SkStream*> gReg(Factory);
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////

View File

@ -330,7 +330,7 @@ DONE:
#include "SkTRegistry.h" #include "SkTRegistry.h"
static SkImageDecoder* sk_libgif_dfactory(SkStream* stream) { static SkImageDecoder* Factory(SkStream* stream) {
char buf[GIF_STAMP_LEN]; char buf[GIF_STAMP_LEN];
if (stream->read(buf, GIF_STAMP_LEN) == GIF_STAMP_LEN) { if (stream->read(buf, GIF_STAMP_LEN) == GIF_STAMP_LEN) {
if (memcmp(GIF_STAMP, buf, GIF_STAMP_LEN) == 0 || if (memcmp(GIF_STAMP, buf, GIF_STAMP_LEN) == 0 ||
@ -342,4 +342,4 @@ static SkImageDecoder* sk_libgif_dfactory(SkStream* stream) {
return NULL; return NULL;
} }
static SkTRegistry<SkImageDecoder*, SkStream*> gReg(sk_libgif_dfactory); static SkTRegistry<SkImageDecoder*, SkStream*> gReg(Factory);

View File

@ -24,6 +24,7 @@ protected:
virtual bool onDecode(SkStream* stream, SkBitmap* bm, Mode); virtual bool onDecode(SkStream* stream, SkBitmap* bm, Mode);
}; };
SkImageDecoder* SkCreateICOImageDecoder();
SkImageDecoder* SkCreateICOImageDecoder() { SkImageDecoder* SkCreateICOImageDecoder() {
return new SkICOImageDecoder; return new SkICOImageDecoder;
} }
@ -370,7 +371,7 @@ static void editPixelBit32(const int pixelNo, const unsigned char* buf,
#include "SkTRegistry.h" #include "SkTRegistry.h"
SkImageDecoder* sk_libico_dfactory(SkStream* stream) { static SkImageDecoder* Factory(SkStream* stream) {
// Check to see if the first four bytes are 0,0,1,0 // Check to see if the first four bytes are 0,0,1,0
// FIXME: Is that required and sufficient? // FIXME: Is that required and sufficient?
SkAutoMalloc autoMal(4); SkAutoMalloc autoMal(4);
@ -385,5 +386,5 @@ SkImageDecoder* sk_libico_dfactory(SkStream* stream) {
return SkNEW(SkICOImageDecoder); return SkNEW(SkICOImageDecoder);
} }
static SkTRegistry<SkImageDecoder*, SkStream*> gReg(sk_libico_dfactory); static SkTRegistry<SkImageDecoder*, SkStream*> gReg(Factory);

View File

@ -146,29 +146,6 @@ static bool return_false(const jpeg_decompress_struct& cinfo,
return false; // must always return false return false; // must always return false
} }
// Convert a scanline of CMYK samples to RGBX in place. Note that this
// method moves the "scanline" pointer in its processing
static void convert_CMYK_to_RGB(uint8_t* scanline, unsigned int width) {
// At this point we've received CMYK pixels from libjpeg. We
// perform a crude conversion to RGB (based on the formulae
// from easyrgb.com):
// CMYK -> CMY
// C = ( C * (1 - K) + K ) // for each CMY component
// CMY -> RGB
// R = ( 1 - C ) * 255 // for each RGB component
// Unfortunately we are seeing inverted CMYK so all the original terms
// are 1-. This yields:
// CMYK -> CMY
// C = ( (1-C) * (1 - (1-K) + (1-K) ) -> C = 1 - C*K
// The conversion from CMY->RGB remains the same
for (unsigned int x = 0; x < width; ++x, scanline += 4) {
scanline[0] = SkMulDiv255Round(scanline[0], scanline[3]);
scanline[1] = SkMulDiv255Round(scanline[1], scanline[3]);
scanline[2] = SkMulDiv255Round(scanline[2], scanline[3]);
scanline[3] = 255;
}
}
bool SkJPEGImageDecoder::onDecode(SkStream* stream, SkBitmap* bm, Mode mode) { bool SkJPEGImageDecoder::onDecode(SkStream* stream, SkBitmap* bm, Mode mode) {
#ifdef TIME_DECODE #ifdef TIME_DECODE
AutoTimeMillis atm("JPEG Decode"); AutoTimeMillis atm("JPEG Decode");
@ -179,7 +156,7 @@ bool SkJPEGImageDecoder::onDecode(SkStream* stream, SkBitmap* bm, Mode mode) {
jpeg_decompress_struct cinfo; jpeg_decompress_struct cinfo;
skjpeg_error_mgr sk_err; skjpeg_error_mgr sk_err;
skjpeg_source_mgr sk_stream(stream, this, false); skjpeg_source_mgr sk_stream(stream, this);
cinfo.err = jpeg_std_error(&sk_err); cinfo.err = jpeg_std_error(&sk_err);
sk_err.error_exit = skjpeg_error_exit; sk_err.error_exit = skjpeg_error_exit;
@ -224,14 +201,7 @@ bool SkJPEGImageDecoder::onDecode(SkStream* stream, SkBitmap* bm, Mode mode) {
cinfo.do_block_smoothing = 0; cinfo.do_block_smoothing = 0;
/* default format is RGB */ /* default format is RGB */
if (cinfo.jpeg_color_space == JCS_CMYK) { cinfo.out_color_space = JCS_RGB;
// libjpeg cannot convert from CMYK to RGB - here we set up
// so libjpeg will give us CMYK samples back and we will
// later manually convert them to RGB
cinfo.out_color_space = JCS_CMYK;
} else {
cinfo.out_color_space = JCS_RGB;
}
SkBitmap::Config config = this->getPrefConfig(k32Bit_SrcDepth, false); SkBitmap::Config config = this->getPrefConfig(k32Bit_SrcDepth, false);
// only these make sense for jpegs // only these make sense for jpegs
@ -243,9 +213,9 @@ bool SkJPEGImageDecoder::onDecode(SkStream* stream, SkBitmap* bm, Mode mode) {
#ifdef ANDROID_RGB #ifdef ANDROID_RGB
cinfo.dither_mode = JDITHER_NONE; cinfo.dither_mode = JDITHER_NONE;
if (SkBitmap::kARGB_8888_Config == config && JCS_CMYK != cinfo.out_color_space) { if (config == SkBitmap::kARGB_8888_Config) {
cinfo.out_color_space = JCS_RGBA_8888; cinfo.out_color_space = JCS_RGBA_8888;
} else if (SkBitmap::kRGB_565_Config == config && JCS_CMYK != cinfo.out_color_space) { } else if (config == SkBitmap::kRGB_565_Config) {
cinfo.out_color_space = JCS_RGB_565; cinfo.out_color_space = JCS_RGB_565;
if (this->getDitherImage()) { if (this->getDitherImage()) {
cinfo.dither_mode = JDITHER_ORDERED; cinfo.dither_mode = JDITHER_ORDERED;
@ -330,13 +300,10 @@ bool SkJPEGImageDecoder::onDecode(SkStream* stream, SkBitmap* bm, Mode mode) {
return true; return true;
} }
#endif #endif
// check for supported formats // check for supported formats
SkScaledBitmapSampler::SrcConfig sc; SkScaledBitmapSampler::SrcConfig sc;
if (JCS_CMYK == cinfo.out_color_space) { if (3 == cinfo.out_color_components && JCS_RGB == cinfo.out_color_space) {
// In this case we will manually convert the CMYK values to RGB
sc = SkScaledBitmapSampler::kRGBX;
} else if (3 == cinfo.out_color_components && JCS_RGB == cinfo.out_color_space) {
sc = SkScaledBitmapSampler::kRGB; sc = SkScaledBitmapSampler::kRGB;
#ifdef ANDROID_RGB #ifdef ANDROID_RGB
} else if (JCS_RGBA_8888 == cinfo.out_color_space) { } else if (JCS_RGBA_8888 == cinfo.out_color_space) {
@ -355,7 +322,7 @@ bool SkJPEGImageDecoder::onDecode(SkStream* stream, SkBitmap* bm, Mode mode) {
sampleSize); sampleSize);
bm->setConfig(config, sampler.scaledWidth(), sampler.scaledHeight()); bm->setConfig(config, sampler.scaledWidth(), sampler.scaledHeight());
// jpegs are always opaque (i.e. have no per-pixel alpha) // jpegs are always opauqe (i.e. have no per-pixel alpha)
bm->setIsOpaque(true); bm->setIsOpaque(true);
if (SkImageDecoder::kDecodeBounds_Mode == mode) { if (SkImageDecoder::kDecodeBounds_Mode == mode) {
@ -365,13 +332,12 @@ bool SkJPEGImageDecoder::onDecode(SkStream* stream, SkBitmap* bm, Mode mode) {
return return_false(cinfo, *bm, "allocPixelRef"); return return_false(cinfo, *bm, "allocPixelRef");
} }
SkAutoLockPixels alp(*bm); SkAutoLockPixels alp(*bm);
if (!sampler.begin(bm, sc, this->getDitherImage())) { if (!sampler.begin(bm, sc, this->getDitherImage())) {
return return_false(cinfo, *bm, "sampler.begin"); return return_false(cinfo, *bm, "sampler.begin");
} }
// The CMYK work-around relies on 4 components per pixel here uint8_t* srcRow = (uint8_t*)srcStorage.alloc(cinfo.output_width * 4);
uint8_t* srcRow = (uint8_t*)srcStorage.reset(cinfo.output_width * 4);
// Possibly skip initial rows [sampler.srcY0] // Possibly skip initial rows [sampler.srcY0]
if (!skip_src_rows(&cinfo, srcRow, sampler.srcY0())) { if (!skip_src_rows(&cinfo, srcRow, sampler.srcY0())) {
@ -388,11 +354,7 @@ bool SkJPEGImageDecoder::onDecode(SkStream* stream, SkBitmap* bm, Mode mode) {
if (this->shouldCancelDecode()) { if (this->shouldCancelDecode()) {
return return_false(cinfo, *bm, "shouldCancelDecode"); return return_false(cinfo, *bm, "shouldCancelDecode");
} }
if (JCS_CMYK == cinfo.out_color_space) {
convert_CMYK_to_RGB(srcRow, cinfo.output_width);
}
sampler.next(srcRow); sampler.next(srcRow);
if (bm->height() - 1 == y) { if (bm->height() - 1 == y) {
// we're done // we're done
@ -631,7 +593,7 @@ protected:
jpeg_start_compress(&cinfo, TRUE); jpeg_start_compress(&cinfo, TRUE);
const int width = bm.width(); const int width = bm.width();
uint8_t* oneRowP = (uint8_t*)oneRow.reset(width * 3); uint8_t* oneRowP = (uint8_t*)oneRow.alloc(width * 3);
const SkPMColor* colors = ctLocker.lockColors(bm); const SkPMColor* colors = ctLocker.lockColors(bm);
const void* srcRow = bm.getPixels(); const void* srcRow = bm.getPixels();
@ -656,7 +618,7 @@ protected:
#include "SkTRegistry.h" #include "SkTRegistry.h"
SkImageDecoder* sk_libjpeg_dfactory(SkStream* stream) { static SkImageDecoder* DFactory(SkStream* stream) {
static const char gHeader[] = { 0xFF, 0xD8, 0xFF }; static const char gHeader[] = { 0xFF, 0xD8, 0xFF };
static const size_t HEADER_SIZE = sizeof(gHeader); static const size_t HEADER_SIZE = sizeof(gHeader);
@ -672,11 +634,9 @@ SkImageDecoder* sk_libjpeg_dfactory(SkStream* stream) {
return SkNEW(SkJPEGImageDecoder); return SkNEW(SkJPEGImageDecoder);
} }
static SkImageEncoder* sk_libjpeg_efactory(SkImageEncoder::Type t) { static SkImageEncoder* EFactory(SkImageEncoder::Type t) {
return (SkImageEncoder::kJPEG_Type == t) ? SkNEW(SkJPEGImageEncoder) : NULL; return (SkImageEncoder::kJPEG_Type == t) ? SkNEW(SkJPEGImageEncoder) : NULL;
} }
static SkTRegistry<SkImageDecoder*, SkStream*> gDReg(DFactory);
static SkTRegistry<SkImageDecoder*, SkStream*> gDReg(sk_libjpeg_dfactory); static SkTRegistry<SkImageEncoder*, SkImageEncoder::Type> gEReg(EFactory);
static SkTRegistry<SkImageEncoder*, SkImageEncoder::Type> gEReg(sk_libjpeg_efactory);

View File

@ -151,7 +151,7 @@ bool SkWBMPImageDecoder::onDecode(SkStream* stream, SkBitmap* decodedBitmap,
#include "SkTRegistry.h" #include "SkTRegistry.h"
SkImageDecoder* sk_wbmp_dfactory(SkStream* stream) { static SkImageDecoder* Factory(SkStream* stream) {
wbmp_head head; wbmp_head head;
if (head.init(stream)) { if (head.init(stream)) {
@ -160,5 +160,5 @@ SkImageDecoder* sk_wbmp_dfactory(SkStream* stream) {
return NULL; return NULL;
} }
static SkTRegistry<SkImageDecoder*, SkStream*> gReg(sk_wbmp_dfactory); static SkTRegistry<SkImageDecoder*, SkStream*> gReg(Factory);

View File

@ -14,9 +14,26 @@ static void sk_init_source(j_decompress_ptr cinfo) {
skjpeg_source_mgr* src = (skjpeg_source_mgr*)cinfo->src; skjpeg_source_mgr* src = (skjpeg_source_mgr*)cinfo->src;
src->next_input_byte = (const JOCTET*)src->fBuffer; src->next_input_byte = (const JOCTET*)src->fBuffer;
src->bytes_in_buffer = 0; src->bytes_in_buffer = 0;
src->current_offset = 0;
src->fStream->rewind(); src->fStream->rewind();
} }
static boolean sk_seek_input_data(j_decompress_ptr cinfo, long byte_offset) {
skjpeg_source_mgr* src = (skjpeg_source_mgr*)cinfo->src;
if (byte_offset > src->current_offset) {
(void)src->fStream->skip(byte_offset - src->current_offset);
} else {
src->fStream->rewind();
(void)src->fStream->skip(byte_offset);
}
src->current_offset = byte_offset;
src->next_input_byte = (const JOCTET*)src->fBuffer;
src->bytes_in_buffer = 0;
return TRUE;
}
static boolean sk_fill_input_buffer(j_decompress_ptr cinfo) { static boolean sk_fill_input_buffer(j_decompress_ptr cinfo) {
skjpeg_source_mgr* src = (skjpeg_source_mgr*)cinfo->src; skjpeg_source_mgr* src = (skjpeg_source_mgr*)cinfo->src;
if (src->fDecoder != NULL && src->fDecoder->shouldCancelDecode()) { if (src->fDecoder != NULL && src->fDecoder->shouldCancelDecode()) {
@ -29,6 +46,7 @@ static boolean sk_fill_input_buffer(j_decompress_ptr cinfo) {
return FALSE; return FALSE;
} }
src->current_offset += bytes;
src->next_input_byte = (const JOCTET*)src->fBuffer; src->next_input_byte = (const JOCTET*)src->fBuffer;
src->bytes_in_buffer = bytes; src->bytes_in_buffer = bytes;
return TRUE; return TRUE;
@ -46,6 +64,7 @@ static void sk_skip_input_data(j_decompress_ptr cinfo, long num_bytes) {
cinfo->err->error_exit((j_common_ptr)cinfo); cinfo->err->error_exit((j_common_ptr)cinfo);
return; return;
} }
src->current_offset += bytes;
bytesToSkip -= bytes; bytesToSkip -= bytes;
} }
src->next_input_byte = (const JOCTET*)src->fBuffer; src->next_input_byte = (const JOCTET*)src->fBuffer;
@ -77,7 +96,9 @@ static void sk_term_source(j_decompress_ptr /*cinfo*/) {}
static void skmem_init_source(j_decompress_ptr cinfo) { static void skmem_init_source(j_decompress_ptr cinfo) {
skjpeg_source_mgr* src = (skjpeg_source_mgr*)cinfo->src; skjpeg_source_mgr* src = (skjpeg_source_mgr*)cinfo->src;
src->next_input_byte = (const JOCTET*)src->fMemoryBase; src->next_input_byte = (const JOCTET*)src->fMemoryBase;
src->start_input_byte = (const JOCTET*)src->fMemoryBase;
src->bytes_in_buffer = src->fMemoryBaseSize; src->bytes_in_buffer = src->fMemoryBaseSize;
src->current_offset = src->fMemoryBaseSize;
} }
static boolean skmem_fill_input_buffer(j_decompress_ptr cinfo) { static boolean skmem_fill_input_buffer(j_decompress_ptr cinfo) {
@ -106,6 +127,8 @@ skjpeg_source_mgr::skjpeg_source_mgr(SkStream* stream, SkImageDecoder* decoder,
bool ownStream) : fStream(stream) { bool ownStream) : fStream(stream) {
fDecoder = decoder; fDecoder = decoder;
const void* baseAddr = stream->getMemoryBase(); const void* baseAddr = stream->getMemoryBase();
size_t bufferSize = 4096;
size_t len;
fMemoryBase = NULL; fMemoryBase = NULL;
fUnrefStream = ownStream; fUnrefStream = ownStream;
fMemoryBaseSize = 0; fMemoryBaseSize = 0;
@ -115,6 +138,7 @@ skjpeg_source_mgr::skjpeg_source_mgr(SkStream* stream, SkImageDecoder* decoder,
skip_input_data = sk_skip_input_data; skip_input_data = sk_skip_input_data;
resync_to_restart = sk_resync_to_restart; resync_to_restart = sk_resync_to_restart;
term_source = sk_term_source; term_source = sk_term_source;
seek_input_data = sk_seek_input_data;
// SkDebugf("**************** use memorybase %p %d\n", fMemoryBase, fMemoryBaseSize); // SkDebugf("**************** use memorybase %p %d\n", fMemoryBase, fMemoryBaseSize);
} }