aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/images/SkImageDecoder_FactoryRegistrar.cpp
diff options
context:
space:
mode:
authorGravatar scroggo@google.com <scroggo@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-04-25 17:33:51 +0000
committerGravatar scroggo@google.com <scroggo@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-04-25 17:33:51 +0000
commit39edf4cd94e6fbeb8c1187a588b314e9795c81e4 (patch)
treeaa4c2bd7cc99646bd18b78ad8e2988b3086edec6 /src/images/SkImageDecoder_FactoryRegistrar.cpp
parent6ef912ac43a49c5df1114b56c106e086915384c9 (diff)
Updates to skimage tool to use it for testing.
skimage_main.cpp: More changes in the interest of testing our decoders. force_all_opaque before writing PNG files. Test reencoding the image to its original type (if possible), and then test redecoding it (to make sure the encoding was successful). Add an option to turn off this behavior. Merge decodeFileAndWrite with decodeFile. SkImageDecoder: Add kUnknown_Type to SkImageEncoder::Types. Add a static function to get the Format of an SkStream. In getFormatName(), remove an incorrect assert. When calling the flavor of DecodeStream that returns the Format, check the stream if the decoder returns kUnknown_Format. BUG=https://code.google.com/p/skia/issues/detail?id=1241 Review URL: https://codereview.chromium.org/14363003 git-svn-id: http://skia.googlecode.com/svn/trunk@8862 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/images/SkImageDecoder_FactoryRegistrar.cpp')
-rw-r--r--src/images/SkImageDecoder_FactoryRegistrar.cpp22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/images/SkImageDecoder_FactoryRegistrar.cpp b/src/images/SkImageDecoder_FactoryRegistrar.cpp
index 6cc417a46f..f1eca3d03a 100644
--- a/src/images/SkImageDecoder_FactoryRegistrar.cpp
+++ b/src/images/SkImageDecoder_FactoryRegistrar.cpp
@@ -5,6 +5,7 @@
* found in the LICENSE file.
*/
+#include "SkErrorInternals.h"
#include "SkImageDecoder.h"
#include "SkStream.h"
#include "SkTRegistry.h"
@@ -45,3 +46,24 @@ SkImageDecoder* image_decoder_from_stream(SkStream* stream) {
}
return NULL;
}
+
+typedef SkTRegistry<SkImageDecoder::Format, SkStream*> FormatReg;
+
+template FormatReg* SkTRegistry<SkImageDecoder::Format, SkStream*>::gHead;
+
+SkImageDecoder::Format SkImageDecoder::GetStreamFormat(SkStream* stream) {
+ const FormatReg* curr = FormatReg::Head();
+ while (curr != NULL) {
+ Format format = curr->factory()(stream);
+ if (!stream->rewind()) {
+ SkErrorInternals::SetError(kInvalidOperation_SkError,
+ "Unable to rewind the image stream\n");
+ return kUnknown_Format;
+ }
+ if (format != kUnknown_Format) {
+ return format;
+ }
+ curr = curr->next();
+ }
+ return kUnknown_Format;
+}