aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/images/SkImageEncoder_Factory.cpp
blob: 2bd1113f7c9512dee48b2d53553e14d4d22baffa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37

/*
 * Copyright 2009 The Android Open Source Project
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */


#include "SkImageEncoder.h"
#include "SkTRegistry.h"

typedef SkTRegistry<SkImageEncoder*, SkImageEncoder::Type> EncodeReg;

// Can't use the typedef here because of complex C++ corner cases
template EncodeReg* SkTRegistry<SkImageEncoder*, SkImageEncoder::Type>::gHead;

#ifdef SK_ENABLE_LIBPNG
    extern SkImageEncoder* sk_libpng_efactory(SkImageEncoder::Type);
#endif

SkImageEncoder* SkImageEncoder::Create(Type t) {
    SkImageEncoder* codec = NULL;
    const EncodeReg* curr = EncodeReg::Head();
    while (curr) {
        if ((codec = curr->factory()(t)) != NULL) {
            return codec;
        }
        curr = curr->next();
    }
#ifdef SK_ENABLE_LIBPNG
    if ((codec = sk_libpng_efactory(t)) != NULL) {
        return codec;
    }
#endif
    return NULL;
}