/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 | | // lookup table for small values of int*log2(int) * (1 << LOG_2_PRECISION_BITS). |
75 | | // Obtained in Python with: |
76 | | // a=[ "%d"%i if i<(1<<32) else "%dull"%i |
77 | | // for i in [ round((1<<LOG_2_PRECISION_BITS)*math.log2(i)*i) if i |
78 | | // else 0 for i in range(256)]] |
79 | | // print(',\n '.join([','.join(v) for v in batched([i.rjust(15) |
80 | | // for i in a],4)])) |
81 | | const uint64_t kSLog2Table[LOG_LOOKUP_IDX_MAX] = { |
82 | | 0ull, 0ull, 16777216ull, 39886887ull, |
83 | | 67108864ull, 97388723ull, 130105423ull, 164848600ull, |
84 | | 201326592ull, 239321324ull, 278663526ull, 319217973ull, |
85 | | 360874141ull, 403539997ull, 447137711ull, 491600606ull, |
86 | | 536870912ull, 582898099ull, 629637592ull, 677049776ull, |
87 | | 725099212ull, 773754010ull, 822985323ull, 872766924ull, |
88 | | 923074875ull, 973887230ull, 1025183802ull, 1076945958ull, |
89 | | 1129156447ull, 1181799249ull, 1234859451ull, 1288323135ull, |
90 | | 1342177280ull, 1396409681ull, 1451008871ull, 1505964059ull, |
91 | | 1561265072ull, 1616902301ull, 1672866655ull, 1729149526ull, |
92 | | 1785742744ull, 1842638548ull, 1899829557ull, 1957308741ull, |
93 | | 2015069397ull, 2073105127ull, 2131409817ull, 2189977618ull, |
94 | | 2248802933ull, 2307880396ull, 2367204859ull, 2426771383ull, |
95 | | 2486575220ull, 2546611805ull, 2606876748ull, 2667365819ull, |
96 | | 2728074942ull, 2789000187ull, 2850137762ull, 2911484006ull, |
97 | | 2973035382ull, 3034788471ull, 3096739966ull, 3158886666ull, |
98 | | 3221225472ull, 3283753383ull, 3346467489ull, 3409364969ull, |
99 | | 3472443085ull, 3535699182ull, 3599130679ull, 3662735070ull, |
100 | | 3726509920ull, 3790452862ull, 3854561593ull, 3918833872ull, |
101 | | 3983267519ull, 4047860410ull, 4112610476ull, 4177515704ull, |
102 | | 4242574127ull, 4307783833ull, 4373142952ull, 4438649662ull, |
103 | | 4504302186ull, 4570098787ull, 4636037770ull, 4702117480ull, |
104 | | 4768336298ull, 4834692645ull, 4901184974ull, 4967811774ull, |
105 | | 5034571569ull, 5101462912ull, 5168484389ull, 5235634615ull, |
106 | | 5302912235ull, 5370315922ull, 5437844376ull, 5505496324ull, |
107 | | 5573270518ull, 5641165737ull, 5709180782ull, 5777314477ull, |
108 | | 5845565671ull, 5913933235ull, 5982416059ull, 6051013057ull, |
109 | | 6119723161ull, 6188545324ull, 6257478518ull, 6326521733ull, |
110 | | 6395673979ull, 6464934282ull, 6534301685ull, 6603775250ull, |
111 | | 6673354052ull, 6743037185ull, 6812823756ull, 6882712890ull, |
112 | | 6952703725ull, 7022795412ull, 7092987118ull, 7163278025ull, |
113 | | 7233667324ull, 7304154222ull, 7374737939ull, 7445417707ull, |
114 | | 7516192768ull, 7587062379ull, 7658025806ull, 7729082328ull, |
115 | | 7800231234ull, 7871471825ull, 7942803410ull, 8014225311ull, |
116 | | 8085736859ull, 8157337394ull, 8229026267ull, 8300802839ull, |
117 | | 8372666477ull, 8444616560ull, 8516652476ull, 8588773618ull, |
118 | | 8660979393ull, 8733269211ull, 8805642493ull, 8878098667ull, |
119 | | 8950637170ull, 9023257446ull, 9095958945ull, 9168741125ull, |
120 | | 9241603454ull, 9314545403ull, 9387566451ull, 9460666086ull, |
121 | | 9533843800ull, 9607099093ull, 9680431471ull, 9753840445ull, |
122 | | 9827325535ull, 9900886263ull, 9974522161ull, 10048232765ull, |
123 | | 10122017615ull, 10195876260ull, 10269808253ull, 10343813150ull, |
124 | | 10417890516ull, 10492039919ull, 10566260934ull, 10640553138ull, |
125 | | 10714916116ull, 10789349456ull, 10863852751ull, 10938425600ull, |
126 | | 11013067604ull, 11087778372ull, 11162557513ull, 11237404645ull, |
127 | | 11312319387ull, 11387301364ull, 11462350205ull, 11537465541ull, |
128 | | 11612647010ull, 11687894253ull, 11763206912ull, 11838584638ull, |
129 | | 11914027082ull, 11989533899ull, 12065104750ull, 12140739296ull, |
130 | | 12216437206ull, 12292198148ull, 12368021795ull, 12443907826ull, |
131 | | 12519855920ull, 12595865759ull, 12671937032ull, 12748069427ull, |
132 | | 12824262637ull, 12900516358ull, 12976830290ull, 13053204134ull, |
133 | | 13129637595ull, 13206130381ull, 13282682202ull, 13359292772ull, |
134 | | 13435961806ull, 13512689025ull, 13589474149ull, 13666316903ull, |
135 | | 13743217014ull, 13820174211ull, 13897188225ull, 13974258793ull, |
136 | | 14051385649ull, 14128568535ull, 14205807192ull, 14283101363ull, |
137 | | 14360450796ull, 14437855239ull, 14515314443ull, 14592828162ull, |
138 | | 14670396151ull, 14748018167ull, 14825693972ull, 14903423326ull, |
139 | | 14981205995ull, 15059041743ull, 15136930339ull, 15214871554ull, |
140 | | 15292865160ull, 15370910930ull, 15449008641ull, 15527158071ull, |
141 | | 15605359001ull, 15683611210ull, 15761914485ull, 15840268608ull, |
142 | | 15918673369ull, 15997128556ull, 16075633960ull, 16154189373ull, |
143 | | 16232794589ull, 16311449405ull, 16390153617ull, 16468907026ull, |
144 | | 16547709431ull, 16626560636ull, 16705460444ull, 16784408661ull, |
145 | | 16863405094ull, 16942449552ull, 17021541845ull, 17100681785ull}; |
146 | | |
147 | | const VP8LPrefixCode kPrefixEncodeCode[PREFIX_LOOKUP_IDX_MAX] = { |
148 | | {0, 0}, {0, 0}, {1, 0}, {2, 0}, {3, 0}, {4, 1}, {4, 1}, {5, 1}, |
149 | | {5, 1}, {6, 2}, {6, 2}, {6, 2}, {6, 2}, {7, 2}, {7, 2}, {7, 2}, |
150 | | {7, 2}, {8, 3}, {8, 3}, {8, 3}, {8, 3}, {8, 3}, {8, 3}, {8, 3}, |
151 | | {8, 3}, {9, 3}, {9, 3}, {9, 3}, {9, 3}, {9, 3}, {9, 3}, {9, 3}, |
152 | | {9, 3}, {10, 4}, {10, 4}, {10, 4}, {10, 4}, {10, 4}, {10, 4}, {10, 4}, |
153 | | {10, 4}, {10, 4}, {10, 4}, {10, 4}, {10, 4}, {10, 4}, {10, 4}, {10, 4}, |
154 | | {10, 4}, {11, 4}, {11, 4}, {11, 4}, {11, 4}, {11, 4}, {11, 4}, {11, 4}, |
155 | | {11, 4}, {11, 4}, {11, 4}, {11, 4}, {11, 4}, {11, 4}, {11, 4}, {11, 4}, |
156 | | {11, 4}, {12, 5}, {12, 5}, {12, 5}, {12, 5}, {12, 5}, {12, 5}, {12, 5}, |
157 | | {12, 5}, {12, 5}, {12, 5}, {12, 5}, {12, 5}, {12, 5}, {12, 5}, {12, 5}, |
158 | | {12, 5}, {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}, {13, 5}, {13, 5}, {13, 5}, {13, 5}, {13, 5}, {13, 5}, {13, 5}, |
161 | | {13, 5}, {13, 5}, {13, 5}, {13, 5}, {13, 5}, {13, 5}, {13, 5}, {13, 5}, |
162 | | {13, 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}, {14, 6}, {14, 6}, {14, 6}, {14, 6}, {14, 6}, {14, 6}, {14, 6}, |
165 | | {14, 6}, {14, 6}, {14, 6}, {14, 6}, {14, 6}, {14, 6}, {14, 6}, {14, 6}, |
166 | | {14, 6}, {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}, {15, 6}, {15, 6}, {15, 6}, {15, 6}, {15, 6}, {15, 6}, {15, 6}, |
173 | | {15, 6}, {15, 6}, {15, 6}, {15, 6}, {15, 6}, {15, 6}, {15, 6}, {15, 6}, |
174 | | {15, 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}, {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7}, |
181 | | {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7}, {16, 7}, |
182 | | {16, 7}, {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}, {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7}, |
197 | | {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7}, |
198 | | {17, 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 | | }; |
213 | | |
214 | | const uint8_t kPrefixEncodeExtraBitsValue[PREFIX_LOOKUP_IDX_MAX] = { |
215 | | 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 2, 3, 0, 1, |
216 | | 2, 3, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, |
217 | | 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, |
218 | | 12, 13, 14, 15, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, |
219 | | 11, 12, 13, 14, 15, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, |
220 | | 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, |
221 | | 25, 26, 27, 28, 29, 30, 31, 0, 1, 2, 3, 4, 5, 6, 7, |
222 | | 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, |
223 | | 23, 24, 25, 26, 27, 28, 29, 30, 31, 0, 1, 2, 3, 4, 5, |
224 | | 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, |
225 | | 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, |
226 | | 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, |
227 | | 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 0, 1, |
228 | | 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, |
229 | | 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, |
230 | | 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, |
231 | | 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, |
232 | | 62, 63, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, |
233 | | 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, |
234 | | 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, |
235 | | 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, |
236 | | 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, |
237 | | 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, |
238 | | 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, |
239 | | 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, |
240 | | 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 0, 1, 2, 3, 4, |
241 | | 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, |
242 | | 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, |
243 | | 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, |
244 | | 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, |
245 | | 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, |
246 | | 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, |
247 | | 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, |
248 | | 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, |
249 | | 125, 126}; |
250 | | |
251 | 143k | static uint64_t FastSLog2Slow_C(uint32_t v) { |
252 | 143k | assert(v >= LOG_LOOKUP_IDX_MAX); |
253 | 143k | if (v < APPROX_LOG_WITH_CORRECTION_MAX) { |
254 | 97.0k | const uint64_t orig_v = v; |
255 | 97.0k | uint64_t correction; |
256 | 97.0k | #if !defined(WEBP_HAVE_SLOW_CLZ_CTZ) |
257 | | // use clz if available |
258 | 97.0k | const uint64_t log_cnt = BitsLog2Floor(v) - 7; |
259 | 97.0k | const uint32_t y = 1 << log_cnt; |
260 | 97.0k | v >>= log_cnt; |
261 | | #else |
262 | | uint64_t log_cnt = 0; |
263 | | uint32_t y = 1; |
264 | | do { |
265 | | ++log_cnt; |
266 | | v = v >> 1; |
267 | | y = y << 1; |
268 | | } while (v >= LOG_LOOKUP_IDX_MAX); |
269 | | #endif |
270 | | // vf = (2^log_cnt) * Xf; where y = 2^log_cnt and Xf < 256 |
271 | | // Xf = floor(Xf) * (1 + (v % y) / v) |
272 | | // log2(Xf) = log2(floor(Xf)) + log2(1 + (v % y) / v) |
273 | | // The correction factor: log(1 + d) ~ d; for very small d values, so |
274 | | // log2(1 + (v % y) / v) ~ LOG_2_RECIPROCAL * (v % y)/v |
275 | 97.0k | correction = LOG_2_RECIPROCAL_FIXED * (orig_v & (y - 1)); |
276 | 97.0k | return orig_v * (kLog2Table[v] + (log_cnt << LOG_2_PRECISION_BITS)) + |
277 | 97.0k | correction; |
278 | 97.0k | } else { |
279 | 46.6k | return (uint64_t)(LOG_2_RECIPROCAL_FIXED_DOUBLE * v * log((double)v) + .5); |
280 | 46.6k | } |
281 | 143k | } |
282 | | |
283 | 143 | static uint32_t FastLog2Slow_C(uint32_t v) { |
284 | 143 | assert(v >= LOG_LOOKUP_IDX_MAX); |
285 | 143 | if (v < APPROX_LOG_WITH_CORRECTION_MAX) { |
286 | 143 | const uint32_t orig_v = v; |
287 | 143 | uint32_t log_2; |
288 | 143 | #if !defined(WEBP_HAVE_SLOW_CLZ_CTZ) |
289 | | // use clz if available |
290 | 143 | const uint32_t log_cnt = BitsLog2Floor(v) - 7; |
291 | 143 | const uint32_t y = 1 << log_cnt; |
292 | 143 | v >>= log_cnt; |
293 | | #else |
294 | | uint32_t log_cnt = 0; |
295 | | uint32_t y = 1; |
296 | | do { |
297 | | ++log_cnt; |
298 | | v = v >> 1; |
299 | | y = y << 1; |
300 | | } while (v >= LOG_LOOKUP_IDX_MAX); |
301 | | #endif |
302 | 143 | log_2 = kLog2Table[v] + (log_cnt << LOG_2_PRECISION_BITS); |
303 | 143 | if (orig_v >= APPROX_LOG_MAX) { |
304 | | // Since the division is still expensive, add this correction factor only |
305 | | // for large values of 'v'. |
306 | 17 | const uint64_t correction = LOG_2_RECIPROCAL_FIXED * (orig_v & (y - 1)); |
307 | 17 | log_2 += (uint32_t)DivRound(correction, orig_v); |
308 | 17 | } |
309 | 143 | return log_2; |
310 | 143 | } else { |
311 | 0 | return (uint32_t)(LOG_2_RECIPROCAL_FIXED_DOUBLE * log((double)v) + .5); |
312 | 0 | } |
313 | 143 | } |
314 | | |
315 | | //------------------------------------------------------------------------------ |
316 | | // Methods to calculate Entropy (Shannon). |
317 | | |
318 | | // Compute the combined Shanon's entropy for distribution {X} and {X+Y} |
319 | | static uint64_t CombinedShannonEntropy_C(const uint32_t X[256], |
320 | 0 | const uint32_t Y[256]) { |
321 | 0 | int i; |
322 | 0 | uint64_t retval = 0; |
323 | 0 | uint32_t sumX = 0, sumXY = 0; |
324 | 0 | for (i = 0; i < 256; ++i) { |
325 | 0 | const uint32_t x = X[i]; |
326 | 0 | if (x != 0) { |
327 | 0 | const uint32_t xy = x + Y[i]; |
328 | 0 | sumX += x; |
329 | 0 | retval += VP8LFastSLog2(x); |
330 | 0 | sumXY += xy; |
331 | 0 | retval += VP8LFastSLog2(xy); |
332 | 0 | } else if (Y[i] != 0) { |
333 | 0 | sumXY += Y[i]; |
334 | 0 | retval += VP8LFastSLog2(Y[i]); |
335 | 0 | } |
336 | 0 | } |
337 | 0 | retval = VP8LFastSLog2(sumX) + VP8LFastSLog2(sumXY) - retval; |
338 | 0 | return retval; |
339 | 0 | } |
340 | | |
341 | 25 | static uint64_t ShannonEntropy_C(const uint32_t* X, int n) { |
342 | 25 | int i; |
343 | 25 | uint64_t retval = 0; |
344 | 25 | uint32_t sumX = 0; |
345 | 5.21k | for (i = 0; i < n; ++i) { |
346 | 5.19k | const int x = X[i]; |
347 | 5.19k | if (x != 0) { |
348 | 366 | sumX += x; |
349 | 366 | retval += VP8LFastSLog2(x); |
350 | 366 | } |
351 | 5.19k | } |
352 | 25 | retval = VP8LFastSLog2(sumX) - retval; |
353 | 25 | return retval; |
354 | 25 | } |
355 | | |
356 | 40.1k | void VP8LBitEntropyInit(VP8LBitEntropy* const entropy) { |
357 | 40.1k | entropy->entropy = 0; |
358 | 40.1k | entropy->sum = 0; |
359 | 40.1k | entropy->nonzeros = 0; |
360 | 40.1k | entropy->max_val = 0; |
361 | 40.1k | entropy->nonzero_code = VP8L_NON_TRIVIAL_SYM; |
362 | 40.1k | } |
363 | | |
364 | | void VP8LBitsEntropyUnrefined(const uint32_t* WEBP_RESTRICT const array, int n, |
365 | 182 | VP8LBitEntropy* WEBP_RESTRICT const entropy) { |
366 | 182 | int i; |
367 | | |
368 | 182 | VP8LBitEntropyInit(entropy); |
369 | | |
370 | 46.7k | for (i = 0; i < n; ++i) { |
371 | 46.5k | if (array[i] != 0) { |
372 | 8.46k | entropy->sum += array[i]; |
373 | 8.46k | entropy->nonzero_code = i; |
374 | 8.46k | ++entropy->nonzeros; |
375 | 8.46k | entropy->entropy += VP8LFastSLog2(array[i]); |
376 | 8.46k | if (entropy->max_val < array[i]) { |
377 | 459 | entropy->max_val = array[i]; |
378 | 459 | } |
379 | 8.46k | } |
380 | 46.5k | } |
381 | 182 | entropy->entropy = VP8LFastSLog2(entropy->sum) - entropy->entropy; |
382 | 182 | } |
383 | | |
384 | | static WEBP_INLINE void GetEntropyUnrefinedHelper( |
385 | | uint32_t val, int i, uint32_t* WEBP_RESTRICT const val_prev, |
386 | | int* WEBP_RESTRICT const i_prev, |
387 | | VP8LBitEntropy* WEBP_RESTRICT const bit_entropy, |
388 | 1.22M | VP8LStreaks* WEBP_RESTRICT const stats) { |
389 | 1.22M | const int streak = i - *i_prev; |
390 | | |
391 | | // Gather info for the bit entropy. |
392 | 1.22M | if (*val_prev != 0) { |
393 | 791k | bit_entropy->sum += (*val_prev) * streak; |
394 | 791k | bit_entropy->nonzeros += streak; |
395 | 791k | bit_entropy->nonzero_code = *i_prev; |
396 | 791k | bit_entropy->entropy += VP8LFastSLog2(*val_prev) * streak; |
397 | 791k | if (bit_entropy->max_val < *val_prev) { |
398 | 79.0k | bit_entropy->max_val = *val_prev; |
399 | 79.0k | } |
400 | 791k | } |
401 | | |
402 | | // Gather info for the Huffman cost. |
403 | 1.22M | stats->counts[*val_prev != 0] += (streak > 3); |
404 | 1.22M | stats->streaks[*val_prev != 0][(streak > 3)] += streak; |
405 | | |
406 | 1.22M | *val_prev = val; |
407 | 1.22M | *i_prev = i; |
408 | 1.22M | } |
409 | | |
410 | | static void GetEntropyUnrefined_C( |
411 | | const uint32_t X[], int length, |
412 | | VP8LBitEntropy* WEBP_RESTRICT const bit_entropy, |
413 | 25.1k | VP8LStreaks* WEBP_RESTRICT const stats) { |
414 | 25.1k | int i; |
415 | 25.1k | int i_prev = 0; |
416 | 25.1k | uint32_t x_prev = X[0]; |
417 | | |
418 | 25.1k | memset(stats, 0, sizeof(*stats)); |
419 | 25.1k | VP8LBitEntropyInit(bit_entropy); |
420 | | |
421 | 5.53M | for (i = 1; i < length; ++i) { |
422 | 5.51M | const uint32_t x = X[i]; |
423 | 5.51M | if (x != x_prev) { |
424 | 94.6k | GetEntropyUnrefinedHelper(x, i, &x_prev, &i_prev, bit_entropy, stats); |
425 | 94.6k | } |
426 | 5.51M | } |
427 | 25.1k | GetEntropyUnrefinedHelper(0, i, &x_prev, &i_prev, bit_entropy, stats); |
428 | | |
429 | 25.1k | bit_entropy->entropy = VP8LFastSLog2(bit_entropy->sum) - bit_entropy->entropy; |
430 | 25.1k | } |
431 | | |
432 | | static void GetCombinedEntropyUnrefined_C( |
433 | | const uint32_t X[], const uint32_t Y[], int length, |
434 | | VP8LBitEntropy* WEBP_RESTRICT const bit_entropy, |
435 | 14.8k | VP8LStreaks* WEBP_RESTRICT const stats) { |
436 | 14.8k | int i = 1; |
437 | 14.8k | int i_prev = 0; |
438 | 14.8k | uint32_t xy_prev = X[0] + Y[0]; |
439 | | |
440 | 14.8k | memset(stats, 0, sizeof(*stats)); |
441 | 14.8k | VP8LBitEntropyInit(bit_entropy); |
442 | | |
443 | 3.15M | for (i = 1; i < length; ++i) { |
444 | 3.14M | const uint32_t xy = X[i] + Y[i]; |
445 | 3.14M | if (xy != xy_prev) { |
446 | 1.09M | GetEntropyUnrefinedHelper(xy, i, &xy_prev, &i_prev, bit_entropy, stats); |
447 | 1.09M | } |
448 | 3.14M | } |
449 | 14.8k | GetEntropyUnrefinedHelper(0, i, &xy_prev, &i_prev, bit_entropy, stats); |
450 | | |
451 | 14.8k | bit_entropy->entropy = VP8LFastSLog2(bit_entropy->sum) - bit_entropy->entropy; |
452 | 14.8k | } |
453 | | |
454 | | //------------------------------------------------------------------------------ |
455 | | |
456 | 0 | void VP8LSubtractGreenFromBlueAndRed_C(uint32_t* argb_data, int num_pixels) { |
457 | 0 | int i; |
458 | 0 | for (i = 0; i < num_pixels; ++i) { |
459 | 0 | const int argb = (int)argb_data[i]; |
460 | 0 | const int green = (argb >> 8) & 0xff; |
461 | 0 | const uint32_t new_r = (((argb >> 16) & 0xff) - green) & 0xff; |
462 | 0 | const uint32_t new_b = (((argb >> 0) & 0xff) - green) & 0xff; |
463 | 0 | argb_data[i] = ((uint32_t)argb & 0xff00ff00u) | (new_r << 16) | new_b; |
464 | 0 | } |
465 | 0 | } |
466 | | |
467 | 2.30k | static WEBP_INLINE int ColorTransformDelta(int8_t color_pred, int8_t color) { |
468 | 2.30k | return ((int)color_pred * color) >> 5; |
469 | 2.30k | } |
470 | | |
471 | 2.29k | static WEBP_INLINE int8_t U32ToS8(uint32_t v) { return (int8_t)(v & 0xff); } |
472 | | |
473 | | void VP8LTransformColor_C(const VP8LMultipliers* WEBP_RESTRICT const m, |
474 | 18 | uint32_t* WEBP_RESTRICT data, int num_pixels) { |
475 | 18 | int i; |
476 | 36 | for (i = 0; i < num_pixels; ++i) { |
477 | 18 | const uint32_t argb = data[i]; |
478 | 18 | const int8_t green = U32ToS8(argb >> 8); |
479 | 18 | const int8_t red = U32ToS8(argb >> 16); |
480 | 18 | int new_red = red & 0xff; |
481 | 18 | int new_blue = argb & 0xff; |
482 | 18 | new_red -= ColorTransformDelta((int8_t)m->green_to_red, green); |
483 | 18 | new_red &= 0xff; |
484 | 18 | new_blue -= ColorTransformDelta((int8_t)m->green_to_blue, green); |
485 | 18 | new_blue -= ColorTransformDelta((int8_t)m->red_to_blue, red); |
486 | 18 | new_blue &= 0xff; |
487 | 18 | data[i] = (argb & 0xff00ff00u) | (new_red << 16) | (new_blue); |
488 | 18 | } |
489 | 18 | } |
490 | | |
491 | | static WEBP_INLINE uint8_t TransformColorRed(uint8_t green_to_red, |
492 | 234 | uint32_t argb) { |
493 | 234 | const int8_t green = U32ToS8(argb >> 8); |
494 | 234 | int new_red = argb >> 16; |
495 | 234 | new_red -= ColorTransformDelta((int8_t)green_to_red, green); |
496 | 234 | return (new_red & 0xff); |
497 | 234 | } |
498 | | |
499 | | static WEBP_INLINE uint8_t TransformColorBlue(uint8_t green_to_blue, |
500 | | uint8_t red_to_blue, |
501 | 1.01k | uint32_t argb) { |
502 | 1.01k | const int8_t green = U32ToS8(argb >> 8); |
503 | 1.01k | const int8_t red = U32ToS8(argb >> 16); |
504 | 1.01k | int new_blue = argb & 0xff; |
505 | 1.01k | new_blue -= ColorTransformDelta((int8_t)green_to_blue, green); |
506 | 1.01k | new_blue -= ColorTransformDelta((int8_t)red_to_blue, red); |
507 | 1.01k | return (new_blue & 0xff); |
508 | 1.01k | } |
509 | | |
510 | | void VP8LCollectColorRedTransforms_C(const uint32_t* WEBP_RESTRICT argb, |
511 | | int stride, int tile_width, |
512 | | int tile_height, int green_to_red, |
513 | 52 | uint32_t histo[]) { |
514 | 286 | while (tile_height-- > 0) { |
515 | 234 | int x; |
516 | 468 | for (x = 0; x < tile_width; ++x) { |
517 | 234 | ++histo[TransformColorRed((uint8_t)green_to_red, argb[x])]; |
518 | 234 | } |
519 | 234 | argb += stride; |
520 | 234 | } |
521 | 52 | } |
522 | | |
523 | | void VP8LCollectColorBlueTransforms_C(const uint32_t* WEBP_RESTRICT argb, |
524 | | int stride, int tile_width, |
525 | | int tile_height, int green_to_blue, |
526 | 212 | int red_to_blue, uint32_t histo[]) { |
527 | 1.22k | while (tile_height-- > 0) { |
528 | 1.01k | int x; |
529 | 2.02k | for (x = 0; x < tile_width; ++x) { |
530 | 1.01k | ++histo[TransformColorBlue((uint8_t)green_to_blue, (uint8_t)red_to_blue, |
531 | 1.01k | argb[x])]; |
532 | 1.01k | } |
533 | 1.01k | argb += stride; |
534 | 1.01k | } |
535 | 212 | } |
536 | | |
537 | | //------------------------------------------------------------------------------ |
538 | | |
539 | | static int VectorMismatch_C(const uint32_t* const array1, |
540 | 0 | const uint32_t* const array2, int length) { |
541 | 0 | int match_len = 0; |
542 | |
|
543 | 0 | while (match_len < length && array1[match_len] == array2[match_len]) { |
544 | 0 | ++match_len; |
545 | 0 | } |
546 | 0 | return match_len; |
547 | 0 | } |
548 | | |
549 | | // Bundles multiple (1, 2, 4 or 8) pixels into a single pixel. |
550 | | void VP8LBundleColorMap_C(const uint8_t* WEBP_RESTRICT const row, int width, |
551 | 5.17k | int xbits, uint32_t* WEBP_RESTRICT dst) { |
552 | 5.17k | int x; |
553 | 5.17k | if (xbits > 0) { |
554 | 5.17k | const int bit_depth = 1 << (3 - xbits); |
555 | 5.17k | const int mask = (1 << xbits) - 1; |
556 | 5.17k | uint32_t code = 0xff000000; |
557 | 34.7k | for (x = 0; x < width; ++x) { |
558 | 29.5k | const int xsub = x & mask; |
559 | 29.5k | if (xsub == 0) { |
560 | 14.5k | code = 0xff000000; |
561 | 14.5k | } |
562 | 29.5k | code |= row[x] << (8 + bit_depth * xsub); |
563 | 29.5k | dst[x >> xbits] = code; |
564 | 29.5k | } |
565 | 5.17k | } else { |
566 | 0 | for (x = 0; x < width; ++x) dst[x] = 0xff000000 | (row[x] << 8); |
567 | 0 | } |
568 | 5.17k | } |
569 | | |
570 | | //------------------------------------------------------------------------------ |
571 | | |
572 | 0 | static uint32_t ExtraCost_C(const uint32_t* population, int length) { |
573 | 0 | int i; |
574 | 0 | uint32_t cost = population[4] + population[5]; |
575 | 0 | assert(length % 2 == 0); |
576 | 0 | for (i = 2; i < length / 2 - 1; ++i) { |
577 | 0 | cost += i * (population[2 * i + 2] + population[2 * i + 3]); |
578 | 0 | } |
579 | 0 | return cost; |
580 | 0 | } |
581 | | |
582 | | //------------------------------------------------------------------------------ |
583 | | |
584 | | static void AddVector_C(const uint32_t* WEBP_RESTRICT a, |
585 | | const uint32_t* WEBP_RESTRICT b, |
586 | 0 | uint32_t* WEBP_RESTRICT out, int size) { |
587 | 0 | int i; |
588 | 0 | for (i = 0; i < size; ++i) out[i] = a[i] + b[i]; |
589 | 0 | } |
590 | | |
591 | | static void AddVectorEq_C(const uint32_t* WEBP_RESTRICT a, |
592 | 0 | uint32_t* WEBP_RESTRICT out, int size) { |
593 | 0 | int i; |
594 | 0 | for (i = 0; i < size; ++i) out[i] += a[i]; |
595 | 0 | } |
596 | | |
597 | | //------------------------------------------------------------------------------ |
598 | | // Image transforms. |
599 | | |
600 | | static void PredictorSub0_C(const uint32_t* in, const uint32_t* upper, |
601 | 1.16k | int num_pixels, uint32_t* WEBP_RESTRICT out) { |
602 | 1.16k | int i; |
603 | 4.56k | for (i = 0; i < num_pixels; ++i) out[i] = VP8LSubPixels(in[i], ARGB_BLACK); |
604 | 1.16k | (void)upper; |
605 | 1.16k | } |
606 | | |
607 | | static void PredictorSub1_C(const uint32_t* in, const uint32_t* upper, |
608 | 1.19k | int num_pixels, uint32_t* WEBP_RESTRICT out) { |
609 | 1.19k | int i; |
610 | 4.77k | for (i = 0; i < num_pixels; ++i) out[i] = VP8LSubPixels(in[i], in[i - 1]); |
611 | 1.19k | (void)upper; |
612 | 1.19k | } |
613 | | |
614 | | // It subtracts the prediction from the input pixel and stores the residual |
615 | | // in the output pixel. |
616 | | #define GENERATE_PREDICTOR_SUB(PREDICTOR_I) \ |
617 | | static void PredictorSub##PREDICTOR_I##_C( \ |
618 | | const uint32_t* in, const uint32_t* upper, int num_pixels, \ |
619 | 23.6k | uint32_t* WEBP_RESTRICT out) { \ |
620 | 23.6k | int x; \ |
621 | 23.6k | assert(upper != NULL); \ |
622 | 76.4k | for (x = 0; x < num_pixels; ++x) { \ |
623 | 52.7k | const uint32_t pred = \ |
624 | 52.7k | VP8LPredictor##PREDICTOR_I##_C(&in[x - 1], upper + x); \ |
625 | 52.7k | out[x] = VP8LSubPixels(in[x], pred); \ |
626 | 52.7k | } \ |
627 | 23.6k | } lossless_enc.c:PredictorSub2_C Line | Count | Source | 619 | 10.3k | uint32_t* WEBP_RESTRICT out) { \ | 620 | 10.3k | int x; \ | 621 | 10.3k | assert(upper != NULL); \ | 622 | 23.1k | for (x = 0; x < num_pixels; ++x) { \ | 623 | 12.7k | const uint32_t pred = \ | 624 | 12.7k | VP8LPredictor##PREDICTOR_I##_C(&in[x - 1], upper + x); \ | 625 | 12.7k | out[x] = VP8LSubPixels(in[x], pred); \ | 626 | 12.7k | } \ | 627 | 10.3k | } |
lossless_enc.c:PredictorSub3_C Line | Count | Source | 619 | 1.11k | uint32_t* WEBP_RESTRICT out) { \ | 620 | 1.11k | int x; \ | 621 | 1.11k | assert(upper != NULL); \ | 622 | 4.47k | for (x = 0; x < num_pixels; ++x) { \ | 623 | 3.35k | const uint32_t pred = \ | 624 | 3.35k | VP8LPredictor##PREDICTOR_I##_C(&in[x - 1], upper + x); \ | 625 | 3.35k | out[x] = VP8LSubPixels(in[x], pred); \ | 626 | 3.35k | } \ | 627 | 1.11k | } |
lossless_enc.c:PredictorSub4_C Line | Count | Source | 619 | 1.11k | uint32_t* WEBP_RESTRICT out) { \ | 620 | 1.11k | int x; \ | 621 | 1.11k | assert(upper != NULL); \ | 622 | 4.47k | for (x = 0; x < num_pixels; ++x) { \ | 623 | 3.35k | const uint32_t pred = \ | 624 | 3.35k | VP8LPredictor##PREDICTOR_I##_C(&in[x - 1], upper + x); \ | 625 | 3.35k | out[x] = VP8LSubPixels(in[x], pred); \ | 626 | 3.35k | } \ | 627 | 1.11k | } |
lossless_enc.c:PredictorSub5_C Line | Count | Source | 619 | 1.11k | uint32_t* WEBP_RESTRICT out) { \ | 620 | 1.11k | int x; \ | 621 | 1.11k | assert(upper != NULL); \ | 622 | 4.47k | for (x = 0; x < num_pixels; ++x) { \ | 623 | 3.35k | const uint32_t pred = \ | 624 | 3.35k | VP8LPredictor##PREDICTOR_I##_C(&in[x - 1], upper + x); \ | 625 | 3.35k | out[x] = VP8LSubPixels(in[x], pred); \ | 626 | 3.35k | } \ | 627 | 1.11k | } |
lossless_enc.c:PredictorSub6_C Line | Count | Source | 619 | 1.11k | uint32_t* WEBP_RESTRICT out) { \ | 620 | 1.11k | int x; \ | 621 | 1.11k | assert(upper != NULL); \ | 622 | 4.47k | for (x = 0; x < num_pixels; ++x) { \ | 623 | 3.35k | const uint32_t pred = \ | 624 | 3.35k | VP8LPredictor##PREDICTOR_I##_C(&in[x - 1], upper + x); \ | 625 | 3.35k | out[x] = VP8LSubPixels(in[x], pred); \ | 626 | 3.35k | } \ | 627 | 1.11k | } |
lossless_enc.c:PredictorSub7_C Line | Count | Source | 619 | 1.11k | uint32_t* WEBP_RESTRICT out) { \ | 620 | 1.11k | int x; \ | 621 | 1.11k | assert(upper != NULL); \ | 622 | 4.47k | for (x = 0; x < num_pixels; ++x) { \ | 623 | 3.35k | const uint32_t pred = \ | 624 | 3.35k | VP8LPredictor##PREDICTOR_I##_C(&in[x - 1], upper + x); \ | 625 | 3.35k | out[x] = VP8LSubPixels(in[x], pred); \ | 626 | 3.35k | } \ | 627 | 1.11k | } |
lossless_enc.c:PredictorSub8_C Line | Count | Source | 619 | 1.11k | uint32_t* WEBP_RESTRICT out) { \ | 620 | 1.11k | int x; \ | 621 | 1.11k | assert(upper != NULL); \ | 622 | 4.47k | for (x = 0; x < num_pixels; ++x) { \ | 623 | 3.35k | const uint32_t pred = \ | 624 | 3.35k | VP8LPredictor##PREDICTOR_I##_C(&in[x - 1], upper + x); \ | 625 | 3.35k | out[x] = VP8LSubPixels(in[x], pred); \ | 626 | 3.35k | } \ | 627 | 1.11k | } |
lossless_enc.c:PredictorSub9_C Line | Count | Source | 619 | 1.11k | uint32_t* WEBP_RESTRICT out) { \ | 620 | 1.11k | int x; \ | 621 | 1.11k | assert(upper != NULL); \ | 622 | 4.47k | for (x = 0; x < num_pixels; ++x) { \ | 623 | 3.35k | const uint32_t pred = \ | 624 | 3.35k | VP8LPredictor##PREDICTOR_I##_C(&in[x - 1], upper + x); \ | 625 | 3.35k | out[x] = VP8LSubPixels(in[x], pred); \ | 626 | 3.35k | } \ | 627 | 1.11k | } |
lossless_enc.c:PredictorSub10_C Line | Count | Source | 619 | 1.11k | uint32_t* WEBP_RESTRICT out) { \ | 620 | 1.11k | int x; \ | 621 | 1.11k | assert(upper != NULL); \ | 622 | 4.47k | for (x = 0; x < num_pixels; ++x) { \ | 623 | 3.35k | const uint32_t pred = \ | 624 | 3.35k | VP8LPredictor##PREDICTOR_I##_C(&in[x - 1], upper + x); \ | 625 | 3.35k | out[x] = VP8LSubPixels(in[x], pred); \ | 626 | 3.35k | } \ | 627 | 1.11k | } |
lossless_enc.c:PredictorSub11_C Line | Count | Source | 619 | 1.11k | uint32_t* WEBP_RESTRICT out) { \ | 620 | 1.11k | int x; \ | 621 | 1.11k | assert(upper != NULL); \ | 622 | 4.47k | for (x = 0; x < num_pixels; ++x) { \ | 623 | 3.35k | const uint32_t pred = \ | 624 | 3.35k | VP8LPredictor##PREDICTOR_I##_C(&in[x - 1], upper + x); \ | 625 | 3.35k | out[x] = VP8LSubPixels(in[x], pred); \ | 626 | 3.35k | } \ | 627 | 1.11k | } |
lossless_enc.c:PredictorSub12_C Line | Count | Source | 619 | 2.13k | uint32_t* WEBP_RESTRICT out) { \ | 620 | 2.13k | int x; \ | 621 | 2.13k | assert(upper != NULL); \ | 622 | 8.55k | for (x = 0; x < num_pixels; ++x) { \ | 623 | 6.41k | const uint32_t pred = \ | 624 | 6.41k | VP8LPredictor##PREDICTOR_I##_C(&in[x - 1], upper + x); \ | 625 | 6.41k | out[x] = VP8LSubPixels(in[x], pred); \ | 626 | 6.41k | } \ | 627 | 2.13k | } |
lossless_enc.c:PredictorSub13_C Line | Count | Source | 619 | 1.11k | uint32_t* WEBP_RESTRICT out) { \ | 620 | 1.11k | int x; \ | 621 | 1.11k | assert(upper != NULL); \ | 622 | 4.47k | for (x = 0; x < num_pixels; ++x) { \ | 623 | 3.35k | const uint32_t pred = \ | 624 | 3.35k | VP8LPredictor##PREDICTOR_I##_C(&in[x - 1], upper + x); \ | 625 | 3.35k | out[x] = VP8LSubPixels(in[x], pred); \ | 626 | 3.35k | } \ | 627 | 1.11k | } |
|
628 | | |
629 | | GENERATE_PREDICTOR_SUB(2) |
630 | | GENERATE_PREDICTOR_SUB(3) |
631 | | GENERATE_PREDICTOR_SUB(4) |
632 | | GENERATE_PREDICTOR_SUB(5) |
633 | | GENERATE_PREDICTOR_SUB(6) |
634 | | GENERATE_PREDICTOR_SUB(7) |
635 | | GENERATE_PREDICTOR_SUB(8) |
636 | | GENERATE_PREDICTOR_SUB(9) |
637 | | GENERATE_PREDICTOR_SUB(10) |
638 | | GENERATE_PREDICTOR_SUB(11) |
639 | | GENERATE_PREDICTOR_SUB(12) |
640 | | GENERATE_PREDICTOR_SUB(13) |
641 | | |
642 | | //------------------------------------------------------------------------------ |
643 | | |
644 | | VP8LProcessEncBlueAndRedFunc VP8LSubtractGreenFromBlueAndRed; |
645 | | VP8LProcessEncBlueAndRedFunc VP8LSubtractGreenFromBlueAndRed_SSE; |
646 | | |
647 | | VP8LTransformColorFunc VP8LTransformColor; |
648 | | VP8LTransformColorFunc VP8LTransformColor_SSE; |
649 | | |
650 | | VP8LCollectColorBlueTransformsFunc VP8LCollectColorBlueTransforms; |
651 | | VP8LCollectColorBlueTransformsFunc VP8LCollectColorBlueTransforms_SSE; |
652 | | VP8LCollectColorRedTransformsFunc VP8LCollectColorRedTransforms; |
653 | | VP8LCollectColorRedTransformsFunc VP8LCollectColorRedTransforms_SSE; |
654 | | |
655 | | VP8LFastLog2SlowFunc VP8LFastLog2Slow; |
656 | | VP8LFastSLog2SlowFunc VP8LFastSLog2Slow; |
657 | | |
658 | | VP8LCostFunc VP8LExtraCost; |
659 | | VP8LCombinedShannonEntropyFunc VP8LCombinedShannonEntropy; |
660 | | VP8LShannonEntropyFunc VP8LShannonEntropy; |
661 | | |
662 | | VP8LGetEntropyUnrefinedFunc VP8LGetEntropyUnrefined; |
663 | | VP8LGetCombinedEntropyUnrefinedFunc VP8LGetCombinedEntropyUnrefined; |
664 | | |
665 | | VP8LAddVectorFunc VP8LAddVector; |
666 | | VP8LAddVectorEqFunc VP8LAddVectorEq; |
667 | | |
668 | | VP8LVectorMismatchFunc VP8LVectorMismatch; |
669 | | VP8LBundleColorMapFunc VP8LBundleColorMap; |
670 | | VP8LBundleColorMapFunc VP8LBundleColorMap_SSE; |
671 | | |
672 | | VP8LPredictorAddSubFunc VP8LPredictorsSub[16]; |
673 | | VP8LPredictorAddSubFunc VP8LPredictorsSub_C[16]; |
674 | | VP8LPredictorAddSubFunc VP8LPredictorsSub_SSE[16]; |
675 | | |
676 | | extern VP8CPUInfo VP8GetCPUInfo; |
677 | | extern void VP8LEncDspInitSSE2(void); |
678 | | extern void VP8LEncDspInitSSE41(void); |
679 | | extern void VP8LEncDspInitAVX2(void); |
680 | | extern void VP8LEncDspInitNEON(void); |
681 | | extern void VP8LEncDspInitMIPS32(void); |
682 | | extern void VP8LEncDspInitMIPSdspR2(void); |
683 | | extern void VP8LEncDspInitMSA(void); |
684 | | |
685 | 1 | WEBP_DSP_INIT_FUNC(VP8LEncDspInit) { |
686 | 1 | VP8LDspInit(); |
687 | | |
688 | 1 | #if !WEBP_NEON_OMIT_C_CODE |
689 | 1 | VP8LSubtractGreenFromBlueAndRed = VP8LSubtractGreenFromBlueAndRed_C; |
690 | | |
691 | 1 | VP8LTransformColor = VP8LTransformColor_C; |
692 | 1 | #endif |
693 | | |
694 | 1 | VP8LCollectColorBlueTransforms = VP8LCollectColorBlueTransforms_C; |
695 | 1 | VP8LCollectColorRedTransforms = VP8LCollectColorRedTransforms_C; |
696 | | |
697 | 1 | VP8LFastLog2Slow = FastLog2Slow_C; |
698 | 1 | VP8LFastSLog2Slow = FastSLog2Slow_C; |
699 | | |
700 | 1 | VP8LExtraCost = ExtraCost_C; |
701 | 1 | VP8LCombinedShannonEntropy = CombinedShannonEntropy_C; |
702 | 1 | VP8LShannonEntropy = ShannonEntropy_C; |
703 | | |
704 | 1 | VP8LGetEntropyUnrefined = GetEntropyUnrefined_C; |
705 | 1 | VP8LGetCombinedEntropyUnrefined = GetCombinedEntropyUnrefined_C; |
706 | | |
707 | 1 | VP8LAddVector = AddVector_C; |
708 | 1 | VP8LAddVectorEq = AddVectorEq_C; |
709 | | |
710 | 1 | VP8LVectorMismatch = VectorMismatch_C; |
711 | 1 | VP8LBundleColorMap = VP8LBundleColorMap_C; |
712 | | |
713 | 1 | VP8LPredictorsSub[0] = PredictorSub0_C; |
714 | 1 | VP8LPredictorsSub[1] = PredictorSub1_C; |
715 | 1 | VP8LPredictorsSub[2] = PredictorSub2_C; |
716 | 1 | VP8LPredictorsSub[3] = PredictorSub3_C; |
717 | 1 | VP8LPredictorsSub[4] = PredictorSub4_C; |
718 | 1 | VP8LPredictorsSub[5] = PredictorSub5_C; |
719 | 1 | VP8LPredictorsSub[6] = PredictorSub6_C; |
720 | 1 | VP8LPredictorsSub[7] = PredictorSub7_C; |
721 | 1 | VP8LPredictorsSub[8] = PredictorSub8_C; |
722 | 1 | VP8LPredictorsSub[9] = PredictorSub9_C; |
723 | 1 | VP8LPredictorsSub[10] = PredictorSub10_C; |
724 | 1 | VP8LPredictorsSub[11] = PredictorSub11_C; |
725 | 1 | VP8LPredictorsSub[12] = PredictorSub12_C; |
726 | 1 | VP8LPredictorsSub[13] = PredictorSub13_C; |
727 | 1 | VP8LPredictorsSub[14] = PredictorSub0_C; // <- padding security sentinels |
728 | 1 | VP8LPredictorsSub[15] = PredictorSub0_C; |
729 | | |
730 | 1 | VP8LPredictorsSub_C[0] = PredictorSub0_C; |
731 | 1 | VP8LPredictorsSub_C[1] = PredictorSub1_C; |
732 | 1 | VP8LPredictorsSub_C[2] = PredictorSub2_C; |
733 | 1 | VP8LPredictorsSub_C[3] = PredictorSub3_C; |
734 | 1 | VP8LPredictorsSub_C[4] = PredictorSub4_C; |
735 | 1 | VP8LPredictorsSub_C[5] = PredictorSub5_C; |
736 | 1 | VP8LPredictorsSub_C[6] = PredictorSub6_C; |
737 | 1 | VP8LPredictorsSub_C[7] = PredictorSub7_C; |
738 | 1 | VP8LPredictorsSub_C[8] = PredictorSub8_C; |
739 | 1 | VP8LPredictorsSub_C[9] = PredictorSub9_C; |
740 | 1 | VP8LPredictorsSub_C[10] = PredictorSub10_C; |
741 | 1 | VP8LPredictorsSub_C[11] = PredictorSub11_C; |
742 | 1 | VP8LPredictorsSub_C[12] = PredictorSub12_C; |
743 | 1 | VP8LPredictorsSub_C[13] = PredictorSub13_C; |
744 | 1 | VP8LPredictorsSub_C[14] = PredictorSub0_C; // <- padding security sentinels |
745 | 1 | VP8LPredictorsSub_C[15] = PredictorSub0_C; |
746 | | |
747 | | // If defined, use CPUInfo() to overwrite some pointers with faster versions. |
748 | 1 | if (VP8GetCPUInfo != NULL) { |
749 | 1 | #if defined(WEBP_HAVE_SSE2) |
750 | 1 | if (VP8GetCPUInfo(kSSE2)) { |
751 | 1 | VP8LEncDspInitSSE2(); |
752 | 1 | #if defined(WEBP_HAVE_SSE41) |
753 | 1 | if (VP8GetCPUInfo(kSSE4_1)) { |
754 | 1 | VP8LEncDspInitSSE41(); |
755 | | #if defined(WEBP_HAVE_AVX2) |
756 | | if (VP8GetCPUInfo(kAVX2)) { |
757 | | VP8LEncDspInitAVX2(); |
758 | | } |
759 | | #endif |
760 | 1 | } |
761 | 1 | #endif |
762 | 1 | } |
763 | 1 | #endif |
764 | | #if defined(WEBP_USE_MIPS32) |
765 | | if (VP8GetCPUInfo(kMIPS32)) { |
766 | | VP8LEncDspInitMIPS32(); |
767 | | } |
768 | | #endif |
769 | | #if defined(WEBP_USE_MIPS_DSP_R2) |
770 | | if (VP8GetCPUInfo(kMIPSdspR2)) { |
771 | | VP8LEncDspInitMIPSdspR2(); |
772 | | } |
773 | | #endif |
774 | | #if defined(WEBP_USE_MSA) |
775 | | if (VP8GetCPUInfo(kMSA)) { |
776 | | VP8LEncDspInitMSA(); |
777 | | } |
778 | | #endif |
779 | 1 | } |
780 | | |
781 | | #if defined(WEBP_HAVE_NEON) |
782 | | if (WEBP_NEON_OMIT_C_CODE || |
783 | | (VP8GetCPUInfo != NULL && VP8GetCPUInfo(kNEON))) { |
784 | | VP8LEncDspInitNEON(); |
785 | | } |
786 | | #endif |
787 | | |
788 | 1 | assert(VP8LSubtractGreenFromBlueAndRed != NULL); |
789 | 1 | assert(VP8LTransformColor != NULL); |
790 | 1 | assert(VP8LCollectColorBlueTransforms != NULL); |
791 | 1 | assert(VP8LCollectColorRedTransforms != NULL); |
792 | 1 | assert(VP8LFastLog2Slow != NULL); |
793 | 1 | assert(VP8LFastSLog2Slow != NULL); |
794 | 1 | assert(VP8LExtraCost != NULL); |
795 | 1 | assert(VP8LCombinedShannonEntropy != NULL); |
796 | 1 | assert(VP8LShannonEntropy != NULL); |
797 | 1 | assert(VP8LGetEntropyUnrefined != NULL); |
798 | 1 | assert(VP8LGetCombinedEntropyUnrefined != NULL); |
799 | 1 | assert(VP8LAddVector != NULL); |
800 | 1 | assert(VP8LAddVectorEq != NULL); |
801 | 1 | assert(VP8LVectorMismatch != NULL); |
802 | 1 | assert(VP8LBundleColorMap != NULL); |
803 | 1 | assert(VP8LPredictorsSub[0] != NULL); |
804 | 1 | assert(VP8LPredictorsSub[1] != NULL); |
805 | 1 | assert(VP8LPredictorsSub[2] != NULL); |
806 | 1 | assert(VP8LPredictorsSub[3] != NULL); |
807 | 1 | assert(VP8LPredictorsSub[4] != NULL); |
808 | 1 | assert(VP8LPredictorsSub[5] != NULL); |
809 | 1 | assert(VP8LPredictorsSub[6] != NULL); |
810 | 1 | assert(VP8LPredictorsSub[7] != NULL); |
811 | 1 | assert(VP8LPredictorsSub[8] != NULL); |
812 | 1 | assert(VP8LPredictorsSub[9] != NULL); |
813 | 1 | assert(VP8LPredictorsSub[10] != NULL); |
814 | 1 | assert(VP8LPredictorsSub[11] != NULL); |
815 | 1 | assert(VP8LPredictorsSub[12] != NULL); |
816 | 1 | assert(VP8LPredictorsSub[13] != NULL); |
817 | 1 | assert(VP8LPredictorsSub[14] != NULL); |
818 | 1 | assert(VP8LPredictorsSub[15] != NULL); |
819 | 1 | assert(VP8LPredictorsSub_C[0] != NULL); |
820 | 1 | assert(VP8LPredictorsSub_C[1] != NULL); |
821 | 1 | assert(VP8LPredictorsSub_C[2] != NULL); |
822 | 1 | assert(VP8LPredictorsSub_C[3] != NULL); |
823 | 1 | assert(VP8LPredictorsSub_C[4] != NULL); |
824 | 1 | assert(VP8LPredictorsSub_C[5] != NULL); |
825 | 1 | assert(VP8LPredictorsSub_C[6] != NULL); |
826 | 1 | assert(VP8LPredictorsSub_C[7] != NULL); |
827 | 1 | assert(VP8LPredictorsSub_C[8] != NULL); |
828 | 1 | assert(VP8LPredictorsSub_C[9] != NULL); |
829 | 1 | assert(VP8LPredictorsSub_C[10] != NULL); |
830 | 1 | assert(VP8LPredictorsSub_C[11] != NULL); |
831 | 1 | assert(VP8LPredictorsSub_C[12] != NULL); |
832 | 1 | assert(VP8LPredictorsSub_C[13] != NULL); |
833 | 1 | assert(VP8LPredictorsSub_C[14] != NULL); |
834 | 1 | assert(VP8LPredictorsSub_C[15] != NULL); |
835 | 1 | } |
836 | | |
837 | | //------------------------------------------------------------------------------ |