1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/skia/trunk/src/core/SkBitmapProcState_sample.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,248 @@ 1.4 + 1.5 +/* 1.6 + * Copyright 2011 Google Inc. 1.7 + * 1.8 + * Use of this source code is governed by a BSD-style license that can be 1.9 + * found in the LICENSE file. 1.10 + */ 1.11 +#include "SkUtils.h" 1.12 + 1.13 +#if DSTSIZE==32 1.14 + #define DSTTYPE SkPMColor 1.15 +#elif DSTSIZE==16 1.16 + #define DSTTYPE uint16_t 1.17 +#else 1.18 + #error "need DSTSIZE to be 32 or 16" 1.19 +#endif 1.20 + 1.21 +#if (DSTSIZE == 32) 1.22 + #define BITMAPPROC_MEMSET(ptr, value, n) sk_memset32(ptr, value, n) 1.23 +#elif (DSTSIZE == 16) 1.24 + #define BITMAPPROC_MEMSET(ptr, value, n) sk_memset16(ptr, value, n) 1.25 +#else 1.26 + #error "unsupported DSTSIZE" 1.27 +#endif 1.28 + 1.29 + 1.30 +// declare functions externally to suppress warnings. 1.31 +void MAKENAME(_nofilter_DXDY)(const SkBitmapProcState& s, 1.32 + const uint32_t* SK_RESTRICT xy, 1.33 + int count, DSTTYPE* SK_RESTRICT colors); 1.34 +void MAKENAME(_nofilter_DX)(const SkBitmapProcState& s, 1.35 + const uint32_t* SK_RESTRICT xy, 1.36 + int count, DSTTYPE* SK_RESTRICT colors); 1.37 +void MAKENAME(_filter_DX)(const SkBitmapProcState& s, 1.38 + const uint32_t* SK_RESTRICT xy, 1.39 + int count, DSTTYPE* SK_RESTRICT colors); 1.40 +void MAKENAME(_filter_DXDY)(const SkBitmapProcState& s, 1.41 + const uint32_t* SK_RESTRICT xy, 1.42 + int count, DSTTYPE* SK_RESTRICT colors); 1.43 + 1.44 +void MAKENAME(_nofilter_DXDY)(const SkBitmapProcState& s, 1.45 + const uint32_t* SK_RESTRICT xy, 1.46 + int count, DSTTYPE* SK_RESTRICT colors) { 1.47 + SkASSERT(count > 0 && colors != NULL); 1.48 + SkASSERT(SkPaint::kNone_FilterLevel == s.fFilterLevel); 1.49 + SkDEBUGCODE(CHECKSTATE(s);) 1.50 + 1.51 +#ifdef PREAMBLE 1.52 + PREAMBLE(s); 1.53 +#endif 1.54 + const char* SK_RESTRICT srcAddr = (const char*)s.fBitmap->getPixels(); 1.55 + size_t rb = s.fBitmap->rowBytes(); 1.56 + 1.57 + uint32_t XY; 1.58 + SRCTYPE src; 1.59 + 1.60 + for (int i = (count >> 1); i > 0; --i) { 1.61 + XY = *xy++; 1.62 + SkASSERT((XY >> 16) < (unsigned)s.fBitmap->height() && 1.63 + (XY & 0xFFFF) < (unsigned)s.fBitmap->width()); 1.64 + src = ((const SRCTYPE*)(srcAddr + (XY >> 16) * rb))[XY & 0xFFFF]; 1.65 + *colors++ = RETURNDST(src); 1.66 + 1.67 + XY = *xy++; 1.68 + SkASSERT((XY >> 16) < (unsigned)s.fBitmap->height() && 1.69 + (XY & 0xFFFF) < (unsigned)s.fBitmap->width()); 1.70 + src = ((const SRCTYPE*)(srcAddr + (XY >> 16) * rb))[XY & 0xFFFF]; 1.71 + *colors++ = RETURNDST(src); 1.72 + } 1.73 + if (count & 1) { 1.74 + XY = *xy++; 1.75 + SkASSERT((XY >> 16) < (unsigned)s.fBitmap->height() && 1.76 + (XY & 0xFFFF) < (unsigned)s.fBitmap->width()); 1.77 + src = ((const SRCTYPE*)(srcAddr + (XY >> 16) * rb))[XY & 0xFFFF]; 1.78 + *colors++ = RETURNDST(src); 1.79 + } 1.80 + 1.81 +#ifdef POSTAMBLE 1.82 + POSTAMBLE(s); 1.83 +#endif 1.84 +} 1.85 + 1.86 +void MAKENAME(_nofilter_DX)(const SkBitmapProcState& s, 1.87 + const uint32_t* SK_RESTRICT xy, 1.88 + int count, DSTTYPE* SK_RESTRICT colors) { 1.89 + SkASSERT(count > 0 && colors != NULL); 1.90 + SkASSERT(s.fInvType <= (SkMatrix::kTranslate_Mask | SkMatrix::kScale_Mask)); 1.91 + SkASSERT(SkPaint::kNone_FilterLevel == s.fFilterLevel); 1.92 + SkDEBUGCODE(CHECKSTATE(s);) 1.93 + 1.94 +#ifdef PREAMBLE 1.95 + PREAMBLE(s); 1.96 +#endif 1.97 + const SRCTYPE* SK_RESTRICT srcAddr = (const SRCTYPE*)s.fBitmap->getPixels(); 1.98 + 1.99 + // buffer is y32, x16, x16, x16, x16, x16 1.100 + // bump srcAddr to the proper row, since we're told Y never changes 1.101 + SkASSERT((unsigned)xy[0] < (unsigned)s.fBitmap->height()); 1.102 + srcAddr = (const SRCTYPE*)((const char*)srcAddr + 1.103 + xy[0] * s.fBitmap->rowBytes()); 1.104 + xy += 1; 1.105 + 1.106 + SRCTYPE src; 1.107 + 1.108 + if (1 == s.fBitmap->width()) { 1.109 + src = srcAddr[0]; 1.110 + DSTTYPE dstValue = RETURNDST(src); 1.111 + BITMAPPROC_MEMSET(colors, dstValue, count); 1.112 + } else { 1.113 + int i; 1.114 + for (i = (count >> 2); i > 0; --i) { 1.115 + uint32_t xx0 = *xy++; 1.116 + uint32_t xx1 = *xy++; 1.117 + SRCTYPE x0 = srcAddr[UNPACK_PRIMARY_SHORT(xx0)]; 1.118 + SRCTYPE x1 = srcAddr[UNPACK_SECONDARY_SHORT(xx0)]; 1.119 + SRCTYPE x2 = srcAddr[UNPACK_PRIMARY_SHORT(xx1)]; 1.120 + SRCTYPE x3 = srcAddr[UNPACK_SECONDARY_SHORT(xx1)]; 1.121 + 1.122 + *colors++ = RETURNDST(x0); 1.123 + *colors++ = RETURNDST(x1); 1.124 + *colors++ = RETURNDST(x2); 1.125 + *colors++ = RETURNDST(x3); 1.126 + } 1.127 + const uint16_t* SK_RESTRICT xx = (const uint16_t*)(xy); 1.128 + for (i = (count & 3); i > 0; --i) { 1.129 + SkASSERT(*xx < (unsigned)s.fBitmap->width()); 1.130 + src = srcAddr[*xx++]; *colors++ = RETURNDST(src); 1.131 + } 1.132 + } 1.133 + 1.134 +#ifdef POSTAMBLE 1.135 + POSTAMBLE(s); 1.136 +#endif 1.137 +} 1.138 + 1.139 +/////////////////////////////////////////////////////////////////////////////// 1.140 + 1.141 +void MAKENAME(_filter_DX)(const SkBitmapProcState& s, 1.142 + const uint32_t* SK_RESTRICT xy, 1.143 + int count, DSTTYPE* SK_RESTRICT colors) { 1.144 + SkASSERT(count > 0 && colors != NULL); 1.145 + SkASSERT(s.fFilterLevel != SkPaint::kNone_FilterLevel); 1.146 + SkDEBUGCODE(CHECKSTATE(s);) 1.147 + 1.148 +#ifdef PREAMBLE 1.149 + PREAMBLE(s); 1.150 +#endif 1.151 + const char* SK_RESTRICT srcAddr = (const char*)s.fBitmap->getPixels(); 1.152 + size_t rb = s.fBitmap->rowBytes(); 1.153 + unsigned subY; 1.154 + const SRCTYPE* SK_RESTRICT row0; 1.155 + const SRCTYPE* SK_RESTRICT row1; 1.156 + 1.157 + // setup row ptrs and update proc_table 1.158 + { 1.159 + uint32_t XY = *xy++; 1.160 + unsigned y0 = XY >> 14; 1.161 + row0 = (const SRCTYPE*)(srcAddr + (y0 >> 4) * rb); 1.162 + row1 = (const SRCTYPE*)(srcAddr + (XY & 0x3FFF) * rb); 1.163 + subY = y0 & 0xF; 1.164 + } 1.165 + 1.166 + do { 1.167 + uint32_t XX = *xy++; // x0:14 | 4 | x1:14 1.168 + unsigned x0 = XX >> 14; 1.169 + unsigned x1 = XX & 0x3FFF; 1.170 + unsigned subX = x0 & 0xF; 1.171 + x0 >>= 4; 1.172 + 1.173 + FILTER_PROC(subX, subY, 1.174 + SRC_TO_FILTER(row0[x0]), 1.175 + SRC_TO_FILTER(row0[x1]), 1.176 + SRC_TO_FILTER(row1[x0]), 1.177 + SRC_TO_FILTER(row1[x1]), 1.178 + colors); 1.179 + colors += 1; 1.180 + 1.181 + } while (--count != 0); 1.182 + 1.183 +#ifdef POSTAMBLE 1.184 + POSTAMBLE(s); 1.185 +#endif 1.186 +} 1.187 +void MAKENAME(_filter_DXDY)(const SkBitmapProcState& s, 1.188 + const uint32_t* SK_RESTRICT xy, 1.189 + int count, DSTTYPE* SK_RESTRICT colors) { 1.190 + SkASSERT(count > 0 && colors != NULL); 1.191 + SkASSERT(s.fFilterLevel != SkPaint::kNone_FilterLevel); 1.192 + SkDEBUGCODE(CHECKSTATE(s);) 1.193 + 1.194 +#ifdef PREAMBLE 1.195 + PREAMBLE(s); 1.196 +#endif 1.197 + const char* SK_RESTRICT srcAddr = (const char*)s.fBitmap->getPixels(); 1.198 + size_t rb = s.fBitmap->rowBytes(); 1.199 + 1.200 + do { 1.201 + uint32_t data = *xy++; 1.202 + unsigned y0 = data >> 14; 1.203 + unsigned y1 = data & 0x3FFF; 1.204 + unsigned subY = y0 & 0xF; 1.205 + y0 >>= 4; 1.206 + 1.207 + data = *xy++; 1.208 + unsigned x0 = data >> 14; 1.209 + unsigned x1 = data & 0x3FFF; 1.210 + unsigned subX = x0 & 0xF; 1.211 + x0 >>= 4; 1.212 + 1.213 + const SRCTYPE* SK_RESTRICT row0 = (const SRCTYPE*)(srcAddr + y0 * rb); 1.214 + const SRCTYPE* SK_RESTRICT row1 = (const SRCTYPE*)(srcAddr + y1 * rb); 1.215 + 1.216 + FILTER_PROC(subX, subY, 1.217 + SRC_TO_FILTER(row0[x0]), 1.218 + SRC_TO_FILTER(row0[x1]), 1.219 + SRC_TO_FILTER(row1[x0]), 1.220 + SRC_TO_FILTER(row1[x1]), 1.221 + colors); 1.222 + colors += 1; 1.223 + } while (--count != 0); 1.224 + 1.225 +#ifdef POSTAMBLE 1.226 + POSTAMBLE(s); 1.227 +#endif 1.228 +} 1.229 + 1.230 +#undef MAKENAME 1.231 +#undef DSTSIZE 1.232 +#undef DSTTYPE 1.233 +#undef SRCTYPE 1.234 +#undef CHECKSTATE 1.235 +#undef RETURNDST 1.236 +#undef SRC_TO_FILTER 1.237 +#undef FILTER_TO_DST 1.238 + 1.239 +#ifdef PREAMBLE 1.240 + #undef PREAMBLE 1.241 +#endif 1.242 +#ifdef POSTAMBLE 1.243 + #undef POSTAMBLE 1.244 +#endif 1.245 + 1.246 +#undef FILTER_PROC_TYPE 1.247 +#undef GET_FILTER_TABLE 1.248 +#undef GET_FILTER_ROW 1.249 +#undef GET_FILTER_ROW_PROC 1.250 +#undef GET_FILTER_PROC 1.251 +#undef BITMAPPROC_MEMSET