go-libwebp

Experimental translation from libwebp to Go source.
Log | Files | Refs | README | LICENSE

yuv_mips32.c (5999B)


      1 // Copyright 2014 Google Inc. All Rights Reserved.
      2 //
      3 // Use of this source code is governed by a BSD-style license
      4 // that can be found in the COPYING file in the root of the source
      5 // tree. An additional intellectual property rights grant can be found
      6 // in the file PATENTS. All contributing project authors may
      7 // be found in the AUTHORS file in the root of the source tree.
      8 // -----------------------------------------------------------------------------
      9 //
     10 // MIPS version of YUV to RGB upsampling functions.
     11 //
     12 // Author(s):  Djordje Pesut    (djordje.pesut@imgtec.com)
     13 //             Jovan Zelincevic (jovan.zelincevic@imgtec.com)
     14 
     15 #include "src/dsp/dsp.h"
     16 
     17 #if defined(WEBP_USE_MIPS32)
     18 
     19 #include "src/dsp/yuv.h"
     20 
     21 //------------------------------------------------------------------------------
     22 // simple point-sampling
     23 
     24 #define ROW_FUNC(FUNC_NAME, XSTEP, R, G, B, A)                                 \
     25 static void FUNC_NAME(const uint8_t* WEBP_RESTRICT y,                          \
     26                       const uint8_t* WEBP_RESTRICT u,                          \
     27                       const uint8_t* WEBP_RESTRICT v,                          \
     28                       uint8_t* WEBP_RESTRICT dst, int len) {                   \
     29   int i, r, g, b;                                                              \
     30   int temp0, temp1, temp2, temp3, temp4;                                       \
     31   for (i = 0; i < (len >> 1); i++) {                                           \
     32     temp1 = MultHi(v[0], 26149);                                               \
     33     temp3 = MultHi(v[0], 13320);                                               \
     34     temp2 = MultHi(u[0], 6419);                                                \
     35     temp4 = MultHi(u[0], 33050);                                               \
     36     temp0 = MultHi(y[0], 19077);                                               \
     37     temp1 -= 14234;                                                            \
     38     temp3 -= 8708;                                                             \
     39     temp2 += temp3;                                                            \
     40     temp4 -= 17685;                                                            \
     41     r = VP8Clip8(temp0 + temp1);                                               \
     42     g = VP8Clip8(temp0 - temp2);                                               \
     43     b = VP8Clip8(temp0 + temp4);                                               \
     44     temp0 = MultHi(y[1], 19077);                                               \
     45     dst[R] = r;                                                                \
     46     dst[G] = g;                                                                \
     47     dst[B] = b;                                                                \
     48     if (A) dst[A] = 0xff;                                                      \
     49     r = VP8Clip8(temp0 + temp1);                                               \
     50     g = VP8Clip8(temp0 - temp2);                                               \
     51     b = VP8Clip8(temp0 + temp4);                                               \
     52     dst[R + XSTEP] = r;                                                        \
     53     dst[G + XSTEP] = g;                                                        \
     54     dst[B + XSTEP] = b;                                                        \
     55     if (A) dst[A + XSTEP] = 0xff;                                              \
     56     y += 2;                                                                    \
     57     ++u;                                                                       \
     58     ++v;                                                                       \
     59     dst += 2 * XSTEP;                                                          \
     60   }                                                                            \
     61   if (len & 1) {                                                               \
     62     temp1 = MultHi(v[0], 26149);                                               \
     63     temp3 = MultHi(v[0], 13320);                                               \
     64     temp2 = MultHi(u[0], 6419);                                                \
     65     temp4 = MultHi(u[0], 33050);                                               \
     66     temp0 = MultHi(y[0], 19077);                                               \
     67     temp1 -= 14234;                                                            \
     68     temp3 -= 8708;                                                             \
     69     temp2 += temp3;                                                            \
     70     temp4 -= 17685;                                                            \
     71     r = VP8Clip8(temp0 + temp1);                                               \
     72     g = VP8Clip8(temp0 - temp2);                                               \
     73     b = VP8Clip8(temp0 + temp4);                                               \
     74     dst[R] = r;                                                                \
     75     dst[G] = g;                                                                \
     76     dst[B] = b;                                                                \
     77     if (A) dst[A] = 0xff;                                                      \
     78   }                                                                            \
     79 }
     80 
     81 ROW_FUNC(YuvToRgbRow_MIPS32,      3, 0, 1, 2, 0)
     82 ROW_FUNC(YuvToRgbaRow_MIPS32,     4, 0, 1, 2, 3)
     83 ROW_FUNC(YuvToBgrRow_MIPS32,      3, 2, 1, 0, 0)
     84 ROW_FUNC(YuvToBgraRow_MIPS32,     4, 2, 1, 0, 3)
     85 
     86 #undef ROW_FUNC
     87 
     88 //------------------------------------------------------------------------------
     89 // Entry point
     90 
     91 extern void WebPInitSamplersMIPS32(void);
     92 
     93 WEBP_TSAN_IGNORE_FUNCTION void WebPInitSamplersMIPS32(void) {
     94   WebPSamplers[MODE_RGB]  = YuvToRgbRow_MIPS32;
     95   WebPSamplers[MODE_RGBA] = YuvToRgbaRow_MIPS32;
     96   WebPSamplers[MODE_BGR]  = YuvToBgrRow_MIPS32;
     97   WebPSamplers[MODE_BGRA] = YuvToBgraRow_MIPS32;
     98 }
     99 
    100 #else  // !WEBP_USE_MIPS32
    101 
    102 WEBP_DSP_INIT_STUB(WebPInitSamplersMIPS32)
    103 
    104 #endif  // WEBP_USE_MIPS32