| OLD | NEW |
| 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 980 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 991 | 991 |
| 992 return true; | 992 return true; |
| 993 } | 993 } |
| 994 }; | 994 }; |
| 995 | 995 |
| 996 /////////////////////////////////////////////////////////////////////////////// | 996 /////////////////////////////////////////////////////////////////////////////// |
| 997 DEFINE_DECODER_CREATOR(JPEGImageDecoder); | 997 DEFINE_DECODER_CREATOR(JPEGImageDecoder); |
| 998 DEFINE_ENCODER_CREATOR(JPEGImageEncoder); | 998 DEFINE_ENCODER_CREATOR(JPEGImageEncoder); |
| 999 /////////////////////////////////////////////////////////////////////////////// | 999 /////////////////////////////////////////////////////////////////////////////// |
| 1000 | 1000 |
| 1001 #include "SkTRegistry.h" | 1001 static bool is_jpeg(SkStream* stream) { |
| 1002 | |
| 1003 static SkImageDecoder* sk_libjpeg_dfactory(SkStream* stream) { | |
| 1004 static const unsigned char gHeader[] = { 0xFF, 0xD8, 0xFF }; | 1002 static const unsigned char gHeader[] = { 0xFF, 0xD8, 0xFF }; |
| 1005 static const size_t HEADER_SIZE = sizeof(gHeader); | 1003 static const size_t HEADER_SIZE = sizeof(gHeader); |
| 1006 | 1004 |
| 1007 char buffer[HEADER_SIZE]; | 1005 char buffer[HEADER_SIZE]; |
| 1008 size_t len = stream->read(buffer, HEADER_SIZE); | 1006 size_t len = stream->read(buffer, HEADER_SIZE); |
| 1009 | 1007 |
| 1010 if (len != HEADER_SIZE) { | 1008 if (len != HEADER_SIZE) { |
| 1011 return NULL; // can't read enough | 1009 return false; // can't read enough |
| 1012 } | 1010 } |
| 1013 if (memcmp(buffer, gHeader, HEADER_SIZE)) { | 1011 if (memcmp(buffer, gHeader, HEADER_SIZE)) { |
| 1014 return NULL; | 1012 return false; |
| 1015 } | 1013 } |
| 1016 return SkNEW(SkJPEGImageDecoder); | 1014 return true; |
| 1015 } |
| 1016 |
| 1017 #include "SkTRegistry.h" |
| 1018 |
| 1019 static SkImageDecoder* sk_libjpeg_dfactory(SkStream* stream) { |
| 1020 if (is_jpeg(stream)) { |
| 1021 return SkNEW(SkJPEGImageDecoder); |
| 1022 } |
| 1023 return NULL; |
| 1024 } |
| 1025 |
| 1026 static SkImageDecoder::Format get_format_jpeg(SkStream* stream) { |
| 1027 if (is_jpeg(stream)) { |
| 1028 return SkImageDecoder::kJPEG_Format; |
| 1029 } |
| 1030 return SkImageDecoder::kUnknown_Format; |
| 1017 } | 1031 } |
| 1018 | 1032 |
| 1019 static SkImageEncoder* sk_libjpeg_efactory(SkImageEncoder::Type t) { | 1033 static SkImageEncoder* sk_libjpeg_efactory(SkImageEncoder::Type t) { |
| 1020 return (SkImageEncoder::kJPEG_Type == t) ? SkNEW(SkJPEGImageEncoder) : NULL; | 1034 return (SkImageEncoder::kJPEG_Type == t) ? SkNEW(SkJPEGImageEncoder) : NULL; |
| 1021 } | 1035 } |
| 1022 | 1036 |
| 1023 | 1037 |
| 1024 static SkTRegistry<SkImageDecoder*, SkStream*> gDReg(sk_libjpeg_dfactory); | 1038 static SkTRegistry<SkImageDecoder*, SkStream*> gDReg(sk_libjpeg_dfactory); |
| 1039 static SkTRegistry<SkImageDecoder::Format, SkStream*> gFormatReg(get_format_jpeg
); |
| 1025 static SkTRegistry<SkImageEncoder*, SkImageEncoder::Type> gEReg(sk_libjpeg_efact
ory); | 1040 static SkTRegistry<SkImageEncoder*, SkImageEncoder::Type> gEReg(sk_libjpeg_efact
ory); |
| OLD | NEW |