gfx/skia/trunk/src/images/transform_scanline.h

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
-rw-r--r--

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 /*
michael@0 3 * Copyright 2012 The Android Open Source Project
michael@0 4 *
michael@0 5 * Use of this source code is governed by a BSD-style license that can be
michael@0 6 * found in the LICENSE file.
michael@0 7 */
michael@0 8
michael@0 9 /**
michael@0 10 * Functions to transform scanlines between packed-pixel formats.
michael@0 11 */
michael@0 12
michael@0 13 #include "SkBitmap.h"
michael@0 14 #include "SkColor.h"
michael@0 15 #include "SkColorPriv.h"
michael@0 16 #include "SkPreConfig.h"
michael@0 17 #include "SkUnPreMultiply.h"
michael@0 18
michael@0 19 /**
michael@0 20 * Function template for transforming scanlines.
michael@0 21 * Transform 'width' pixels from 'src' buffer into 'dst' buffer,
michael@0 22 * repacking color channel data as appropriate for the given transformation.
michael@0 23 */
michael@0 24 typedef void (*transform_scanline_proc)(const char* SK_RESTRICT src,
michael@0 25 int width, char* SK_RESTRICT dst);
michael@0 26
michael@0 27 /**
michael@0 28 * Identity transformation: just copy bytes from src to dst.
michael@0 29 */
michael@0 30 static void transform_scanline_memcpy(const char* SK_RESTRICT src, int width,
michael@0 31 char* SK_RESTRICT dst) {
michael@0 32 memcpy(dst, src, width);
michael@0 33 }
michael@0 34
michael@0 35 /**
michael@0 36 * Transform from kRGB_565_Config to 3-bytes-per-pixel RGB.
michael@0 37 * Alpha channel data is not present in kRGB_565_Config format, so there is no
michael@0 38 * alpha channel data to preserve.
michael@0 39 */
michael@0 40 static void transform_scanline_565(const char* SK_RESTRICT src, int width,
michael@0 41 char* SK_RESTRICT dst) {
michael@0 42 const uint16_t* SK_RESTRICT srcP = (const uint16_t*)src;
michael@0 43 for (int i = 0; i < width; i++) {
michael@0 44 unsigned c = *srcP++;
michael@0 45 *dst++ = SkPacked16ToR32(c);
michael@0 46 *dst++ = SkPacked16ToG32(c);
michael@0 47 *dst++ = SkPacked16ToB32(c);
michael@0 48 }
michael@0 49 }
michael@0 50
michael@0 51 /**
michael@0 52 * Transform from kARGB_8888_Config to 3-bytes-per-pixel RGB.
michael@0 53 * Alpha channel data, if any, is abandoned.
michael@0 54 */
michael@0 55 static void transform_scanline_888(const char* SK_RESTRICT src, int width,
michael@0 56 char* SK_RESTRICT dst) {
michael@0 57 const SkPMColor* SK_RESTRICT srcP = (const SkPMColor*)src;
michael@0 58 for (int i = 0; i < width; i++) {
michael@0 59 SkPMColor c = *srcP++;
michael@0 60 *dst++ = SkGetPackedR32(c);
michael@0 61 *dst++ = SkGetPackedG32(c);
michael@0 62 *dst++ = SkGetPackedB32(c);
michael@0 63 }
michael@0 64 }
michael@0 65
michael@0 66 /**
michael@0 67 * Transform from kARGB_4444_Config to 3-bytes-per-pixel RGB.
michael@0 68 * Alpha channel data, if any, is abandoned.
michael@0 69 */
michael@0 70 static void transform_scanline_444(const char* SK_RESTRICT src, int width,
michael@0 71 char* SK_RESTRICT dst) {
michael@0 72 const SkPMColor16* SK_RESTRICT srcP = (const SkPMColor16*)src;
michael@0 73 for (int i = 0; i < width; i++) {
michael@0 74 SkPMColor16 c = *srcP++;
michael@0 75 *dst++ = SkPacked4444ToR32(c);
michael@0 76 *dst++ = SkPacked4444ToG32(c);
michael@0 77 *dst++ = SkPacked4444ToB32(c);
michael@0 78 }
michael@0 79 }
michael@0 80
michael@0 81 /**
michael@0 82 * Transform from kARGB_8888_Config to 4-bytes-per-pixel RGBA.
michael@0 83 * (This would be the identity transformation, except for byte-order and
michael@0 84 * scaling of RGB based on alpha channel).
michael@0 85 */
michael@0 86 static void transform_scanline_8888(const char* SK_RESTRICT src, int width,
michael@0 87 char* SK_RESTRICT dst) {
michael@0 88 const SkPMColor* SK_RESTRICT srcP = (const SkPMColor*)src;
michael@0 89 const SkUnPreMultiply::Scale* SK_RESTRICT table =
michael@0 90 SkUnPreMultiply::GetScaleTable();
michael@0 91
michael@0 92 for (int i = 0; i < width; i++) {
michael@0 93 SkPMColor c = *srcP++;
michael@0 94 unsigned a = SkGetPackedA32(c);
michael@0 95 unsigned r = SkGetPackedR32(c);
michael@0 96 unsigned g = SkGetPackedG32(c);
michael@0 97 unsigned b = SkGetPackedB32(c);
michael@0 98
michael@0 99 if (0 != a && 255 != a) {
michael@0 100 SkUnPreMultiply::Scale scale = table[a];
michael@0 101 r = SkUnPreMultiply::ApplyScale(scale, r);
michael@0 102 g = SkUnPreMultiply::ApplyScale(scale, g);
michael@0 103 b = SkUnPreMultiply::ApplyScale(scale, b);
michael@0 104 }
michael@0 105 *dst++ = r;
michael@0 106 *dst++ = g;
michael@0 107 *dst++ = b;
michael@0 108 *dst++ = a;
michael@0 109 }
michael@0 110 }
michael@0 111
michael@0 112 /**
michael@0 113 * Transform from kARGB_8888_Config to 4-bytes-per-pixel RGBA,
michael@0 114 * with scaling of RGB based on alpha channel.
michael@0 115 */
michael@0 116 static void transform_scanline_4444(const char* SK_RESTRICT src, int width,
michael@0 117 char* SK_RESTRICT dst) {
michael@0 118 const SkPMColor16* SK_RESTRICT srcP = (const SkPMColor16*)src;
michael@0 119 const SkUnPreMultiply::Scale* SK_RESTRICT table =
michael@0 120 SkUnPreMultiply::GetScaleTable();
michael@0 121
michael@0 122 for (int i = 0; i < width; i++) {
michael@0 123 SkPMColor16 c = *srcP++;
michael@0 124 unsigned a = SkPacked4444ToA32(c);
michael@0 125 unsigned r = SkPacked4444ToR32(c);
michael@0 126 unsigned g = SkPacked4444ToG32(c);
michael@0 127 unsigned b = SkPacked4444ToB32(c);
michael@0 128
michael@0 129 if (0 != a && 255 != a) {
michael@0 130 SkUnPreMultiply::Scale scale = table[a];
michael@0 131 r = SkUnPreMultiply::ApplyScale(scale, r);
michael@0 132 g = SkUnPreMultiply::ApplyScale(scale, g);
michael@0 133 b = SkUnPreMultiply::ApplyScale(scale, b);
michael@0 134 }
michael@0 135 *dst++ = r;
michael@0 136 *dst++ = g;
michael@0 137 *dst++ = b;
michael@0 138 *dst++ = a;
michael@0 139 }
michael@0 140 }

mercurial