Coverage Report

Created: 2025-06-13 06:49

/src/libwebp/src/dsp/lossless_enc.c
Line
Count
Source (jump to first uncovered line)
1
// Copyright 2015 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
// Image transform methods for lossless encoder.
11
//
12
// Authors: Vikas Arora (vikaas.arora@gmail.com)
13
//          Jyrki Alakuijala (jyrki@google.com)
14
//          Urvang Joshi (urvang@google.com)
15
16
#include <assert.h>
17
#include <math.h>
18
#include <stdlib.h>
19
#include <string.h>
20
21
#include "src/dsp/cpu.h"
22
#include "src/dsp/dsp.h"
23
#include "src/dsp/lossless.h"
24
#include "src/dsp/lossless_common.h"
25
#include "src/enc/histogram_enc.h"
26
#include "src/utils/utils.h"
27
#include "src/webp/format_constants.h"
28
#include "src/webp/types.h"
29
30
// lookup table for small values of log2(int) * (1 << LOG_2_PRECISION_BITS).
31
// Obtained in Python with:
32
// a = [ str(round((1<<23)*math.log2(i))) if i else "0" for i in range(256)]
33
// print(',\n'.join(['  '+','.join(v)
34
//       for v in batched([i.rjust(9) for i in a],7)]))
35
const uint32_t kLog2Table[LOG_LOOKUP_IDX_MAX] = {
36
         0,        0,  8388608, 13295629, 16777216, 19477745, 21684237,
37
  23549800, 25165824, 26591258, 27866353, 29019816, 30072845, 31041538,
38
  31938408, 32773374, 33554432, 34288123, 34979866, 35634199, 36254961,
39
  36845429, 37408424, 37946388, 38461453, 38955489, 39430146, 39886887,
40
  40327016, 40751698, 41161982, 41558811, 41943040, 42315445, 42676731,
41
  43027545, 43368474, 43700062, 44022807, 44337167, 44643569, 44942404,
42
  45234037, 45518808, 45797032, 46069003, 46334996, 46595268, 46850061,
43
  47099600, 47344097, 47583753, 47818754, 48049279, 48275495, 48497560,
44
  48715624, 48929828, 49140306, 49347187, 49550590, 49750631, 49947419,
45
  50141058, 50331648, 50519283, 50704053, 50886044, 51065339, 51242017,
46
  51416153, 51587818, 51757082, 51924012, 52088670, 52251118, 52411415,
47
  52569616, 52725775, 52879946, 53032177, 53182516, 53331012, 53477707,
48
  53622645, 53765868, 53907416, 54047327, 54185640, 54322389, 54457611,
49
  54591338, 54723604, 54854440, 54983876, 55111943, 55238669, 55364082,
50
  55488208, 55611074, 55732705, 55853126, 55972361, 56090432, 56207362,
51
  56323174, 56437887, 56551524, 56664103, 56775645, 56886168, 56995691,
52
  57104232, 57211808, 57318436, 57424133, 57528914, 57632796, 57735795,
53
  57837923, 57939198, 58039632, 58139239, 58238033, 58336027, 58433234,
54
  58529666, 58625336, 58720256, 58814437, 58907891, 59000628, 59092661,
55
  59183999, 59274652, 59364632, 59453947, 59542609, 59630625, 59718006,
56
  59804761, 59890898, 59976426, 60061354, 60145690, 60229443, 60312620,
57
  60395229, 60477278, 60558775, 60639726, 60720140, 60800023, 60879382,
58
  60958224, 61036555, 61114383, 61191714, 61268554, 61344908, 61420785,
59
  61496188, 61571124, 61645600, 61719620, 61793189, 61866315, 61939001,
60
  62011253, 62083076, 62154476, 62225457, 62296024, 62366182, 62435935,
61
  62505289, 62574248, 62642816, 62710997, 62778797, 62846219, 62913267,
62
  62979946, 63046260, 63112212, 63177807, 63243048, 63307939, 63372484,
63
  63436687, 63500551, 63564080, 63627277, 63690146, 63752690, 63814912,
64
  63876816, 63938405, 63999682, 64060650, 64121313, 64181673, 64241734,
65
  64301498, 64360969, 64420148, 64479040, 64537646, 64595970, 64654014,
66
  64711782, 64769274, 64826495, 64883447, 64940132, 64996553, 65052711,
67
  65108611, 65164253, 65219641, 65274776, 65329662, 65384299, 65438691,
68
  65492840, 65546747, 65600416, 65653847, 65707044, 65760008, 65812741,
69
  65865245, 65917522, 65969575, 66021404, 66073013, 66124403, 66175575,
70
  66226531, 66277275, 66327806, 66378127, 66428240, 66478146, 66527847,
71
  66577345, 66626641, 66675737, 66724635, 66773336, 66821842, 66870154,
72
  66918274, 66966204, 67013944, 67061497
73
};
74
75
// lookup table for small values of int*log2(int) * (1 << LOG_2_PRECISION_BITS).
76
// Obtained in Python with:
77
// a=[ "%d"%i if i<(1<<32) else "%dull"%i
78
//     for i in [ round((1<<LOG_2_PRECISION_BITS)*math.log2(i)*i) if i
79
//     else 0 for i in range(256)]]
80
// print(',\n '.join([','.join(v) for v in batched([i.rjust(15)
81
//                      for i in a],4)]))
82
const uint64_t kSLog2Table[LOG_LOOKUP_IDX_MAX] = {
83
               0,              0,       16777216,       39886887,
84
        67108864,       97388723,      130105423,      164848600,
85
       201326592,      239321324,      278663526,      319217973,
86
       360874141,      403539997,      447137711,      491600606,
87
       536870912,      582898099,      629637592,      677049776,
88
       725099212,      773754010,      822985323,      872766924,
89
       923074875,      973887230,     1025183802,     1076945958,
90
      1129156447,     1181799249,     1234859451,     1288323135,
91
      1342177280,     1396409681,     1451008871,     1505964059,
92
      1561265072,     1616902301,     1672866655,     1729149526,
93
      1785742744,     1842638548,     1899829557,     1957308741,
94
      2015069397,     2073105127,     2131409817,  2189977618ull,
95
   2248802933ull,  2307880396ull,  2367204859ull,  2426771383ull,
96
   2486575220ull,  2546611805ull,  2606876748ull,  2667365819ull,
97
   2728074942ull,  2789000187ull,  2850137762ull,  2911484006ull,
98
   2973035382ull,  3034788471ull,  3096739966ull,  3158886666ull,
99
   3221225472ull,  3283753383ull,  3346467489ull,  3409364969ull,
100
   3472443085ull,  3535699182ull,  3599130679ull,  3662735070ull,
101
   3726509920ull,  3790452862ull,  3854561593ull,  3918833872ull,
102
   3983267519ull,  4047860410ull,  4112610476ull,  4177515704ull,
103
   4242574127ull,  4307783833ull,  4373142952ull,  4438649662ull,
104
   4504302186ull,  4570098787ull,  4636037770ull,  4702117480ull,
105
   4768336298ull,  4834692645ull,  4901184974ull,  4967811774ull,
106
   5034571569ull,  5101462912ull,  5168484389ull,  5235634615ull,
107
   5302912235ull,  5370315922ull,  5437844376ull,  5505496324ull,
108
   5573270518ull,  5641165737ull,  5709180782ull,  5777314477ull,
109
   5845565671ull,  5913933235ull,  5982416059ull,  6051013057ull,
110
   6119723161ull,  6188545324ull,  6257478518ull,  6326521733ull,
111
   6395673979ull,  6464934282ull,  6534301685ull,  6603775250ull,
112
   6673354052ull,  6743037185ull,  6812823756ull,  6882712890ull,
113
   6952703725ull,  7022795412ull,  7092987118ull,  7163278025ull,
114
   7233667324ull,  7304154222ull,  7374737939ull,  7445417707ull,
115
   7516192768ull,  7587062379ull,  7658025806ull,  7729082328ull,
116
   7800231234ull,  7871471825ull,  7942803410ull,  8014225311ull,
117
   8085736859ull,  8157337394ull,  8229026267ull,  8300802839ull,
118
   8372666477ull,  8444616560ull,  8516652476ull,  8588773618ull,
119
   8660979393ull,  8733269211ull,  8805642493ull,  8878098667ull,
120
   8950637170ull,  9023257446ull,  9095958945ull,  9168741125ull,
121
   9241603454ull,  9314545403ull,  9387566451ull,  9460666086ull,
122
   9533843800ull,  9607099093ull,  9680431471ull,  9753840445ull,
123
   9827325535ull,  9900886263ull,  9974522161ull, 10048232765ull,
124
  10122017615ull, 10195876260ull, 10269808253ull, 10343813150ull,
125
  10417890516ull, 10492039919ull, 10566260934ull, 10640553138ull,
126
  10714916116ull, 10789349456ull, 10863852751ull, 10938425600ull,
127
  11013067604ull, 11087778372ull, 11162557513ull, 11237404645ull,
128
  11312319387ull, 11387301364ull, 11462350205ull, 11537465541ull,
129
  11612647010ull, 11687894253ull, 11763206912ull, 11838584638ull,
130
  11914027082ull, 11989533899ull, 12065104750ull, 12140739296ull,
131
  12216437206ull, 12292198148ull, 12368021795ull, 12443907826ull,
132
  12519855920ull, 12595865759ull, 12671937032ull, 12748069427ull,
133
  12824262637ull, 12900516358ull, 12976830290ull, 13053204134ull,
134
  13129637595ull, 13206130381ull, 13282682202ull, 13359292772ull,
135
  13435961806ull, 13512689025ull, 13589474149ull, 13666316903ull,
136
  13743217014ull, 13820174211ull, 13897188225ull, 13974258793ull,
137
  14051385649ull, 14128568535ull, 14205807192ull, 14283101363ull,
138
  14360450796ull, 14437855239ull, 14515314443ull, 14592828162ull,
139
  14670396151ull, 14748018167ull, 14825693972ull, 14903423326ull,
140
  14981205995ull, 15059041743ull, 15136930339ull, 15214871554ull,
141
  15292865160ull, 15370910930ull, 15449008641ull, 15527158071ull,
142
  15605359001ull, 15683611210ull, 15761914485ull, 15840268608ull,
143
  15918673369ull, 15997128556ull, 16075633960ull, 16154189373ull,
144
  16232794589ull, 16311449405ull, 16390153617ull, 16468907026ull,
145
  16547709431ull, 16626560636ull, 16705460444ull, 16784408661ull,
146
  16863405094ull, 16942449552ull, 17021541845ull, 17100681785ull
147
};
148
149
const VP8LPrefixCode kPrefixEncodeCode[PREFIX_LOOKUP_IDX_MAX] = {
150
  { 0, 0}, { 0, 0}, { 1, 0}, { 2, 0}, { 3, 0}, { 4, 1}, { 4, 1}, { 5, 1},
151
  { 5, 1}, { 6, 2}, { 6, 2}, { 6, 2}, { 6, 2}, { 7, 2}, { 7, 2}, { 7, 2},
152
  { 7, 2}, { 8, 3}, { 8, 3}, { 8, 3}, { 8, 3}, { 8, 3}, { 8, 3}, { 8, 3},
153
  { 8, 3}, { 9, 3}, { 9, 3}, { 9, 3}, { 9, 3}, { 9, 3}, { 9, 3}, { 9, 3},
154
  { 9, 3}, {10, 4}, {10, 4}, {10, 4}, {10, 4}, {10, 4}, {10, 4}, {10, 4},
155
  {10, 4}, {10, 4}, {10, 4}, {10, 4}, {10, 4}, {10, 4}, {10, 4}, {10, 4},
156
  {10, 4}, {11, 4}, {11, 4}, {11, 4}, {11, 4}, {11, 4}, {11, 4}, {11, 4},
157
  {11, 4}, {11, 4}, {11, 4}, {11, 4}, {11, 4}, {11, 4}, {11, 4}, {11, 4},
158
  {11, 4}, {12, 5}, {12, 5}, {12, 5}, {12, 5}, {12, 5}, {12, 5}, {12, 5},
159
  {12, 5}, {12, 5}, {12, 5}, {12, 5}, {12, 5}, {12, 5}, {12, 5}, {12, 5},
160
  {12, 5}, {12, 5}, {12, 5}, {12, 5}, {12, 5}, {12, 5}, {12, 5}, {12, 5},
161
  {12, 5}, {12, 5}, {12, 5}, {12, 5}, {12, 5}, {12, 5}, {12, 5}, {12, 5},
162
  {12, 5}, {13, 5}, {13, 5}, {13, 5}, {13, 5}, {13, 5}, {13, 5}, {13, 5},
163
  {13, 5}, {13, 5}, {13, 5}, {13, 5}, {13, 5}, {13, 5}, {13, 5}, {13, 5},
164
  {13, 5}, {13, 5}, {13, 5}, {13, 5}, {13, 5}, {13, 5}, {13, 5}, {13, 5},
165
  {13, 5}, {13, 5}, {13, 5}, {13, 5}, {13, 5}, {13, 5}, {13, 5}, {13, 5},
166
  {13, 5}, {14, 6}, {14, 6}, {14, 6}, {14, 6}, {14, 6}, {14, 6}, {14, 6},
167
  {14, 6}, {14, 6}, {14, 6}, {14, 6}, {14, 6}, {14, 6}, {14, 6}, {14, 6},
168
  {14, 6}, {14, 6}, {14, 6}, {14, 6}, {14, 6}, {14, 6}, {14, 6}, {14, 6},
169
  {14, 6}, {14, 6}, {14, 6}, {14, 6}, {14, 6}, {14, 6}, {14, 6}, {14, 6},
170
  {14, 6}, {14, 6}, {14, 6}, {14, 6}, {14, 6}, {14, 6}, {14, 6}, {14, 6},
171
  {14, 6}, {14, 6}, {14, 6}, {14, 6}, {14, 6}, {14, 6}, {14, 6}, {14, 6},
172
  {14, 6}, {14, 6}, {14, 6}, {14, 6}, {14, 6}, {14, 6}, {14, 6}, {14, 6},
173
  {14, 6}, {14, 6}, {14, 6}, {14, 6}, {14, 6}, {14, 6}, {14, 6}, {14, 6},
174
  {14, 6}, {15, 6}, {15, 6}, {15, 6}, {15, 6}, {15, 6}, {15, 6}, {15, 6},
175
  {15, 6}, {15, 6}, {15, 6}, {15, 6}, {15, 6}, {15, 6}, {15, 6}, {15, 6},
176
  {15, 6}, {15, 6}, {15, 6}, {15, 6}, {15, 6}, {15, 6}, {15, 6}, {15, 6},
177
  {15, 6}, {15, 6}, {15, 6}, {15, 6}, {15, 6}, {15, 6}, {15, 6}, {15, 6},
178
  {15, 6}, {15, 6}, {15, 6}, {15, 6}, {15, 6}, {15, 6}, {15, 6}, {15, 6},
179
  {15, 6}, {15, 6}, {15, 6}, {15, 6}, {15, 6}, {15, 6}, {15, 6}, {15, 6},
180
  {15, 6}, {15, 6}, {15, 6}, {15, 6}, {15, 6}, {15, 6}, {15, 6}, {15, 6},
181
  {15, 6}, {15, 6}, {15, 6}, {15, 6}, {15, 6}, {15, 6}, {15, 6}, {15, 6},
182
  {15, 6}, {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7},
183
  {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7},
184
  {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7},
185
  {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7},
186
  {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7},
187
  {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7},
188
  {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7},
189
  {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7},
190
  {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7},
191
  {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7},
192
  {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7},
193
  {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7},
194
  {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7},
195
  {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7},
196
  {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7},
197
  {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7},
198
  {16, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7},
199
  {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7},
200
  {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7},
201
  {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7},
202
  {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7},
203
  {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7},
204
  {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7},
205
  {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7},
206
  {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7},
207
  {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7},
208
  {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7},
209
  {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7},
210
  {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7},
211
  {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7},
212
  {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7},
213
  {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7},
214
};
215
216
const uint8_t kPrefixEncodeExtraBitsValue[PREFIX_LOOKUP_IDX_MAX] = {
217
   0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  2,  3,  0,  1,  2,  3,
218
   0,  1,  2,  3,  4,  5,  6,  7,  0,  1,  2,  3,  4,  5,  6,  7,
219
   0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15,
220
   0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15,
221
   0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15,
222
  16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
223
   0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15,
224
  16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
225
   0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15,
226
  16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
227
  32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
228
  48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
229
   0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15,
230
  16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
231
  32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
232
  48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
233
   0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15,
234
  16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
235
  32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
236
  48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
237
  64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
238
  80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
239
  96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
240
  112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126,
241
  127,
242
   0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15,
243
  16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
244
  32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
245
  48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
246
  64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
247
  80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
248
  96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
249
  112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126
250
};
251
252
0
static uint64_t FastSLog2Slow_C(uint32_t v) {
253
0
  assert(v >= LOG_LOOKUP_IDX_MAX);
254
0
  if (v < APPROX_LOG_WITH_CORRECTION_MAX) {
255
0
    const uint64_t orig_v = v;
256
0
    uint64_t correction;
257
0
#if !defined(WEBP_HAVE_SLOW_CLZ_CTZ)
258
    // use clz if available
259
0
    const uint64_t log_cnt = BitsLog2Floor(v) - 7;
260
0
    const uint32_t y = 1 << log_cnt;
261
0
    v >>= log_cnt;
262
#else
263
    uint64_t log_cnt = 0;
264
    uint32_t y = 1;
265
    do {
266
      ++log_cnt;
267
      v = v >> 1;
268
      y = y << 1;
269
    } while (v >= LOG_LOOKUP_IDX_MAX);
270
#endif
271
    // vf = (2^log_cnt) * Xf; where y = 2^log_cnt and Xf < 256
272
    // Xf = floor(Xf) * (1 + (v % y) / v)
273
    // log2(Xf) = log2(floor(Xf)) + log2(1 + (v % y) / v)
274
    // The correction factor: log(1 + d) ~ d; for very small d values, so
275
    // log2(1 + (v % y) / v) ~ LOG_2_RECIPROCAL * (v % y)/v
276
0
    correction = LOG_2_RECIPROCAL_FIXED * (orig_v & (y - 1));
277
0
    return orig_v * (kLog2Table[v] + (log_cnt << LOG_2_PRECISION_BITS)) +
278
0
           correction;
279
0
  } else {
280
0
    return (uint64_t)(LOG_2_RECIPROCAL_FIXED_DOUBLE * v * log((double)v) + .5);
281
0
  }
282
0
}
283
284
0
static uint32_t FastLog2Slow_C(uint32_t v) {
285
0
  assert(v >= LOG_LOOKUP_IDX_MAX);
286
0
  if (v < APPROX_LOG_WITH_CORRECTION_MAX) {
287
0
    const uint32_t orig_v = v;
288
0
    uint32_t log_2;
289
0
#if !defined(WEBP_HAVE_SLOW_CLZ_CTZ)
290
    // use clz if available
291
0
    const uint32_t log_cnt = BitsLog2Floor(v) - 7;
292
0
    const uint32_t y = 1 << log_cnt;
293
0
    v >>= log_cnt;
294
#else
295
    uint32_t log_cnt = 0;
296
    uint32_t y = 1;
297
    do {
298
      ++log_cnt;
299
      v = v >> 1;
300
      y = y << 1;
301
    } while (v >= LOG_LOOKUP_IDX_MAX);
302
#endif
303
0
    log_2 = kLog2Table[v] + (log_cnt << LOG_2_PRECISION_BITS);
304
0
    if (orig_v >= APPROX_LOG_MAX) {
305
      // Since the division is still expensive, add this correction factor only
306
      // for large values of 'v'.
307
0
      const uint64_t correction = LOG_2_RECIPROCAL_FIXED * (orig_v & (y - 1));
308
0
      log_2 += (uint32_t)DivRound(correction, orig_v);
309
0
    }
310
0
    return log_2;
311
0
  } else {
312
0
    return (uint32_t)(LOG_2_RECIPROCAL_FIXED_DOUBLE * log((double)v) + .5);
313
0
  }
314
0
}
315
316
//------------------------------------------------------------------------------
317
// Methods to calculate Entropy (Shannon).
318
319
// Compute the combined Shanon's entropy for distribution {X} and {X+Y}
320
static uint64_t CombinedShannonEntropy_C(const uint32_t X[256],
321
0
                                         const uint32_t Y[256]) {
322
0
  int i;
323
0
  uint64_t retval = 0;
324
0
  uint32_t sumX = 0, sumXY = 0;
325
0
  for (i = 0; i < 256; ++i) {
326
0
    const uint32_t x = X[i];
327
0
    if (x != 0) {
328
0
      const uint32_t xy = x + Y[i];
329
0
      sumX += x;
330
0
      retval += VP8LFastSLog2(x);
331
0
      sumXY += xy;
332
0
      retval += VP8LFastSLog2(xy);
333
0
    } else if (Y[i] != 0) {
334
0
      sumXY += Y[i];
335
0
      retval += VP8LFastSLog2(Y[i]);
336
0
    }
337
0
  }
338
0
  retval = VP8LFastSLog2(sumX) + VP8LFastSLog2(sumXY) - retval;
339
0
  return retval;
340
0
}
341
342
0
static uint64_t ShannonEntropy_C(const uint32_t* X, int n) {
343
0
  int i;
344
0
  uint64_t retval = 0;
345
0
  uint32_t sumX = 0;
346
0
  for (i = 0; i < n; ++i) {
347
0
    const int x = X[i];
348
0
    if (x != 0) {
349
0
      sumX += x;
350
0
      retval += VP8LFastSLog2(x);
351
0
    }
352
0
  }
353
0
  retval = VP8LFastSLog2(sumX) - retval;
354
0
  return retval;
355
0
}
356
357
0
void VP8LBitEntropyInit(VP8LBitEntropy* const entropy) {
358
0
  entropy->entropy = 0;
359
0
  entropy->sum = 0;
360
0
  entropy->nonzeros = 0;
361
0
  entropy->max_val = 0;
362
0
  entropy->nonzero_code = VP8L_NON_TRIVIAL_SYM;
363
0
}
364
365
void VP8LBitsEntropyUnrefined(const uint32_t* WEBP_RESTRICT const array, int n,
366
0
                              VP8LBitEntropy* WEBP_RESTRICT const entropy) {
367
0
  int i;
368
369
0
  VP8LBitEntropyInit(entropy);
370
371
0
  for (i = 0; i < n; ++i) {
372
0
    if (array[i] != 0) {
373
0
      entropy->sum += array[i];
374
0
      entropy->nonzero_code = i;
375
0
      ++entropy->nonzeros;
376
0
      entropy->entropy += VP8LFastSLog2(array[i]);
377
0
      if (entropy->max_val < array[i]) {
378
0
        entropy->max_val = array[i];
379
0
      }
380
0
    }
381
0
  }
382
0
  entropy->entropy = VP8LFastSLog2(entropy->sum) - entropy->entropy;
383
0
}
384
385
static WEBP_INLINE void GetEntropyUnrefinedHelper(
386
    uint32_t val, int i, uint32_t* WEBP_RESTRICT const val_prev,
387
    int* WEBP_RESTRICT const i_prev,
388
    VP8LBitEntropy* WEBP_RESTRICT const bit_entropy,
389
0
    VP8LStreaks* WEBP_RESTRICT const stats) {
390
0
  const int streak = i - *i_prev;
391
392
  // Gather info for the bit entropy.
393
0
  if (*val_prev != 0) {
394
0
    bit_entropy->sum += (*val_prev) * streak;
395
0
    bit_entropy->nonzeros += streak;
396
0
    bit_entropy->nonzero_code = *i_prev;
397
0
    bit_entropy->entropy += VP8LFastSLog2(*val_prev) * streak;
398
0
    if (bit_entropy->max_val < *val_prev) {
399
0
      bit_entropy->max_val = *val_prev;
400
0
    }
401
0
  }
402
403
  // Gather info for the Huffman cost.
404
0
  stats->counts[*val_prev != 0] += (streak > 3);
405
0
  stats->streaks[*val_prev != 0][(streak > 3)] += streak;
406
407
0
  *val_prev = val;
408
0
  *i_prev = i;
409
0
}
410
411
static void GetEntropyUnrefined_C(
412
    const uint32_t X[], int length,
413
    VP8LBitEntropy* WEBP_RESTRICT const bit_entropy,
414
0
    VP8LStreaks* WEBP_RESTRICT const stats) {
415
0
  int i;
416
0
  int i_prev = 0;
417
0
  uint32_t x_prev = X[0];
418
419
0
  memset(stats, 0, sizeof(*stats));
420
0
  VP8LBitEntropyInit(bit_entropy);
421
422
0
  for (i = 1; i < length; ++i) {
423
0
    const uint32_t x = X[i];
424
0
    if (x != x_prev) {
425
0
      GetEntropyUnrefinedHelper(x, i, &x_prev, &i_prev, bit_entropy, stats);
426
0
    }
427
0
  }
428
0
  GetEntropyUnrefinedHelper(0, i, &x_prev, &i_prev, bit_entropy, stats);
429
430
0
  bit_entropy->entropy = VP8LFastSLog2(bit_entropy->sum) - bit_entropy->entropy;
431
0
}
432
433
static void GetCombinedEntropyUnrefined_C(
434
    const uint32_t X[], const uint32_t Y[], int length,
435
    VP8LBitEntropy* WEBP_RESTRICT const bit_entropy,
436
0
    VP8LStreaks* WEBP_RESTRICT const stats) {
437
0
  int i = 1;
438
0
  int i_prev = 0;
439
0
  uint32_t xy_prev = X[0] + Y[0];
440
441
0
  memset(stats, 0, sizeof(*stats));
442
0
  VP8LBitEntropyInit(bit_entropy);
443
444
0
  for (i = 1; i < length; ++i) {
445
0
    const uint32_t xy = X[i] + Y[i];
446
0
    if (xy != xy_prev) {
447
0
      GetEntropyUnrefinedHelper(xy, i, &xy_prev, &i_prev, bit_entropy, stats);
448
0
    }
449
0
  }
450
0
  GetEntropyUnrefinedHelper(0, i, &xy_prev, &i_prev, bit_entropy, stats);
451
452
0
  bit_entropy->entropy = VP8LFastSLog2(bit_entropy->sum) - bit_entropy->entropy;
453
0
}
454
455
//------------------------------------------------------------------------------
456
457
0
void VP8LSubtractGreenFromBlueAndRed_C(uint32_t* argb_data, int num_pixels) {
458
0
  int i;
459
0
  for (i = 0; i < num_pixels; ++i) {
460
0
    const int argb = (int)argb_data[i];
461
0
    const int green = (argb >> 8) & 0xff;
462
0
    const uint32_t new_r = (((argb >> 16) & 0xff) - green) & 0xff;
463
0
    const uint32_t new_b = (((argb >>  0) & 0xff) - green) & 0xff;
464
0
    argb_data[i] = ((uint32_t)argb & 0xff00ff00u) | (new_r << 16) | new_b;
465
0
  }
466
0
}
467
468
0
static WEBP_INLINE int ColorTransformDelta(int8_t color_pred, int8_t color) {
469
0
  return ((int)color_pred * color) >> 5;
470
0
}
471
472
0
static WEBP_INLINE int8_t U32ToS8(uint32_t v) {
473
0
  return (int8_t)(v & 0xff);
474
0
}
475
476
void VP8LTransformColor_C(const VP8LMultipliers* WEBP_RESTRICT const m,
477
0
                          uint32_t* WEBP_RESTRICT data, int num_pixels) {
478
0
  int i;
479
0
  for (i = 0; i < num_pixels; ++i) {
480
0
    const uint32_t argb = data[i];
481
0
    const int8_t green = U32ToS8(argb >>  8);
482
0
    const int8_t red   = U32ToS8(argb >> 16);
483
0
    int new_red = red & 0xff;
484
0
    int new_blue = argb & 0xff;
485
0
    new_red -= ColorTransformDelta((int8_t)m->green_to_red, green);
486
0
    new_red &= 0xff;
487
0
    new_blue -= ColorTransformDelta((int8_t)m->green_to_blue, green);
488
0
    new_blue -= ColorTransformDelta((int8_t)m->red_to_blue, red);
489
0
    new_blue &= 0xff;
490
0
    data[i] = (argb & 0xff00ff00u) | (new_red << 16) | (new_blue);
491
0
  }
492
0
}
493
494
static WEBP_INLINE uint8_t TransformColorRed(uint8_t green_to_red,
495
0
                                             uint32_t argb) {
496
0
  const int8_t green = U32ToS8(argb >> 8);
497
0
  int new_red = argb >> 16;
498
0
  new_red -= ColorTransformDelta((int8_t)green_to_red, green);
499
0
  return (new_red & 0xff);
500
0
}
501
502
static WEBP_INLINE uint8_t TransformColorBlue(uint8_t green_to_blue,
503
                                              uint8_t red_to_blue,
504
0
                                              uint32_t argb) {
505
0
  const int8_t green = U32ToS8(argb >>  8);
506
0
  const int8_t red   = U32ToS8(argb >> 16);
507
0
  int new_blue = argb & 0xff;
508
0
  new_blue -= ColorTransformDelta((int8_t)green_to_blue, green);
509
0
  new_blue -= ColorTransformDelta((int8_t)red_to_blue, red);
510
0
  return (new_blue & 0xff);
511
0
}
512
513
void VP8LCollectColorRedTransforms_C(const uint32_t* WEBP_RESTRICT argb,
514
                                     int stride,
515
                                     int tile_width, int tile_height,
516
0
                                     int green_to_red, uint32_t histo[]) {
517
0
  while (tile_height-- > 0) {
518
0
    int x;
519
0
    for (x = 0; x < tile_width; ++x) {
520
0
      ++histo[TransformColorRed((uint8_t)green_to_red, argb[x])];
521
0
    }
522
0
    argb += stride;
523
0
  }
524
0
}
525
526
void VP8LCollectColorBlueTransforms_C(const uint32_t* WEBP_RESTRICT argb,
527
                                      int stride,
528
                                      int tile_width, int tile_height,
529
                                      int green_to_blue, int red_to_blue,
530
0
                                      uint32_t histo[]) {
531
0
  while (tile_height-- > 0) {
532
0
    int x;
533
0
    for (x = 0; x < tile_width; ++x) {
534
0
      ++histo[TransformColorBlue((uint8_t)green_to_blue, (uint8_t)red_to_blue,
535
0
                                 argb[x])];
536
0
    }
537
0
    argb += stride;
538
0
  }
539
0
}
540
541
//------------------------------------------------------------------------------
542
543
static int VectorMismatch_C(const uint32_t* const array1,
544
0
                            const uint32_t* const array2, int length) {
545
0
  int match_len = 0;
546
547
0
  while (match_len < length && array1[match_len] == array2[match_len]) {
548
0
    ++match_len;
549
0
  }
550
0
  return match_len;
551
0
}
552
553
// Bundles multiple (1, 2, 4 or 8) pixels into a single pixel.
554
void VP8LBundleColorMap_C(const uint8_t* WEBP_RESTRICT const row,
555
0
                          int width, int xbits, uint32_t* WEBP_RESTRICT dst) {
556
0
  int x;
557
0
  if (xbits > 0) {
558
0
    const int bit_depth = 1 << (3 - xbits);
559
0
    const int mask = (1 << xbits) - 1;
560
0
    uint32_t code = 0xff000000;
561
0
    for (x = 0; x < width; ++x) {
562
0
      const int xsub = x & mask;
563
0
      if (xsub == 0) {
564
0
        code = 0xff000000;
565
0
      }
566
0
      code |= row[x] << (8 + bit_depth * xsub);
567
0
      dst[x >> xbits] = code;
568
0
    }
569
0
  } else {
570
0
    for (x = 0; x < width; ++x) dst[x] = 0xff000000 | (row[x] << 8);
571
0
  }
572
0
}
573
574
//------------------------------------------------------------------------------
575
576
0
static uint32_t ExtraCost_C(const uint32_t* population, int length) {
577
0
  int i;
578
0
  uint32_t cost = population[4] + population[5];
579
0
  assert(length % 2 == 0);
580
0
  for (i = 2; i < length / 2 - 1; ++i) {
581
0
    cost += i * (population[2 * i + 2] + population[2 * i + 3]);
582
0
  }
583
0
  return cost;
584
0
}
585
586
//------------------------------------------------------------------------------
587
588
static void AddVector_C(const uint32_t* WEBP_RESTRICT a,
589
                        const uint32_t* WEBP_RESTRICT b,
590
0
                        uint32_t* WEBP_RESTRICT out, int size) {
591
0
  int i;
592
0
  for (i = 0; i < size; ++i) out[i] = a[i] + b[i];
593
0
}
594
595
static void AddVectorEq_C(const uint32_t* WEBP_RESTRICT a,
596
0
                          uint32_t* WEBP_RESTRICT out, int size) {
597
0
  int i;
598
0
  for (i = 0; i < size; ++i) out[i] += a[i];
599
0
}
600
601
//------------------------------------------------------------------------------
602
// Image transforms.
603
604
static void PredictorSub0_C(const uint32_t* in, const uint32_t* upper,
605
0
                            int num_pixels, uint32_t* WEBP_RESTRICT out) {
606
0
  int i;
607
0
  for (i = 0; i < num_pixels; ++i) out[i] = VP8LSubPixels(in[i], ARGB_BLACK);
608
0
  (void)upper;
609
0
}
610
611
static void PredictorSub1_C(const uint32_t* in, const uint32_t* upper,
612
0
                            int num_pixels, uint32_t* WEBP_RESTRICT out) {
613
0
  int i;
614
0
  for (i = 0; i < num_pixels; ++i) out[i] = VP8LSubPixels(in[i], in[i - 1]);
615
0
  (void)upper;
616
0
}
617
618
// It subtracts the prediction from the input pixel and stores the residual
619
// in the output pixel.
620
#define GENERATE_PREDICTOR_SUB(PREDICTOR_I)                                \
621
static void PredictorSub##PREDICTOR_I##_C(const uint32_t* in,              \
622
                                          const uint32_t* upper,           \
623
                                          int num_pixels,                  \
624
0
                                          uint32_t* WEBP_RESTRICT out) {   \
625
0
  int x;                                                                   \
626
0
  assert(upper != NULL);                                                   \
627
0
  for (x = 0; x < num_pixels; ++x) {                                       \
628
0
    const uint32_t pred =                                                  \
629
0
        VP8LPredictor##PREDICTOR_I##_C(&in[x - 1], upper + x);             \
630
0
    out[x] = VP8LSubPixels(in[x], pred);                                   \
631
0
  }                                                                        \
632
0
}
Unexecuted instantiation: lossless_enc.c:PredictorSub2_C
Unexecuted instantiation: lossless_enc.c:PredictorSub3_C
Unexecuted instantiation: lossless_enc.c:PredictorSub4_C
Unexecuted instantiation: lossless_enc.c:PredictorSub5_C
Unexecuted instantiation: lossless_enc.c:PredictorSub6_C
Unexecuted instantiation: lossless_enc.c:PredictorSub7_C
Unexecuted instantiation: lossless_enc.c:PredictorSub8_C
Unexecuted instantiation: lossless_enc.c:PredictorSub9_C
Unexecuted instantiation: lossless_enc.c:PredictorSub10_C
Unexecuted instantiation: lossless_enc.c:PredictorSub11_C
Unexecuted instantiation: lossless_enc.c:PredictorSub12_C
Unexecuted instantiation: lossless_enc.c:PredictorSub13_C
633
634
GENERATE_PREDICTOR_SUB(2)
635
GENERATE_PREDICTOR_SUB(3)
636
GENERATE_PREDICTOR_SUB(4)
637
GENERATE_PREDICTOR_SUB(5)
638
GENERATE_PREDICTOR_SUB(6)
639
GENERATE_PREDICTOR_SUB(7)
640
GENERATE_PREDICTOR_SUB(8)
641
GENERATE_PREDICTOR_SUB(9)
642
GENERATE_PREDICTOR_SUB(10)
643
GENERATE_PREDICTOR_SUB(11)
644
GENERATE_PREDICTOR_SUB(12)
645
GENERATE_PREDICTOR_SUB(13)
646
647
//------------------------------------------------------------------------------
648
649
VP8LProcessEncBlueAndRedFunc VP8LSubtractGreenFromBlueAndRed;
650
VP8LProcessEncBlueAndRedFunc VP8LSubtractGreenFromBlueAndRed_SSE;
651
652
VP8LTransformColorFunc VP8LTransformColor;
653
VP8LTransformColorFunc VP8LTransformColor_SSE;
654
655
VP8LCollectColorBlueTransformsFunc VP8LCollectColorBlueTransforms;
656
VP8LCollectColorBlueTransformsFunc VP8LCollectColorBlueTransforms_SSE;
657
VP8LCollectColorRedTransformsFunc VP8LCollectColorRedTransforms;
658
VP8LCollectColorRedTransformsFunc VP8LCollectColorRedTransforms_SSE;
659
660
VP8LFastLog2SlowFunc VP8LFastLog2Slow;
661
VP8LFastSLog2SlowFunc VP8LFastSLog2Slow;
662
663
VP8LCostFunc VP8LExtraCost;
664
VP8LCombinedShannonEntropyFunc VP8LCombinedShannonEntropy;
665
VP8LShannonEntropyFunc VP8LShannonEntropy;
666
667
VP8LGetEntropyUnrefinedFunc VP8LGetEntropyUnrefined;
668
VP8LGetCombinedEntropyUnrefinedFunc VP8LGetCombinedEntropyUnrefined;
669
670
VP8LAddVectorFunc VP8LAddVector;
671
VP8LAddVectorEqFunc VP8LAddVectorEq;
672
673
VP8LVectorMismatchFunc VP8LVectorMismatch;
674
VP8LBundleColorMapFunc VP8LBundleColorMap;
675
VP8LBundleColorMapFunc VP8LBundleColorMap_SSE;
676
677
VP8LPredictorAddSubFunc VP8LPredictorsSub[16];
678
VP8LPredictorAddSubFunc VP8LPredictorsSub_C[16];
679
VP8LPredictorAddSubFunc VP8LPredictorsSub_SSE[16];
680
681
extern VP8CPUInfo VP8GetCPUInfo;
682
extern void VP8LEncDspInitSSE2(void);
683
extern void VP8LEncDspInitSSE41(void);
684
extern void VP8LEncDspInitAVX2(void);
685
extern void VP8LEncDspInitNEON(void);
686
extern void VP8LEncDspInitMIPS32(void);
687
extern void VP8LEncDspInitMIPSdspR2(void);
688
extern void VP8LEncDspInitMSA(void);
689
690
0
WEBP_DSP_INIT_FUNC(VP8LEncDspInit) {
691
0
  VP8LDspInit();
692
693
0
#if !WEBP_NEON_OMIT_C_CODE
694
0
  VP8LSubtractGreenFromBlueAndRed = VP8LSubtractGreenFromBlueAndRed_C;
695
696
0
  VP8LTransformColor = VP8LTransformColor_C;
697
0
#endif
698
699
0
  VP8LCollectColorBlueTransforms = VP8LCollectColorBlueTransforms_C;
700
0
  VP8LCollectColorRedTransforms = VP8LCollectColorRedTransforms_C;
701
702
0
  VP8LFastLog2Slow = FastLog2Slow_C;
703
0
  VP8LFastSLog2Slow = FastSLog2Slow_C;
704
705
0
  VP8LExtraCost = ExtraCost_C;
706
0
  VP8LCombinedShannonEntropy = CombinedShannonEntropy_C;
707
0
  VP8LShannonEntropy = ShannonEntropy_C;
708
709
0
  VP8LGetEntropyUnrefined = GetEntropyUnrefined_C;
710
0
  VP8LGetCombinedEntropyUnrefined = GetCombinedEntropyUnrefined_C;
711
712
0
  VP8LAddVector = AddVector_C;
713
0
  VP8LAddVectorEq = AddVectorEq_C;
714
715
0
  VP8LVectorMismatch = VectorMismatch_C;
716
0
  VP8LBundleColorMap = VP8LBundleColorMap_C;
717
718
0
  VP8LPredictorsSub[0] = PredictorSub0_C;
719
0
  VP8LPredictorsSub[1] = PredictorSub1_C;
720
0
  VP8LPredictorsSub[2] = PredictorSub2_C;
721
0
  VP8LPredictorsSub[3] = PredictorSub3_C;
722
0
  VP8LPredictorsSub[4] = PredictorSub4_C;
723
0
  VP8LPredictorsSub[5] = PredictorSub5_C;
724
0
  VP8LPredictorsSub[6] = PredictorSub6_C;
725
0
  VP8LPredictorsSub[7] = PredictorSub7_C;
726
0
  VP8LPredictorsSub[8] = PredictorSub8_C;
727
0
  VP8LPredictorsSub[9] = PredictorSub9_C;
728
0
  VP8LPredictorsSub[10] = PredictorSub10_C;
729
0
  VP8LPredictorsSub[11] = PredictorSub11_C;
730
0
  VP8LPredictorsSub[12] = PredictorSub12_C;
731
0
  VP8LPredictorsSub[13] = PredictorSub13_C;
732
0
  VP8LPredictorsSub[14] = PredictorSub0_C;  // <- padding security sentinels
733
0
  VP8LPredictorsSub[15] = PredictorSub0_C;
734
735
0
  VP8LPredictorsSub_C[0] = PredictorSub0_C;
736
0
  VP8LPredictorsSub_C[1] = PredictorSub1_C;
737
0
  VP8LPredictorsSub_C[2] = PredictorSub2_C;
738
0
  VP8LPredictorsSub_C[3] = PredictorSub3_C;
739
0
  VP8LPredictorsSub_C[4] = PredictorSub4_C;
740
0
  VP8LPredictorsSub_C[5] = PredictorSub5_C;
741
0
  VP8LPredictorsSub_C[6] = PredictorSub6_C;
742
0
  VP8LPredictorsSub_C[7] = PredictorSub7_C;
743
0
  VP8LPredictorsSub_C[8] = PredictorSub8_C;
744
0
  VP8LPredictorsSub_C[9] = PredictorSub9_C;
745
0
  VP8LPredictorsSub_C[10] = PredictorSub10_C;
746
0
  VP8LPredictorsSub_C[11] = PredictorSub11_C;
747
0
  VP8LPredictorsSub_C[12] = PredictorSub12_C;
748
0
  VP8LPredictorsSub_C[13] = PredictorSub13_C;
749
0
  VP8LPredictorsSub_C[14] = PredictorSub0_C;  // <- padding security sentinels
750
0
  VP8LPredictorsSub_C[15] = PredictorSub0_C;
751
752
  // If defined, use CPUInfo() to overwrite some pointers with faster versions.
753
0
  if (VP8GetCPUInfo != NULL) {
754
0
#if defined(WEBP_HAVE_SSE2)
755
0
    if (VP8GetCPUInfo(kSSE2)) {
756
0
      VP8LEncDspInitSSE2();
757
0
#if defined(WEBP_HAVE_SSE41)
758
0
      if (VP8GetCPUInfo(kSSE4_1)) {
759
0
        VP8LEncDspInitSSE41();
760
#if defined(WEBP_HAVE_AVX2)
761
        if (VP8GetCPUInfo(kAVX2)) {
762
          VP8LEncDspInitAVX2();
763
        }
764
#endif
765
0
      }
766
0
#endif
767
0
    }
768
0
#endif
769
#if defined(WEBP_USE_MIPS32)
770
    if (VP8GetCPUInfo(kMIPS32)) {
771
      VP8LEncDspInitMIPS32();
772
    }
773
#endif
774
#if defined(WEBP_USE_MIPS_DSP_R2)
775
    if (VP8GetCPUInfo(kMIPSdspR2)) {
776
      VP8LEncDspInitMIPSdspR2();
777
    }
778
#endif
779
#if defined(WEBP_USE_MSA)
780
    if (VP8GetCPUInfo(kMSA)) {
781
      VP8LEncDspInitMSA();
782
    }
783
#endif
784
0
  }
785
786
#if defined(WEBP_HAVE_NEON)
787
  if (WEBP_NEON_OMIT_C_CODE ||
788
      (VP8GetCPUInfo != NULL && VP8GetCPUInfo(kNEON))) {
789
    VP8LEncDspInitNEON();
790
  }
791
#endif
792
793
0
  assert(VP8LSubtractGreenFromBlueAndRed != NULL);
794
0
  assert(VP8LTransformColor != NULL);
795
0
  assert(VP8LCollectColorBlueTransforms != NULL);
796
0
  assert(VP8LCollectColorRedTransforms != NULL);
797
0
  assert(VP8LFastLog2Slow != NULL);
798
0
  assert(VP8LFastSLog2Slow != NULL);
799
0
  assert(VP8LExtraCost != NULL);
800
0
  assert(VP8LCombinedShannonEntropy != NULL);
801
0
  assert(VP8LShannonEntropy != NULL);
802
0
  assert(VP8LGetEntropyUnrefined != NULL);
803
0
  assert(VP8LGetCombinedEntropyUnrefined != NULL);
804
0
  assert(VP8LAddVector != NULL);
805
0
  assert(VP8LAddVectorEq != NULL);
806
0
  assert(VP8LVectorMismatch != NULL);
807
0
  assert(VP8LBundleColorMap != NULL);
808
0
  assert(VP8LPredictorsSub[0] != NULL);
809
0
  assert(VP8LPredictorsSub[1] != NULL);
810
0
  assert(VP8LPredictorsSub[2] != NULL);
811
0
  assert(VP8LPredictorsSub[3] != NULL);
812
0
  assert(VP8LPredictorsSub[4] != NULL);
813
0
  assert(VP8LPredictorsSub[5] != NULL);
814
0
  assert(VP8LPredictorsSub[6] != NULL);
815
0
  assert(VP8LPredictorsSub[7] != NULL);
816
0
  assert(VP8LPredictorsSub[8] != NULL);
817
0
  assert(VP8LPredictorsSub[9] != NULL);
818
0
  assert(VP8LPredictorsSub[10] != NULL);
819
0
  assert(VP8LPredictorsSub[11] != NULL);
820
0
  assert(VP8LPredictorsSub[12] != NULL);
821
0
  assert(VP8LPredictorsSub[13] != NULL);
822
0
  assert(VP8LPredictorsSub[14] != NULL);
823
0
  assert(VP8LPredictorsSub[15] != NULL);
824
0
  assert(VP8LPredictorsSub_C[0] != NULL);
825
0
  assert(VP8LPredictorsSub_C[1] != NULL);
826
0
  assert(VP8LPredictorsSub_C[2] != NULL);
827
0
  assert(VP8LPredictorsSub_C[3] != NULL);
828
0
  assert(VP8LPredictorsSub_C[4] != NULL);
829
0
  assert(VP8LPredictorsSub_C[5] != NULL);
830
0
  assert(VP8LPredictorsSub_C[6] != NULL);
831
0
  assert(VP8LPredictorsSub_C[7] != NULL);
832
0
  assert(VP8LPredictorsSub_C[8] != NULL);
833
0
  assert(VP8LPredictorsSub_C[9] != NULL);
834
0
  assert(VP8LPredictorsSub_C[10] != NULL);
835
0
  assert(VP8LPredictorsSub_C[11] != NULL);
836
0
  assert(VP8LPredictorsSub_C[12] != NULL);
837
0
  assert(VP8LPredictorsSub_C[13] != NULL);
838
0
  assert(VP8LPredictorsSub_C[14] != NULL);
839
0
  assert(VP8LPredictorsSub_C[15] != NULL);
840
0
}
841
842
//------------------------------------------------------------------------------