blob: 2bd1113f7c9512dee48b2d53553e14d4d22baffa [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
reed@android.comb08eb2b2009-01-06 20:16:26 +00002/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00003 * Copyright 2009 The Android Open Source Project
reed@android.comb08eb2b2009-01-06 20:16:26 +00004 *
epoger@google.comec3ed6a2011-07-28 14:26:00 +00005 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
reed@android.comb08eb2b2009-01-06 20:16:26 +00007 */
8
epoger@google.comec3ed6a2011-07-28 14:26:00 +00009
reed@android.comb08eb2b2009-01-06 20:16:26 +000010#include "SkImageEncoder.h"
reed@android.com00bf85a2009-01-22 13:04:56 +000011#include "SkTRegistry.h"
reed@android.comb08eb2b2009-01-06 20:16:26 +000012
reed@android.com00bf85a2009-01-22 13:04:56 +000013typedef SkTRegistry<SkImageEncoder*, SkImageEncoder::Type> EncodeReg;
reed@android.comb08eb2b2009-01-06 20:16:26 +000014
tomhudson@google.coma87cd2a2011-06-15 16:50:27 +000015// Can't use the typedef here because of complex C++ corner cases
16template EncodeReg* SkTRegistry<SkImageEncoder*, SkImageEncoder::Type>::gHead;
reed@android.com3c2b7e82009-01-27 01:43:36 +000017
reed@android.comdfee5792010-04-15 14:24:50 +000018#ifdef SK_ENABLE_LIBPNG
19 extern SkImageEncoder* sk_libpng_efactory(SkImageEncoder::Type);
20#endif
21
reed@android.comb08eb2b2009-01-06 20:16:26 +000022SkImageEncoder* SkImageEncoder::Create(Type t) {
reed@android.comdfee5792010-04-15 14:24:50 +000023 SkImageEncoder* codec = NULL;
reed@android.com00bf85a2009-01-22 13:04:56 +000024 const EncodeReg* curr = EncodeReg::Head();
25 while (curr) {
reed@android.comdfee5792010-04-15 14:24:50 +000026 if ((codec = curr->factory()(t)) != NULL) {
reed@android.com00bf85a2009-01-22 13:04:56 +000027 return codec;
28 }
29 curr = curr->next();
reed@android.comb08eb2b2009-01-06 20:16:26 +000030 }
reed@android.comdfee5792010-04-15 14:24:50 +000031#ifdef SK_ENABLE_LIBPNG
32 if ((codec = sk_libpng_efactory(t)) != NULL) {
33 return codec;
34 }
35#endif
reed@android.com00bf85a2009-01-22 13:04:56 +000036 return NULL;
reed@android.comb08eb2b2009-01-06 20:16:26 +000037}