| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2013 The Android Open Source Project | 2 * Copyright 2013 The Android Open Source Project |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "SkErrorInternals.h" | 8 #include "SkErrorInternals.h" |
| 9 #include "SkImageDecoder.h" | 9 #include "SkImageDecoder.h" |
| 10 #include "SkStream.h" | 10 #include "SkStream.h" |
| 11 #include "SkTRegistry.h" | 11 #include "SkTRegistry.h" |
| 12 | 12 |
| 13 // This file is used for registration of SkImageDecoders. It also holds a functi
on | 13 // This file is used for registration of SkImageDecoders. It also holds a functi
on |
| 14 // for checking all the the registered SkImageDecoders for one that matches an | 14 // for checking all the the registered SkImageDecoders for one that matches an |
| 15 // input SkStreamRewindable. | 15 // input SkStreamRewindable. |
| 16 | 16 |
| 17 template SkImageDecoder_DecodeReg* SkImageDecoder_DecodeReg::gHead; | 17 template SkImageDecoder_DecodeReg* SkImageDecoder_DecodeReg::gHead; |
| 18 | 18 |
| 19 SkImageDecoder* image_decoder_from_stream(SkStreamRewindable*); | 19 SkImageDecoder* image_decoder_from_stream(SkStreamRewindable*); |
| 20 | 20 |
| 21 SkImageDecoder* image_decoder_from_stream(SkStreamRewindable* stream) { | 21 SkImageDecoder* image_decoder_from_stream(SkStreamRewindable* stream) { |
| 22 SkImageDecoder* codec = NULL; | 22 SkImageDecoder* codec = nullptr; |
| 23 const SkImageDecoder_DecodeReg* curr = SkImageDecoder_DecodeReg::Head(); | 23 const SkImageDecoder_DecodeReg* curr = SkImageDecoder_DecodeReg::Head(); |
| 24 while (curr) { | 24 while (curr) { |
| 25 codec = curr->factory()(stream); | 25 codec = curr->factory()(stream); |
| 26 // we rewind here, because we promise later when we call "decode", that | 26 // we rewind here, because we promise later when we call "decode", that |
| 27 // the stream will be at its beginning. | 27 // the stream will be at its beginning. |
| 28 bool rewindSuceeded = stream->rewind(); | 28 bool rewindSuceeded = stream->rewind(); |
| 29 | 29 |
| 30 // our image decoder's require that rewind is supported so we fail early | 30 // our image decoder's require that rewind is supported so we fail early |
| 31 // if we are given a stream that does not support rewinding. | 31 // if we are given a stream that does not support rewinding. |
| 32 if (!rewindSuceeded) { | 32 if (!rewindSuceeded) { |
| 33 SkDEBUGF(("Unable to rewind the image stream.")); | 33 SkDEBUGF(("Unable to rewind the image stream.")); |
| 34 delete codec; | 34 delete codec; |
| 35 return NULL; | 35 return nullptr; |
| 36 } | 36 } |
| 37 | 37 |
| 38 if (codec) { | 38 if (codec) { |
| 39 return codec; | 39 return codec; |
| 40 } | 40 } |
| 41 curr = curr->next(); | 41 curr = curr->next(); |
| 42 } | 42 } |
| 43 return NULL; | 43 return nullptr; |
| 44 } | 44 } |
| 45 | 45 |
| 46 template SkImageDecoder_FormatReg* SkImageDecoder_FormatReg::gHead; | 46 template SkImageDecoder_FormatReg* SkImageDecoder_FormatReg::gHead; |
| 47 | 47 |
| 48 SkImageDecoder::Format SkImageDecoder::GetStreamFormat(SkStreamRewindable* strea
m) { | 48 SkImageDecoder::Format SkImageDecoder::GetStreamFormat(SkStreamRewindable* strea
m) { |
| 49 const SkImageDecoder_FormatReg* curr = SkImageDecoder_FormatReg::Head(); | 49 const SkImageDecoder_FormatReg* curr = SkImageDecoder_FormatReg::Head(); |
| 50 while (curr != NULL) { | 50 while (curr != nullptr) { |
| 51 Format format = curr->factory()(stream); | 51 Format format = curr->factory()(stream); |
| 52 if (!stream->rewind()) { | 52 if (!stream->rewind()) { |
| 53 SkErrorInternals::SetError(kInvalidOperation_SkError, | 53 SkErrorInternals::SetError(kInvalidOperation_SkError, |
| 54 "Unable to rewind the image stream\n"); | 54 "Unable to rewind the image stream\n"); |
| 55 return kUnknown_Format; | 55 return kUnknown_Format; |
| 56 } | 56 } |
| 57 if (format != kUnknown_Format) { | 57 if (format != kUnknown_Format) { |
| 58 return format; | 58 return format; |
| 59 } | 59 } |
| 60 curr = curr->next(); | 60 curr = curr->next(); |
| 61 } | 61 } |
| 62 return kUnknown_Format; | 62 return kUnknown_Format; |
| 63 } | 63 } |
| OLD | NEW |