Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(455)

Unified Diff: src/images/SkImageDecoder_libjpeg.cpp

Issue 14363003: Updates to skimage tool to use it for testing. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: GetFormat -> GetStreamFormat Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/images/SkImageDecoder_libico.cpp ('k') | src/images/SkImageDecoder_libpng.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/images/SkImageDecoder_libjpeg.cpp
diff --git a/src/images/SkImageDecoder_libjpeg.cpp b/src/images/SkImageDecoder_libjpeg.cpp
index 9920bacc45302e6c5ee3540cc62e3c0262d3683a..c55f4c4123394c4f26ebc2357d4204401486c369 100644
--- a/src/images/SkImageDecoder_libjpeg.cpp
+++ b/src/images/SkImageDecoder_libjpeg.cpp
@@ -998,9 +998,7 @@ DEFINE_DECODER_CREATOR(JPEGImageDecoder);
DEFINE_ENCODER_CREATOR(JPEGImageEncoder);
///////////////////////////////////////////////////////////////////////////////
-#include "SkTRegistry.h"
-
-static SkImageDecoder* sk_libjpeg_dfactory(SkStream* stream) {
+static bool is_jpeg(SkStream* stream) {
static const unsigned char gHeader[] = { 0xFF, 0xD8, 0xFF };
static const size_t HEADER_SIZE = sizeof(gHeader);
@@ -1008,12 +1006,28 @@ static SkImageDecoder* sk_libjpeg_dfactory(SkStream* stream) {
size_t len = stream->read(buffer, HEADER_SIZE);
if (len != HEADER_SIZE) {
- return NULL; // can't read enough
+ return false; // can't read enough
}
if (memcmp(buffer, gHeader, HEADER_SIZE)) {
- return NULL;
+ return false;
+ }
+ return true;
+}
+
+#include "SkTRegistry.h"
+
+static SkImageDecoder* sk_libjpeg_dfactory(SkStream* stream) {
+ if (is_jpeg(stream)) {
+ return SkNEW(SkJPEGImageDecoder);
+ }
+ return NULL;
+}
+
+static SkImageDecoder::Format get_format_jpeg(SkStream* stream) {
+ if (is_jpeg(stream)) {
+ return SkImageDecoder::kJPEG_Format;
}
- return SkNEW(SkJPEGImageDecoder);
+ return SkImageDecoder::kUnknown_Format;
}
static SkImageEncoder* sk_libjpeg_efactory(SkImageEncoder::Type t) {
@@ -1022,4 +1036,5 @@ static SkImageEncoder* sk_libjpeg_efactory(SkImageEncoder::Type t) {
static SkTRegistry<SkImageDecoder*, SkStream*> gDReg(sk_libjpeg_dfactory);
+static SkTRegistry<SkImageDecoder::Format, SkStream*> gFormatReg(get_format_jpeg);
static SkTRegistry<SkImageEncoder*, SkImageEncoder::Type> gEReg(sk_libjpeg_efactory);
« no previous file with comments | « src/images/SkImageDecoder_libico.cpp ('k') | src/images/SkImageDecoder_libpng.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698