michael@0: /* michael@0: * Copyright 2010 Google Inc. michael@0: * michael@0: * Use of this source code is governed by a BSD-style license that can be michael@0: * found in the LICENSE file. michael@0: */ michael@0: michael@0: #import michael@0: #include michael@0: #import michael@0: michael@0: #include "SkImageDecoder.h" michael@0: #include "SkImageEncoder.h" michael@0: #include "SkMovie.h" michael@0: #include "SkStream_NSData.h" michael@0: michael@0: class SkImageDecoder_iOS : public SkImageDecoder { michael@0: protected: michael@0: virtual bool onDecode(SkStream* stream, SkBitmap* bm, Mode); michael@0: }; michael@0: michael@0: #define BITMAP_INFO (kCGBitmapByteOrder32Big | kCGImageAlphaPremultipliedLast) michael@0: michael@0: bool SkImageDecoder_iOS::onDecode(SkStream* stream, SkBitmap* bm, Mode mode) { michael@0: michael@0: NSData* data = NSData_dataWithStream(stream); michael@0: michael@0: UIImage* uimage = [UIImage imageWithData:data]; michael@0: michael@0: const int width = uimage.size.width; michael@0: const int height = uimage.size.height; michael@0: bm->setConfig(SkBitmap::kARGB_8888_Config, width, height); michael@0: if (SkImageDecoder::kDecodeBounds_Mode == mode) { michael@0: return true; michael@0: } michael@0: michael@0: if (!this->allocPixelRef(bm, NULL)) { michael@0: return false; michael@0: } michael@0: michael@0: bm->lockPixels(); michael@0: bm->eraseColor(0); michael@0: michael@0: CGColorSpaceRef cs = CGColorSpaceCreateDeviceRGB(); michael@0: CGContextRef cg = CGBitmapContextCreate(bm->getPixels(), width, height, michael@0: 8, bm->rowBytes(), cs, BITMAP_INFO); michael@0: CGContextDrawImage(cg, CGRectMake(0, 0, width, height), uimage.CGImage); michael@0: CGContextRelease(cg); michael@0: CGColorSpaceRelease(cs); michael@0: michael@0: bm->unlockPixels(); michael@0: return true; michael@0: } michael@0: michael@0: ///////////////////////////////////////////////////////////////////////// michael@0: michael@0: SkImageDecoder* SkImageDecoder::Factory(SkStreamRewindable* stream) { michael@0: return new SkImageDecoder_iOS; michael@0: } michael@0: michael@0: SkMovie* SkMovie::DecodeStream(SkStreamRewindable* stream) { michael@0: return NULL; michael@0: } michael@0: michael@0: SkImageEncoder* SkImageEncoder::Create(Type t) { michael@0: return NULL; michael@0: } michael@0: