Home | History | Annotate | Download | only in core
      1 #include "SkUtils.h"
      2 
      3 #if DSTSIZE==32
      4     #define DSTTYPE SkPMColor
      5 #elif DSTSIZE==16
      6     #define DSTTYPE uint16_t
      7 #else
      8     #error "need DSTSIZE to be 32 or 16"
      9 #endif
     10 
     11 #if (DSTSIZE == 32)
     12     #define BITMAPPROC_MEMSET(ptr, value, n) sk_memset32(ptr, value, n)
     13 #elif (DSTSIZE == 16)
     14     #define BITMAPPROC_MEMSET(ptr, value, n) sk_memset16(ptr, value, n)
     15 #else
     16     #error "unsupported DSTSIZE"
     17 #endif
     18 
     19 void MAKENAME(_nofilter_DXDY)(const SkBitmapProcState& s,
     20                               const uint32_t* SK_RESTRICT xy,
     21                               int count, DSTTYPE* SK_RESTRICT colors) {
     22     SkASSERT(count > 0 && colors != NULL);
     23     SkASSERT(s.fDoFilter == false);
     24     SkDEBUGCODE(CHECKSTATE(s);)
     25 
     26 #ifdef PREAMBLE
     27     PREAMBLE(s);
     28 #endif
     29     const char* SK_RESTRICT srcAddr = (const char*)s.fBitmap->getPixels();
     30     int i, rb = s.fBitmap->rowBytes();
     31 
     32     uint32_t XY;
     33     SRCTYPE src;
     34 
     35     for (i = (count >> 1); i > 0; --i) {
     36         XY = *xy++;
     37         SkASSERT((XY >> 16) < (unsigned)s.fBitmap->height() &&
     38                  (XY & 0xFFFF) < (unsigned)s.fBitmap->width());
     39         src = ((const SRCTYPE*)(srcAddr + (XY >> 16) * rb))[XY & 0xFFFF];
     40         *colors++ = RETURNDST(src);
     41 
     42         XY = *xy++;
     43         SkASSERT((XY >> 16) < (unsigned)s.fBitmap->height() &&
     44                  (XY & 0xFFFF) < (unsigned)s.fBitmap->width());
     45         src = ((const SRCTYPE*)(srcAddr + (XY >> 16) * rb))[XY & 0xFFFF];
     46         *colors++ = RETURNDST(src);
     47     }
     48     if (count & 1) {
     49         XY = *xy++;
     50         SkASSERT((XY >> 16) < (unsigned)s.fBitmap->height() &&
     51                  (XY & 0xFFFF) < (unsigned)s.fBitmap->width());
     52         src = ((const SRCTYPE*)(srcAddr + (XY >> 16) * rb))[XY & 0xFFFF];
     53         *colors++ = RETURNDST(src);
     54     }
     55 
     56 #ifdef POSTAMBLE
     57     POSTAMBLE(s);
     58 #endif
     59 }
     60 
     61 void MAKENAME(_nofilter_DX)(const SkBitmapProcState& s,
     62                             const uint32_t* SK_RESTRICT xy,
     63                             int count, DSTTYPE* SK_RESTRICT colors) {
     64     SkASSERT(count > 0 && colors != NULL);
     65     SkASSERT(s.fInvType <= (SkMatrix::kTranslate_Mask | SkMatrix::kScale_Mask));
     66     SkASSERT(s.fDoFilter == false);
     67     SkDEBUGCODE(CHECKSTATE(s);)
     68 
     69 #ifdef PREAMBLE
     70     PREAMBLE(s);
     71 #endif
     72     const SRCTYPE* SK_RESTRICT srcAddr = (const SRCTYPE*)s.fBitmap->getPixels();
     73 
     74     // buffer is y32, x16, x16, x16, x16, x16
     75     // bump srcAddr to the proper row, since we're told Y never changes
     76     SkASSERT((unsigned)xy[0] < (unsigned)s.fBitmap->height());
     77     srcAddr = (const SRCTYPE*)((const char*)srcAddr +
     78                                                 xy[0] * s.fBitmap->rowBytes());
     79     xy += 1;
     80 
     81     SRCTYPE src;
     82 
     83     if (1 == s.fBitmap->width()) {
     84         src = srcAddr[0];
     85         DSTTYPE dstValue = RETURNDST(src);
     86         BITMAPPROC_MEMSET(colors, dstValue, count);
     87     } else {
     88         int i;
     89         for (i = (count >> 2); i > 0; --i) {
     90             uint32_t xx0 = *xy++;
     91             uint32_t xx1 = *xy++;
     92             SRCTYPE x0 = srcAddr[UNPACK_PRIMARY_SHORT(xx0)];
     93             SRCTYPE x1 = srcAddr[UNPACK_SECONDARY_SHORT(xx0)];
     94             SRCTYPE x2 = srcAddr[UNPACK_PRIMARY_SHORT(xx1)];
     95             SRCTYPE x3 = srcAddr[UNPACK_SECONDARY_SHORT(xx1)];
     96 
     97             *colors++ = RETURNDST(x0);
     98             *colors++ = RETURNDST(x1);
     99             *colors++ = RETURNDST(x2);
    100             *colors++ = RETURNDST(x3);
    101         }
    102         const uint16_t* SK_RESTRICT xx = (const uint16_t*)(xy);
    103         for (i = (count & 3); i > 0; --i) {
    104             SkASSERT(*xx < (unsigned)s.fBitmap->width());
    105             src = srcAddr[*xx++]; *colors++ = RETURNDST(src);
    106         }
    107     }
    108 
    109 #ifdef POSTAMBLE
    110     POSTAMBLE(s);
    111 #endif
    112 }
    113 
    114 ///////////////////////////////////////////////////////////////////////////////
    115 
    116 void MAKENAME(_filter_DX)(const SkBitmapProcState& s,
    117                           const uint32_t* SK_RESTRICT xy,
    118                            int count, DSTTYPE* SK_RESTRICT colors) {
    119     SkASSERT(count > 0 && colors != NULL);
    120     SkASSERT(s.fDoFilter);
    121     SkDEBUGCODE(CHECKSTATE(s);)
    122 
    123 #ifdef PREAMBLE
    124     PREAMBLE(s);
    125 #endif
    126     const char* SK_RESTRICT srcAddr = (const char*)s.fBitmap->getPixels();
    127     unsigned rb = s.fBitmap->rowBytes();
    128     unsigned subY;
    129     const SRCTYPE* SK_RESTRICT row0;
    130     const SRCTYPE* SK_RESTRICT row1;
    131 
    132     // setup row ptrs and update proc_table
    133     {
    134         uint32_t XY = *xy++;
    135         unsigned y0 = XY >> 14;
    136         row0 = (const SRCTYPE*)(srcAddr + (y0 >> 4) * rb);
    137         row1 = (const SRCTYPE*)(srcAddr + (XY & 0x3FFF) * rb);
    138         subY = y0 & 0xF;
    139     }
    140 
    141     do {
    142         uint32_t XX = *xy++;    // x0:14 | 4 | x1:14
    143         unsigned x0 = XX >> 14;
    144         unsigned x1 = XX & 0x3FFF;
    145         unsigned subX = x0 & 0xF;
    146         x0 >>= 4;
    147 
    148         FILTER_PROC(subX, subY,
    149                     SRC_TO_FILTER(row0[x0]),
    150                     SRC_TO_FILTER(row0[x1]),
    151                     SRC_TO_FILTER(row1[x0]),
    152                     SRC_TO_FILTER(row1[x1]),
    153                     colors);
    154         colors += 1;
    155 
    156     } while (--count != 0);
    157 
    158 #ifdef POSTAMBLE
    159     POSTAMBLE(s);
    160 #endif
    161 }
    162 void MAKENAME(_filter_DXDY)(const SkBitmapProcState& s,
    163                             const uint32_t* SK_RESTRICT xy,
    164                             int count, DSTTYPE* SK_RESTRICT colors) {
    165     SkASSERT(count > 0 && colors != NULL);
    166     SkASSERT(s.fDoFilter);
    167     SkDEBUGCODE(CHECKSTATE(s);)
    168 
    169 #ifdef PREAMBLE
    170         PREAMBLE(s);
    171 #endif
    172     const char* SK_RESTRICT srcAddr = (const char*)s.fBitmap->getPixels();
    173     int rb = s.fBitmap->rowBytes();
    174 
    175     do {
    176         uint32_t data = *xy++;
    177         unsigned y0 = data >> 14;
    178         unsigned y1 = data & 0x3FFF;
    179         unsigned subY = y0 & 0xF;
    180         y0 >>= 4;
    181 
    182         data = *xy++;
    183         unsigned x0 = data >> 14;
    184         unsigned x1 = data & 0x3FFF;
    185         unsigned subX = x0 & 0xF;
    186         x0 >>= 4;
    187 
    188         const SRCTYPE* SK_RESTRICT row0 = (const SRCTYPE*)(srcAddr + y0 * rb);
    189         const SRCTYPE* SK_RESTRICT row1 = (const SRCTYPE*)(srcAddr + y1 * rb);
    190 
    191         FILTER_PROC(subX, subY,
    192                     SRC_TO_FILTER(row0[x0]),
    193                     SRC_TO_FILTER(row0[x1]),
    194                     SRC_TO_FILTER(row1[x0]),
    195                     SRC_TO_FILTER(row1[x1]),
    196                     colors);
    197         colors += 1;
    198     } while (--count != 0);
    199 
    200 #ifdef POSTAMBLE
    201     POSTAMBLE(s);
    202 #endif
    203 }
    204 
    205 #undef MAKENAME
    206 #undef DSTSIZE
    207 #undef DSTTYPE
    208 #undef SRCTYPE
    209 #undef CHECKSTATE
    210 #undef RETURNDST
    211 #undef SRC_TO_FILTER
    212 #undef FILTER_TO_DST
    213 
    214 #ifdef PREAMBLE
    215     #undef PREAMBLE
    216 #endif
    217 #ifdef POSTAMBLE
    218     #undef POSTAMBLE
    219 #endif
    220 
    221 #undef FILTER_PROC_TYPE
    222 #undef GET_FILTER_TABLE
    223 #undef GET_FILTER_ROW
    224 #undef GET_FILTER_ROW_PROC
    225 #undef GET_FILTER_PROC
    226 #undef BITMAPPROC_MEMSET
    227