michael@0: /* michael@0: * Copyright 2008, The Android Open Source Project michael@0: * michael@0: * Redistribution and use in source and binary forms, with or without michael@0: * modification, are permitted provided that the following conditions michael@0: * are met: michael@0: * * Redistributions of source code must retain the above copyright michael@0: * notice, this list of conditions and the following disclaimer. michael@0: * * Redistributions in binary form must reproduce the above copyright michael@0: * notice, this list of conditions and the following disclaimer in the michael@0: * documentation and/or other materials provided with the distribution. michael@0: * michael@0: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY michael@0: * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE michael@0: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR michael@0: * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR michael@0: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, michael@0: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, michael@0: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR michael@0: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY michael@0: * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT michael@0: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE michael@0: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. michael@0: */ michael@0: michael@0: // must include config.h first for webkit to fiddle with new/delete michael@0: #include "SkANP.h" michael@0: michael@0: SkRect* SkANP::SetRect(SkRect* dst, const ANPRectF& src) { michael@0: dst->set(SkFloatToScalar(src.left), michael@0: SkFloatToScalar(src.top), michael@0: SkFloatToScalar(src.right), michael@0: SkFloatToScalar(src.bottom)); michael@0: return dst; michael@0: } michael@0: michael@0: SkIRect* SkANP::SetRect(SkIRect* dst, const ANPRectI& src) { michael@0: dst->set(src.left, src.top, src.right, src.bottom); michael@0: return dst; michael@0: } michael@0: michael@0: ANPRectI* SkANP::SetRect(ANPRectI* dst, const SkIRect& src) { michael@0: dst->left = src.fLeft; michael@0: dst->top = src.fTop; michael@0: dst->right = src.fRight; michael@0: dst->bottom = src.fBottom; michael@0: return dst; michael@0: } michael@0: michael@0: ANPRectF* SkANP::SetRect(ANPRectF* dst, const SkRect& src) { michael@0: dst->left = SkScalarToFloat(src.fLeft); michael@0: dst->top = SkScalarToFloat(src.fTop); michael@0: dst->right = SkScalarToFloat(src.fRight); michael@0: dst->bottom = SkScalarToFloat(src.fBottom); michael@0: return dst; michael@0: } michael@0: michael@0: SkBitmap* SkANP::SetBitmap(SkBitmap* dst, const ANPBitmap& src) { michael@0: SkBitmap::Config config = SkBitmap::kNo_Config; michael@0: michael@0: switch (src.format) { michael@0: case kRGBA_8888_ANPBitmapFormat: michael@0: config = SkBitmap::kARGB_8888_Config; michael@0: break; michael@0: case kRGB_565_ANPBitmapFormat: michael@0: config = SkBitmap::kRGB_565_Config; michael@0: break; michael@0: default: michael@0: break; michael@0: } michael@0: michael@0: dst->setConfig(config, src.width, src.height, src.rowBytes); michael@0: dst->setPixels(src.baseAddr); michael@0: return dst; michael@0: } michael@0: michael@0: bool SkANP::SetBitmap(ANPBitmap* dst, const SkBitmap& src) { michael@0: if (!(dst->baseAddr = src.getPixels())) { michael@0: SkDebugf("SkANP::SetBitmap - getPixels() returned null\n"); michael@0: return false; michael@0: } michael@0: michael@0: switch (src.config()) { michael@0: case SkBitmap::kARGB_8888_Config: michael@0: dst->format = kRGBA_8888_ANPBitmapFormat; michael@0: break; michael@0: case SkBitmap::kRGB_565_Config: michael@0: dst->format = kRGB_565_ANPBitmapFormat; michael@0: break; michael@0: default: michael@0: SkDebugf("SkANP::SetBitmap - unsupported src.config %d\n", src.config()); michael@0: return false; michael@0: } michael@0: michael@0: dst->width = src.width(); michael@0: dst->height = src.height(); michael@0: dst->rowBytes = src.rowBytes(); michael@0: return true; michael@0: } michael@0: michael@0: void SkANP::InitEvent(ANPEvent* event, ANPEventType et) { michael@0: event->inSize = sizeof(ANPEvent); michael@0: event->eventType = et; michael@0: }