aboutsummaryrefslogtreecommitdiffhomepage
path: root/gm
diff options
context:
space:
mode:
authorGravatar robertphillips@google.com <robertphillips@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-03-20 14:51:47 +0000
committerGravatar robertphillips@google.com <robertphillips@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-03-20 14:51:47 +0000
commitd5c9e996dff7169cd6bfbf5c6d1543fca512c1a5 (patch)
treec33f0ce090db0c651fe50f30c2979deebd68ea99 /gm
parent166e653f67f3fffc3846184a25ce45ab083f07a2 (diff)
Fix for CMYK jpeg decoding issue (69 - unable to read some jpeg files on android)
Diffstat (limited to 'gm')
-rw-r--r--gm/cmykjpeg.cpp69
-rw-r--r--gm/gm.cpp2
-rw-r--r--gm/gm.h30
-rw-r--r--gm/gmmain.cpp35
-rw-r--r--gm/resources/CMYK.jpgbin0 -> 116536 bytes
5 files changed, 113 insertions, 23 deletions
diff --git a/gm/cmykjpeg.cpp b/gm/cmykjpeg.cpp
new file mode 100644
index 0000000000..67d2a60451
--- /dev/null
+++ b/gm/cmykjpeg.cpp
@@ -0,0 +1,69 @@
+/*
+ * Copyright 2012 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "gm.h"
+#include "SkCanvas.h"
+#include "SkImageDecoder.h"
+#include "SkStream.h"
+
+namespace skiagm {
+
+/** Draw a CMYK encoded jpeg - libjpeg doesn't support CMYK->RGB
+ conversion so this tests Skia's internal processing
+*/
+class CMYKJpegGM : public GM {
+public:
+ CMYKJpegGM() {
+
+ // parameters to the "decode" call
+ bool dither = false;
+ SkBitmap::Config prefConfig = SkBitmap::kARGB_8888_Config;
+
+ SkString filename(INHERITED::gResourcePath);
+ if (!filename.endsWith("/") && !filename.endsWith("\\")) {
+ filename.append("/");
+ }
+
+ filename.append("CMYK.jpg");
+
+ SkFILEStream stream(filename.c_str());
+ SkImageDecoder* codec = SkImageDecoder::Factory(&stream);
+ if (codec) {
+ stream.rewind();
+ codec->setDitherImage(dither);
+ codec->decode(&stream, &fBitmap, prefConfig,
+ SkImageDecoder::kDecodePixels_Mode);
+ }
+ }
+
+protected:
+ virtual SkString onShortName() {
+ return SkString("cmykjpeg");
+ }
+
+ virtual SkISize onISize() {
+ return make_isize(640, 480);
+ }
+
+ virtual void onDraw(SkCanvas* canvas) {
+
+ canvas->translate(20*SK_Scalar1, 20*SK_Scalar1);
+ canvas->drawBitmap(fBitmap, 0, 0);
+ }
+
+private:
+ SkBitmap fBitmap;
+
+ typedef GM INHERITED;
+};
+
+//////////////////////////////////////////////////////////////////////////////
+
+static GM* MyFactory(void*) { return new CMYKJpegGM; }
+static GMRegistry reg(MyFactory);
+
+}
diff --git a/gm/gm.cpp b/gm/gm.cpp
index f9c0e6637f..b6f21f81ff 100644
--- a/gm/gm.cpp
+++ b/gm/gm.cpp
@@ -8,6 +8,8 @@
#include "gm.h"
using namespace skiagm;
+SkString GM::gResourcePath;
+
GM::GM() {
fBGColor = SK_ColorWHITE;
}
diff --git a/gm/gm.h b/gm/gm.h
index b0de9227f7..d75a1c17c8 100644
--- a/gm/gm.h
+++ b/gm/gm.h
@@ -18,18 +18,18 @@
#include "SkTRegistry.h"
namespace skiagm {
-
- static inline SkISize make_isize(int w, int h) {
- SkISize sz;
- sz.set(w, h);
- return sz;
- }
+
+ static inline SkISize make_isize(int w, int h) {
+ SkISize sz;
+ sz.set(w, h);
+ return sz;
+ }
class GM {
public:
GM();
virtual ~GM();
-
+
enum Flags {
kSkipPDF_Flag = 1 << 0,
kSkipPicture_Flag = 1 << 1
@@ -39,7 +39,7 @@ namespace skiagm {
void drawBackground(SkCanvas*);
void drawContent(SkCanvas*);
- SkISize getISize() { return this->onISize(); }
+ SkISize getISize() { return this->onISize(); }
const char* shortName();
uint32_t getFlags() const {
@@ -53,10 +53,16 @@ namespace skiagm {
// GM's getISize bounds.
void drawSizeBounds(SkCanvas*, SkColor);
- protected:
- virtual void onDraw(SkCanvas*) = 0;
- virtual void onDrawBackground(SkCanvas*);
- virtual SkISize onISize() = 0;
+ static void SetResourcePath(const char* resourcePath) {
+ gResourcePath = resourcePath;
+ }
+
+ protected:
+ static SkString gResourcePath;
+
+ virtual void onDraw(SkCanvas*) = 0;
+ virtual void onDrawBackground(SkCanvas*);
+ virtual SkISize onISize() = 0;
virtual SkString onShortName() = 0;
virtual uint32_t onGetFlags() const { return 0; }
diff --git a/gm/gmmain.cpp b/gm/gmmain.cpp
index 6f53ce8f7b..61095e173f 100644
--- a/gm/gmmain.cpp
+++ b/gm/gmmain.cpp
@@ -589,9 +589,9 @@ static ErrorBitfield test_picture_serialization(GM* gm,
static void usage(const char * argv0) {
SkDebugf(
- "%s [-w writePath] [-r readPath] [-d diffPath] [--noreplay]\n"
- " [--serialize] [--forceBWtext] [--nopdf] [--nodeferred]\n"
- " [--match substring] [--notexturecache]"
+ "%s [-w writePath] [-r readPath] [-d diffPath] [-i resourcePath]\n"
+ " [--noreplay] [--serialize] [--forceBWtext] [--nopdf] \n"
+ " [--nodeferred] [--match substring] [--notexturecache]"
#if SK_MESA
" [--mesagl]"
#endif
@@ -601,6 +601,7 @@ static void usage(const char * argv0) {
" readPath: directory to read reference images from;\n"
" reports if any pixels mismatch between reference and new images\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(
" --serialize: exercise SkPicture serialization & deserialization.\n");
@@ -660,6 +661,7 @@ int main(int argc, char * const argv[]) {
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* 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;
@@ -688,6 +690,11 @@ int main(int argc, char * const argv[]) {
if (argv < stop && **argv) {
diffPath = *argv;
}
+ } else if (strcmp(*argv, "-i") == 0) {
+ argv++;
+ if (argv < stop && **argv) {
+ resourcePath = *argv;
+ }
} else if (strcmp(*argv, "--forceBWtext") == 0) {
gForceBWtext = true;
} else if (strcmp(*argv, "--noreplay") == 0) {
@@ -709,17 +716,19 @@ int main(int argc, char * const argv[]) {
useMesa = true;
#endif
} else if (strcmp(*argv, "--notexturecache") == 0) {
- disableTextureCache = true;
+ disableTextureCache = true;
} else {
- usage(commandName);
- return -1;
+ usage(commandName);
+ return -1;
}
}
if (argv != stop) {
- usage(commandName);
- return -1;
+ usage(commandName);
+ return -1;
}
+ GM::SetResourcePath(resourcePath);
+
int maxW = -1;
int maxH = -1;
Iter iter;
@@ -763,6 +772,10 @@ int main(int argc, char * const argv[]) {
fprintf(stderr, "writing to %s\n", writePath);
}
+ if (resourcePath) {
+ fprintf(stderr, "reading resources from %s\n", resourcePath);
+ }
+
// Accumulate success of all tests.
int testsRun = 0;
int testsPassed = 0;
@@ -828,10 +841,10 @@ int main(int argc, char * const argv[]) {
if (doDeferred && !testErrors &&
(kGPU_Backend == gRec[i].fBackend ||
- kRaster_Backend == gRec[i].fBackend)) {
+ kRaster_Backend == gRec[i].fBackend)) {
testErrors |= test_deferred_drawing(gm, gRec[i],
- forwardRenderedBitmap,
- diffPath, gGrContext, rt.get());
+ forwardRenderedBitmap,
+ diffPath, gGrContext, rt.get());
}
if ((ERROR_NONE == testErrors) && doReplay &&
diff --git a/gm/resources/CMYK.jpg b/gm/resources/CMYK.jpg
new file mode 100644
index 0000000000..04ed9859dd
--- /dev/null
+++ b/gm/resources/CMYK.jpg
Binary files differ