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

Side by Side 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: Implement onGetFormat for other decoders. 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2007 The Android Open Source Project 3 * Copyright 2007 The Android Open Source Project
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 9
10 #include "SkImageDecoder.h" 10 #include "SkImageDecoder.h"
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 virtual Format getFormat() const { 114 virtual Format getFormat() const {
115 return kJPEG_Format; 115 return kJPEG_Format;
116 } 116 }
117 117
118 protected: 118 protected:
119 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK 119 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
120 virtual bool onBuildTileIndex(SkStream *stream, int *width, int *height) SK_ OVERRIDE; 120 virtual bool onBuildTileIndex(SkStream *stream, int *width, int *height) SK_ OVERRIDE;
121 virtual bool onDecodeRegion(SkBitmap* bitmap, const SkIRect& rect) SK_OVERRI DE; 121 virtual bool onDecodeRegion(SkBitmap* bitmap, const SkIRect& rect) SK_OVERRI DE;
122 #endif 122 #endif
123 virtual bool onDecode(SkStream* stream, SkBitmap* bm, Mode) SK_OVERRIDE; 123 virtual bool onDecode(SkStream* stream, SkBitmap* bm, Mode) SK_OVERRIDE;
124 virtual Format onGetFormat(SkStream*) const SK_OVERRIDE;
124 125
125 private: 126 private:
126 SkJPEGImageIndex* fImageIndex; 127 SkJPEGImageIndex* fImageIndex;
127 int fImageWidth; 128 int fImageWidth;
128 int fImageHeight; 129 int fImageHeight;
129 130
130 typedef SkImageDecoder INHERITED; 131 typedef SkImageDecoder INHERITED;
131 }; 132 };
132 133
133 ////////////////////////////////////////////////////////////////////////// 134 //////////////////////////////////////////////////////////////////////////
(...skipping 852 matching lines...) Expand 10 before | Expand all | Expand 10 after
986 srcRow = (const void*)((const char*)srcRow + bm.rowBytes()); 987 srcRow = (const void*)((const char*)srcRow + bm.rowBytes());
987 } 988 }
988 989
989 jpeg_finish_compress(&cinfo); 990 jpeg_finish_compress(&cinfo);
990 jpeg_destroy_compress(&cinfo); 991 jpeg_destroy_compress(&cinfo);
991 992
992 return true; 993 return true;
993 } 994 }
994 }; 995 };
995 996
996 /////////////////////////////////////////////////////////////////////////////// 997 static bool is_jpeg(SkStream* stream) {
997 DEFINE_DECODER_CREATOR(JPEGImageDecoder);
998 DEFINE_ENCODER_CREATOR(JPEGImageEncoder);
999 ///////////////////////////////////////////////////////////////////////////////
1000
1001 #include "SkTRegistry.h"
1002
1003 static SkImageDecoder* sk_libjpeg_dfactory(SkStream* stream) {
1004 static const unsigned char gHeader[] = { 0xFF, 0xD8, 0xFF }; 998 static const unsigned char gHeader[] = { 0xFF, 0xD8, 0xFF };
1005 static const size_t HEADER_SIZE = sizeof(gHeader); 999 static const size_t HEADER_SIZE = sizeof(gHeader);
1006 1000
1007 char buffer[HEADER_SIZE]; 1001 char buffer[HEADER_SIZE];
1008 size_t len = stream->read(buffer, HEADER_SIZE); 1002 size_t len = stream->read(buffer, HEADER_SIZE);
1009 1003
1010 if (len != HEADER_SIZE) { 1004 if (len != HEADER_SIZE) {
1011 return NULL; // can't read enough 1005 return false; // can't read enough
1012 } 1006 }
1013 if (memcmp(buffer, gHeader, HEADER_SIZE)) { 1007 if (memcmp(buffer, gHeader, HEADER_SIZE)) {
1014 return NULL; 1008 return false;
1015 } 1009 }
1016 return SkNEW(SkJPEGImageDecoder); 1010 return true;
1011 }
1012
1013 SkImageDecoder::Format SkJPEGImageDecoder::onGetFormat(SkStream* stream) const {
1014 if (is_jpeg(stream)) {
1015 return kJPEG_Format;
1016 }
1017 return kUnknown_Format;
1018 }
1019
1020 ///////////////////////////////////////////////////////////////////////////////
1021 DEFINE_DECODER_CREATOR(JPEGImageDecoder);
1022 DEFINE_ENCODER_CREATOR(JPEGImageEncoder);
1023 ///////////////////////////////////////////////////////////////////////////////
1024
1025 #include "SkTRegistry.h"
1026
1027 static SkImageDecoder* sk_libjpeg_dfactory(SkStream* stream) {
1028 if (is_jpeg(stream)) {
1029 return SkNEW(SkJPEGImageDecoder);
1030 }
1031 return NULL;
1017 } 1032 }
1018 1033
1019 static SkImageEncoder* sk_libjpeg_efactory(SkImageEncoder::Type t) { 1034 static SkImageEncoder* sk_libjpeg_efactory(SkImageEncoder::Type t) {
1020 return (SkImageEncoder::kJPEG_Type == t) ? SkNEW(SkJPEGImageEncoder) : NULL; 1035 return (SkImageEncoder::kJPEG_Type == t) ? SkNEW(SkJPEGImageEncoder) : NULL;
1021 } 1036 }
1022 1037
1023 1038
1024 static SkTRegistry<SkImageDecoder*, SkStream*> gDReg(sk_libjpeg_dfactory); 1039 static SkTRegistry<SkImageDecoder*, SkStream*> gDReg(sk_libjpeg_dfactory);
1025 static SkTRegistry<SkImageEncoder*, SkImageEncoder::Type> gEReg(sk_libjpeg_efact ory); 1040 static SkTRegistry<SkImageEncoder*, SkImageEncoder::Type> gEReg(sk_libjpeg_efact ory);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698