PageRenderTime 16ms CodeModel.GetById 7ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 1ms

/src/canvas/skia/ftk_bitmap_factory_skia.cpp

http://ftk.googlecode.com/
C++ | 120 lines | 71 code | 20 blank | 29 comment | 5 complexity | b2f269a8c44c4ae093192e3c3f1282da MD5 | raw file
  1/*
  2 * File: ftk_bitmap_factory.c    
  3 * Author:  Li XianJing <xianjimli@hotmail.com>
  4 * Brief:   bitmap factory.
  5 *
  6 * Copyright (c) 2009 - 2010  Li XianJing <xianjimli@hotmail.com>
  7 *
  8 * Licensed under the Academic Free License version 2.1
  9 *
 10 * This program is free software; you can redistribute it and/or modify
 11 * it under the terms of the GNU General Public License as published by
 12 * the Free Software Foundation; either version 2 of the License, or
 13 * (at your option) any later version.
 14 *
 15 * This program is distributed in the hope that it will be useful,
 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 18 * GNU General Public License for more details.
 19 *
 20 * You should have received a copy of the GNU General Public License
 21 * along with this program; if not, write to the Free Software
 22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 23 */
 24
 25/*
 26 * History:
 27 * ================================================================
 28 * 2009-10-03 Li XianJing <xianjimli@hotmail.com> created
 29 *
 30 */
 31#include "SkString.h"
 32#include "SkBitmap.h"
 33#include "SkColor.h"
 34#include "SkStream.h"
 35#include "SkTemplates.h"
 36#include "images/SkImageDecoder.h"
 37#include "effects/SkPorterDuff.h"
 38
 39#include "ftk_log.h"
 40#include "ftk_allocator.h"
 41#include "ftk_bitmap_factory.h"
 42
 43#ifdef ANDROID
 44using namespace android;
 45#include "ftk_jni.h"
 46#endif
 47
 48struct _FtkBitmapFactory
 49{
 50	int unused;
 51};
 52
 53FtkBitmapFactory* ftk_bitmap_factory_create(void)
 54{
 55	FtkBitmapFactory* thiz = (FtkBitmapFactory*)FTK_ZALLOC(sizeof(FtkBitmapFactory));
 56
 57	return thiz;
 58}
 59
 60static bool decodeFile(SkBitmap* bitmap, const char srcPath[]) {
 61    
 62    SkFILEStream stream(srcPath);
 63    if (!stream.isValid()) {
 64        SkDebugf("ERROR: bad filename <%s>\n", srcPath);
 65        return false;
 66    }
 67
 68    SkImageDecoder* codec = SkImageDecoder::Factory(&stream);
 69    if (NULL == codec) {
 70        SkDebugf("ERROR: no codec found for <%s>\n", srcPath);
 71        return false;
 72    }
 73
 74    SkAutoTDelete<SkImageDecoder> ad(codec);
 75
 76    stream.rewind();
 77    if (!codec->decode(&stream, bitmap, SkBitmap::kARGB_8888_Config,
 78                       SkImageDecoder::kDecodePixels_Mode)) {
 79        SkDebugf("ERROR: codec failed for <%s>\n", srcPath);
 80        return false;
 81    }
 82    return true;
 83}
 84
 85static void destroy_bitmap(void* data)
 86{
 87	SkBitmap* b = (SkBitmap*)data;
 88
 89	delete b;
 90
 91	return;
 92}
 93
 94FtkBitmap* ftk_bitmap_factory_load(FtkBitmapFactory* thiz, const char* filename)
 95{	
 96#ifdef ANDROID
 97	return Android_LoadImage(filename);
 98#else
 99	SkBitmap* b = new SkBitmap();
100	FtkBitmap* bmp = NULL;
101
102	if (decodeFile(b, filename)) 
103	{
104		bmp = ftk_bitmap_create_with_native(b);
105	}
106
107	return bmp;
108#endif
109}
110
111Ret        ftk_bitmap_factory_add_decoder(FtkBitmapFactory* thiz, FtkImageDecoder* decoder)
112{
113	return RET_OK;
114}
115
116void       ftk_bitmap_factory_destroy(FtkBitmapFactory* thiz)
117{
118	return;
119}
120