gfx/skia/trunk/src/utils/ios/SkImageDecoder_iOS.mm

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rwxr-xr-x

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /*
michael@0 2 * Copyright 2010 Google Inc.
michael@0 3 *
michael@0 4 * Use of this source code is governed by a BSD-style license that can be
michael@0 5 * found in the LICENSE file.
michael@0 6 */
michael@0 7
michael@0 8 #import <CoreGraphics/CoreGraphics.h>
michael@0 9 #include <CoreGraphics/CGColorSpace.h>
michael@0 10 #import <UIKit/UIKit.h>
michael@0 11
michael@0 12 #include "SkImageDecoder.h"
michael@0 13 #include "SkImageEncoder.h"
michael@0 14 #include "SkMovie.h"
michael@0 15 #include "SkStream_NSData.h"
michael@0 16
michael@0 17 class SkImageDecoder_iOS : public SkImageDecoder {
michael@0 18 protected:
michael@0 19 virtual bool onDecode(SkStream* stream, SkBitmap* bm, Mode);
michael@0 20 };
michael@0 21
michael@0 22 #define BITMAP_INFO (kCGBitmapByteOrder32Big | kCGImageAlphaPremultipliedLast)
michael@0 23
michael@0 24 bool SkImageDecoder_iOS::onDecode(SkStream* stream, SkBitmap* bm, Mode mode) {
michael@0 25
michael@0 26 NSData* data = NSData_dataWithStream(stream);
michael@0 27
michael@0 28 UIImage* uimage = [UIImage imageWithData:data];
michael@0 29
michael@0 30 const int width = uimage.size.width;
michael@0 31 const int height = uimage.size.height;
michael@0 32 bm->setConfig(SkBitmap::kARGB_8888_Config, width, height);
michael@0 33 if (SkImageDecoder::kDecodeBounds_Mode == mode) {
michael@0 34 return true;
michael@0 35 }
michael@0 36
michael@0 37 if (!this->allocPixelRef(bm, NULL)) {
michael@0 38 return false;
michael@0 39 }
michael@0 40
michael@0 41 bm->lockPixels();
michael@0 42 bm->eraseColor(0);
michael@0 43
michael@0 44 CGColorSpaceRef cs = CGColorSpaceCreateDeviceRGB();
michael@0 45 CGContextRef cg = CGBitmapContextCreate(bm->getPixels(), width, height,
michael@0 46 8, bm->rowBytes(), cs, BITMAP_INFO);
michael@0 47 CGContextDrawImage(cg, CGRectMake(0, 0, width, height), uimage.CGImage);
michael@0 48 CGContextRelease(cg);
michael@0 49 CGColorSpaceRelease(cs);
michael@0 50
michael@0 51 bm->unlockPixels();
michael@0 52 return true;
michael@0 53 }
michael@0 54
michael@0 55 /////////////////////////////////////////////////////////////////////////
michael@0 56
michael@0 57 SkImageDecoder* SkImageDecoder::Factory(SkStreamRewindable* stream) {
michael@0 58 return new SkImageDecoder_iOS;
michael@0 59 }
michael@0 60
michael@0 61 SkMovie* SkMovie::DecodeStream(SkStreamRewindable* stream) {
michael@0 62 return NULL;
michael@0 63 }
michael@0 64
michael@0 65 SkImageEncoder* SkImageEncoder::Create(Type t) {
michael@0 66 return NULL;
michael@0 67 }
michael@0 68

mercurial