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 // ARGB making functions.
11 //
12 // Author: Djordje Pesut (djordje.pesut@imgtec.com)
13
14 #include "./dsp.h"
15
MakeARGB32(int a,int r,int g,int b)16 static WEBP_INLINE uint32_t MakeARGB32(int a, int r, int g, int b) {
17 return (((uint32_t)a << 24) | (r << 16) | (g << 8) | b);
18 }
19
PackARGB(const uint8_t * a,const uint8_t * r,const uint8_t * g,const uint8_t * b,int len,uint32_t * out)20 static void PackARGB(const uint8_t* a, const uint8_t* r, const uint8_t* g,
21 const uint8_t* b, int len, uint32_t* out) {
22 int i;
23 for (i = 0; i < len; ++i) {
24 out[i] = MakeARGB32(a[4 * i], r[4 * i], g[4 * i], b[4 * i]);
25 }
26 }
27
PackRGB(const uint8_t * r,const uint8_t * g,const uint8_t * b,int len,int step,uint32_t * out)28 static void PackRGB(const uint8_t* r, const uint8_t* g, const uint8_t* b,
29 int len, int step, uint32_t* out) {
30 int i, offset = 0;
31 for (i = 0; i < len; ++i) {
32 out[i] = MakeARGB32(0xff, r[offset], g[offset], b[offset]);
33 offset += step;
34 }
35 }
36
37 void (*VP8PackARGB)(const uint8_t*, const uint8_t*, const uint8_t*,
38 const uint8_t*, int, uint32_t*);
39 void (*VP8PackRGB)(const uint8_t*, const uint8_t*, const uint8_t*,
40 int, int, uint32_t*);
41
42 extern void VP8EncDspARGBInitMIPSdspR2(void);
43 extern void VP8EncDspARGBInitSSE2(void);
44
45 static volatile VP8CPUInfo argb_last_cpuinfo_used =
46 (VP8CPUInfo)&argb_last_cpuinfo_used;
47
VP8EncDspARGBInit(void)48 WEBP_TSAN_IGNORE_FUNCTION void VP8EncDspARGBInit(void) {
49 if (argb_last_cpuinfo_used == VP8GetCPUInfo) return;
50
51 VP8PackARGB = PackARGB;
52 VP8PackRGB = PackRGB;
53
54 // If defined, use CPUInfo() to overwrite some pointers with faster versions.
55 if (VP8GetCPUInfo != NULL) {
56 #if defined(WEBP_USE_SSE2)
57 if (VP8GetCPUInfo(kSSE2)) {
58 VP8EncDspARGBInitSSE2();
59 }
60 #endif
61 #if defined(WEBP_USE_MIPS_DSP_R2)
62 if (VP8GetCPUInfo(kMIPSdspR2)) {
63 VP8EncDspARGBInitMIPSdspR2();
64 }
65 #endif
66 }
67 argb_last_cpuinfo_used = VP8GetCPUInfo;
68 }
69