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

Side by Side Diff: src/images/SkImageDecoder_libpng.cpp

Issue 23453031: Rewrite SkTRegistry to take any trivially-copyable type. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: reed+scroggo Created 7 years, 3 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
« no previous file with comments | « src/images/SkImageDecoder_libjpeg.cpp ('k') | src/images/SkImageDecoder_libwebp.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2006 The Android Open Source Project 3 * Copyright 2006 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 1156 matching lines...) Expand 10 before | Expand all | Expand 10 after
1167 /* clean up after the write, and free any memory allocated */ 1167 /* clean up after the write, and free any memory allocated */
1168 png_destroy_write_struct(&png_ptr, &info_ptr); 1168 png_destroy_write_struct(&png_ptr, &info_ptr);
1169 return true; 1169 return true;
1170 } 1170 }
1171 1171
1172 /////////////////////////////////////////////////////////////////////////////// 1172 ///////////////////////////////////////////////////////////////////////////////
1173 DEFINE_DECODER_CREATOR(PNGImageDecoder); 1173 DEFINE_DECODER_CREATOR(PNGImageDecoder);
1174 DEFINE_ENCODER_CREATOR(PNGImageEncoder); 1174 DEFINE_ENCODER_CREATOR(PNGImageEncoder);
1175 /////////////////////////////////////////////////////////////////////////////// 1175 ///////////////////////////////////////////////////////////////////////////////
1176 1176
1177 #include "SkTRegistry.h"
1178
1179 static bool is_png(SkStream* stream) { 1177 static bool is_png(SkStream* stream) {
1180 char buf[PNG_BYTES_TO_CHECK]; 1178 char buf[PNG_BYTES_TO_CHECK];
1181 if (stream->read(buf, PNG_BYTES_TO_CHECK) == PNG_BYTES_TO_CHECK && 1179 if (stream->read(buf, PNG_BYTES_TO_CHECK) == PNG_BYTES_TO_CHECK &&
1182 !png_sig_cmp((png_bytep) buf, (png_size_t)0, PNG_BYTES_TO_CHECK)) { 1180 !png_sig_cmp((png_bytep) buf, (png_size_t)0, PNG_BYTES_TO_CHECK)) {
1183 return true; 1181 return true;
1184 } 1182 }
1185 return false; 1183 return false;
1186 } 1184 }
1187 1185
1188 SkImageDecoder* sk_libpng_dfactory(SkStream* stream) { 1186 SkImageDecoder* sk_libpng_dfactory(SkStream* stream) {
1189 if (is_png(stream)) { 1187 if (is_png(stream)) {
1190 return SkNEW(SkPNGImageDecoder); 1188 return SkNEW(SkPNGImageDecoder);
1191 } 1189 }
1192 return NULL; 1190 return NULL;
1193 } 1191 }
1194 1192
1195 static SkImageDecoder::Format get_format_png(SkStream* stream) { 1193 static SkImageDecoder::Format get_format_png(SkStream* stream) {
1196 if (is_png(stream)) { 1194 if (is_png(stream)) {
1197 return SkImageDecoder::kPNG_Format; 1195 return SkImageDecoder::kPNG_Format;
1198 } 1196 }
1199 return SkImageDecoder::kUnknown_Format; 1197 return SkImageDecoder::kUnknown_Format;
1200 } 1198 }
1201 1199
1202 SkImageEncoder* sk_libpng_efactory(SkImageEncoder::Type t) { 1200 SkImageEncoder* sk_libpng_efactory(SkImageEncoder::Type t) {
1203 return (SkImageEncoder::kPNG_Type == t) ? SkNEW(SkPNGImageEncoder) : NULL; 1201 return (SkImageEncoder::kPNG_Type == t) ? SkNEW(SkPNGImageEncoder) : NULL;
1204 } 1202 }
1205 1203
1206 static SkTRegistry<SkImageEncoder*, SkImageEncoder::Type> gEReg(sk_libpng_efacto ry); 1204 static SkImageDecoder_DecodeReg gDReg(sk_libpng_dfactory);
1207 static SkTRegistry<SkImageDecoder::Format, SkStream*> gFormatReg(get_format_png) ; 1205 static SkImageDecoder_FormatReg gFormatReg(get_format_png);
1208 static SkTRegistry<SkImageDecoder*, SkStream*> gDReg(sk_libpng_dfactory); 1206 static SkImageEncoder_EncodeReg gEReg(sk_libpng_efactory);
OLDNEW
« no previous file with comments | « src/images/SkImageDecoder_libjpeg.cpp ('k') | src/images/SkImageDecoder_libwebp.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698