FFmpeg
texturedsp.c
Go to the documentation of this file.
1 /*
2  * Texture block decompression
3  * Copyright (C) 2009 Benjamin Dobell, Glass Echidna
4  * Copyright (C) 2012 Matthäus G. "Anteru" Chajdas (http://anteru.net)
5  * Copyright (C) 2015 Vittorio Giovara <vittorio.giovara@gmail.com>
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining a
8  * copy of this software and associated documentation files (the "Software"),
9  * to deal in the Software without restriction, including without limitation
10  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11  * and/or sell copies of the Software, and to permit persons to whom the
12  * Software is furnished to do so, subject to the following conditions:
13  * The above copyright notice and this permission notice shall be included
14  * in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22  * IN THE SOFTWARE.
23  */
24 
25 #include <stddef.h>
26 #include <stdint.h>
27 
28 #include "libavutil/attributes.h"
29 #include "libavutil/common.h"
30 #include "libavutil/intreadwrite.h"
31 #include "libavutil/libm.h"
32 
33 #include "texturedsp.h"
34 
35 #define RGBA(r, g, b, a) (((uint8_t)(r) << 0) | \
36  ((uint8_t)(g) << 8) | \
37  ((uint8_t)(b) << 16) | \
38  ((unsigned)(uint8_t)(a) << 24))
39 
40 static av_always_inline void extract_color(uint32_t colors[4],
41  uint16_t color0,
42  uint16_t color1,
43  int dxtn, int alpha)
44 {
45  int tmp;
46  uint8_t r0, g0, b0, r1, g1, b1;
47  uint8_t a = dxtn ? 0 : 255;
48 
49  tmp = (color0 >> 11) * 255 + 16;
50  r0 = (uint8_t) ((tmp / 32 + tmp) / 32);
51  tmp = ((color0 & 0x07E0) >> 5) * 255 + 32;
52  g0 = (uint8_t) ((tmp / 64 + tmp) / 64);
53  tmp = (color0 & 0x001F) * 255 + 16;
54  b0 = (uint8_t) ((tmp / 32 + tmp) / 32);
55 
56  tmp = (color1 >> 11) * 255 + 16;
57  r1 = (uint8_t) ((tmp / 32 + tmp) / 32);
58  tmp = ((color1 & 0x07E0) >> 5) * 255 + 32;
59  g1 = (uint8_t) ((tmp / 64 + tmp) / 64);
60  tmp = (color1 & 0x001F) * 255 + 16;
61  b1 = (uint8_t) ((tmp / 32 + tmp) / 32);
62 
63  if (dxtn || color0 > color1) {
64  colors[0] = RGBA(r0, g0, b0, a);
65  colors[1] = RGBA(r1, g1, b1, a);
66  colors[2] = RGBA((2 * r0 + r1) / 3,
67  (2 * g0 + g1) / 3,
68  (2 * b0 + b1) / 3,
69  a);
70  colors[3] = RGBA((2 * r1 + r0) / 3,
71  (2 * g1 + g0) / 3,
72  (2 * b1 + b0) / 3,
73  a);
74  } else {
75  colors[0] = RGBA(r0, g0, b0, a);
76  colors[1] = RGBA(r1, g1, b1, a);
77  colors[2] = RGBA((r0 + r1) / 2,
78  (g0 + g1) / 2,
79  (b0 + b1) / 2,
80  a);
81  colors[3] = RGBA(0, 0, 0, alpha);
82  }
83 }
84 
85 static inline void dxt1_block_internal(uint8_t *dst, ptrdiff_t stride,
86  const uint8_t *block, uint8_t alpha)
87 {
88  int x, y;
89  uint32_t colors[4];
90  uint16_t color0 = AV_RL16(block + 0);
91  uint16_t color1 = AV_RL16(block + 2);
92  uint32_t code = AV_RL32(block + 4);
93 
94  extract_color(colors, color0, color1, 0, alpha);
95 
96  for (y = 0; y < 4; y++) {
97  for (x = 0; x < 4; x++) {
98  uint32_t pixel = colors[code & 3];
99  code >>= 2;
100  AV_WL32(dst + x * 4, pixel);
101  }
102  dst += stride;
103  }
104 }
105 
106 /**
107  * Decompress one block of a DXT1 texture and store the resulting
108  * RGBA pixels in 'dst'. Alpha component is fully opaque.
109  *
110  * @param dst output buffer.
111  * @param stride scanline in bytes.
112  * @param block block to decompress.
113  * @return how much texture data has been consumed.
114  */
115 static int dxt1_block(uint8_t *dst, ptrdiff_t stride, const uint8_t *block)
116 {
118 
119  return 8;
120 }
121 
122 /**
123  * Decompress one block of a DXT1 with 1-bit alpha texture and store
124  * the resulting RGBA pixels in 'dst'. Alpha is either fully opaque or
125  * fully transparent.
126  *
127  * @param dst output buffer.
128  * @param stride scanline in bytes.
129  * @param block block to decompress.
130  * @return how much texture data has been consumed.
131  */
132 static int dxt1a_block(uint8_t *dst, ptrdiff_t stride, const uint8_t *block)
133 {
135 
136  return 8;
137 }
138 
139 static inline void dxt3_block_internal(uint8_t *dst, ptrdiff_t stride,
140  const uint8_t *block)
141 {
142  int x, y;
143  uint32_t colors[4];
144  uint16_t color0 = AV_RL16(block + 8);
145  uint16_t color1 = AV_RL16(block + 10);
146  uint32_t code = AV_RL32(block + 12);
147 
148  extract_color(colors, color0, color1, 1, 0);
149 
150  for (y = 0; y < 4; y++) {
151  const uint16_t alpha_code = AV_RL16(block + 2 * y);
152  uint8_t alpha_values[4];
153 
154  alpha_values[0] = ((alpha_code >> 0) & 0x0F) * 17;
155  alpha_values[1] = ((alpha_code >> 4) & 0x0F) * 17;
156  alpha_values[2] = ((alpha_code >> 8) & 0x0F) * 17;
157  alpha_values[3] = ((alpha_code >> 12) & 0x0F) * 17;
158 
159  for (x = 0; x < 4; x++) {
160  uint8_t alpha = alpha_values[x];
161  uint32_t pixel = colors[code & 3] | ((unsigned)alpha << 24);
162  code >>= 2;
163 
164  AV_WL32(dst + x * 4, pixel);
165  }
166  dst += stride;
167  }
168 }
169 
170 /** Convert a premultiplied alpha pixel to a straight alpha pixel. */
171 static av_always_inline void premult2straight(uint8_t *src)
172 {
173  int r = src[0];
174  int g = src[1];
175  int b = src[2];
176  int a = src[3]; /* unchanged */
177 
178  if (a == 0)
179  return;
180 
181  src[0] = (uint8_t) FFMIN(r * 255 / a, 255);
182  src[1] = (uint8_t) FFMIN(g * 255 / a, 255);
183  src[2] = (uint8_t) FFMIN(b * 255 / a, 255);
184 }
185 
186 /**
187  * Decompress one block of a DXT2 texture and store the resulting
188  * RGBA pixels in 'dst'.
189  *
190  * @param dst output buffer.
191  * @param stride scanline in bytes.
192  * @param block block to decompress.
193  * @return how much texture data has been consumed.
194  */
195 static int dxt2_block(uint8_t *dst, ptrdiff_t stride, const uint8_t *block)
196 {
197  int x, y;
198 
200 
201  /* This format is DXT3, but returns premultiplied alpha. It needs to be
202  * converted because it's what lavc outputs (and swscale expects). */
203  for (y = 0; y < 4; y++)
204  for (x = 0; x < 4; x++)
205  premult2straight(dst + x * 4 + y * stride);
206 
207  return 16;
208 }
209 
210 /**
211  * Decompress one block of a DXT3 texture and store the resulting
212  * RGBA pixels in 'dst'.
213  *
214  * @param dst output buffer.
215  * @param stride scanline in bytes.
216  * @param block block to decompress.
217  * @return how much texture data has been consumed.
218  */
219 static int dxt3_block(uint8_t *dst, ptrdiff_t stride, const uint8_t *block)
220 {
222 
223  return 16;
224 }
225 
226 /**
227  * Decompress a BC 16x3 index block stored as
228  * h g f e
229  * d c b a
230  * p o n m
231  * l k j i
232  *
233  * Bits packed as
234  * | h | g | f | e | d | c | b | a | // Entry
235  * |765 432 107 654 321 076 543 210| // Bit
236  * |0000000000111111111112222222222| // Byte
237  *
238  * into 16 8-bit indices.
239  */
240 static void decompress_indices(uint8_t *dst, const uint8_t *src)
241 {
242  int block, i;
243 
244  for (block = 0; block < 2; block++) {
245  int tmp = AV_RL24(src);
246 
247  /* Unpack 8x3 bit from last 3 byte block */
248  for (i = 0; i < 8; i++)
249  dst[i] = (tmp >> (i * 3)) & 0x7;
250 
251  src += 3;
252  dst += 8;
253  }
254 }
255 
256 static inline void dxt5_block_internal(uint8_t *dst, ptrdiff_t stride,
257  const uint8_t *block)
258 {
259  int x, y;
260  uint32_t colors[4];
261  uint8_t alpha_indices[16];
262  uint16_t color0 = AV_RL16(block + 8);
263  uint16_t color1 = AV_RL16(block + 10);
264  uint32_t code = AV_RL32(block + 12);
265  uint8_t alpha0 = *(block);
266  uint8_t alpha1 = *(block + 1);
267 
268  decompress_indices(alpha_indices, block + 2);
269 
270  extract_color(colors, color0, color1, 1, 0);
271 
272  for (y = 0; y < 4; y++) {
273  for (x = 0; x < 4; x++) {
274  int alpha_code = alpha_indices[x + y * 4];
275  uint32_t pixel;
276  uint8_t alpha;
277 
278  if (alpha_code == 0) {
279  alpha = alpha0;
280  } else if (alpha_code == 1) {
281  alpha = alpha1;
282  } else {
283  if (alpha0 > alpha1) {
284  alpha = (uint8_t) (((8 - alpha_code) * alpha0 +
285  (alpha_code - 1) * alpha1) / 7);
286  } else {
287  if (alpha_code == 6) {
288  alpha = 0;
289  } else if (alpha_code == 7) {
290  alpha = 255;
291  } else {
292  alpha = (uint8_t) (((6 - alpha_code) * alpha0 +
293  (alpha_code - 1) * alpha1) / 5);
294  }
295  }
296  }
297  pixel = colors[code & 3] | ((unsigned)alpha << 24);
298  code >>= 2;
299  AV_WL32(dst + x * 4, pixel);
300  }
301  dst += stride;
302  }
303 }
304 
305 /**
306  * Decompress one block of a DXT4 texture and store the resulting
307  * RGBA pixels in 'dst'.
308  *
309  * @param dst output buffer.
310  * @param stride scanline in bytes.
311  * @param block block to decompress.
312  * @return how much texture data has been consumed.
313  */
314 static int dxt4_block(uint8_t *dst, ptrdiff_t stride, const uint8_t *block)
315 {
316  int x, y;
317 
319 
320  /* This format is DXT5, but returns premultiplied alpha. It needs to be
321  * converted because it's what lavc outputs (and swscale expects). */
322  for (y = 0; y < 4; y++)
323  for (x = 0; x < 4; x++)
324  premult2straight(dst + x * 4 + y * stride);
325 
326  return 16;
327 }
328 
329 /**
330  * Decompress one block of a DXT5 texture and store the resulting
331  * RGBA pixels in 'dst'.
332  *
333  * @param dst output buffer.
334  * @param stride scanline in bytes.
335  * @param block block to decompress.
336  * @return how much texture data has been consumed.
337  */
338 static int dxt5_block(uint8_t *dst, ptrdiff_t stride, const uint8_t *block)
339 {
341 
342  return 16;
343 }
344 
345 /**
346  * Convert a YCoCg buffer to RGBA.
347  *
348  * @param src input buffer.
349  * @param scaled variant with scaled chroma components and opaque alpha.
350  */
351 static av_always_inline void ycocg2rgba(uint8_t *src, int scaled)
352 {
353  int r = src[0];
354  int g = src[1];
355  int b = src[2];
356  int a = src[3];
357 
358  int s = scaled ? (b >> 3) + 1 : 1;
359  int y = a;
360  int co = (r - 128) / s;
361  int cg = (g - 128) / s;
362 
363  src[0] = av_clip_uint8(y + co - cg);
364  src[1] = av_clip_uint8(y + cg);
365  src[2] = av_clip_uint8(y - co - cg);
366  src[3] = scaled ? 255 : b;
367 }
368 
369 /**
370  * Decompress one block of a DXT5 texture with classic YCoCg and store
371  * the resulting RGBA pixels in 'dst'. Alpha component is fully opaque.
372  *
373  * @param dst output buffer.
374  * @param stride scanline in bytes.
375  * @param block block to decompress.
376  * @return how much texture data has been consumed.
377  */
378 static int dxt5y_block(uint8_t *dst, ptrdiff_t stride, const uint8_t *block)
379 {
380  int x, y;
381 
382  /* This format is basically DXT5, with luma stored in alpha.
383  * Run a normal decompress and then reorder the components. */
385 
386  for (y = 0; y < 4; y++)
387  for (x = 0; x < 4; x++)
388  ycocg2rgba(dst + x * 4 + y * stride, 0);
389 
390  return 16;
391 }
392 
393 /**
394  * Decompress one block of a DXT5 texture with scaled YCoCg and store
395  * the resulting RGBA pixels in 'dst'. Alpha component is fully opaque.
396  *
397  * @param dst output buffer.
398  * @param stride scanline in bytes.
399  * @param block block to decompress.
400  * @return how much texture data has been consumed.
401  */
402 static int dxt5ys_block(uint8_t *dst, ptrdiff_t stride, const uint8_t *block)
403 {
404  int x, y;
405 
406  /* This format is basically DXT5, with luma stored in alpha.
407  * Run a normal decompress and then reorder the components. */
409 
410  for (y = 0; y < 4; y++)
411  for (x = 0; x < 4; x++)
412  ycocg2rgba(dst + x * 4 + y * stride, 1);
413 
414  return 16;
415 }
416 
417 static inline void rgtc_block_internal(uint8_t *dst, ptrdiff_t stride,
418  const uint8_t *block,
419  const int *color_tab, int mono, int offset, int pix_size)
420 {
421  uint8_t indices[16];
422  int x, y;
423 
424  decompress_indices(indices, block + 2);
425 
426  /* Only one or two channels are stored at most, since it only used to
427  * compress specular (black and white) or normal (red and green) maps.
428  * Although the standard says to zero out unused components, many
429  * implementations fill all of them with the same value. */
430  for (y = 0; y < 4; y++) {
431  for (x = 0; x < 4; x++) {
432  int i = indices[x + y * 4];
433  /* Interval expansion from [-1 1] or [0 1] to [0 255]. */
434  int c = color_tab[i];
435 
436  if (mono){
437  dst [x * pix_size + y * stride + offset] = (uint8_t)c;
438  }
439  else{
440  uint32_t pixel = RGBA(c, c, c, 255U);
441  AV_WL32(dst + x * pix_size + y * stride, pixel);
442  }
443  }
444  }
445 }
446 
447 static inline void rgtc1_block_internal(uint8_t *dst, ptrdiff_t stride,
448  const uint8_t *block, int sign, int mono, int offset, int pix_size)
449 {
450  int color_table[8];
451  int r0, r1;
452 
453  if (sign) {
454  /* signed data is in [-128 127] so just offset it to unsigned
455  * and it can be treated exactly the same */
456  r0 = ((int8_t) block[0]) + 128;
457  r1 = ((int8_t) block[1]) + 128;
458  } else {
459  r0 = block[0];
460  r1 = block[1];
461  }
462 
463  color_table[0] = r0;
464  color_table[1] = r1;
465 
466  if (r0 > r1) {
467  /* 6 interpolated color values */
468  color_table[2] = (6 * r0 + 1 * r1) / 7; // bit code 010
469  color_table[3] = (5 * r0 + 2 * r1) / 7; // bit code 011
470  color_table[4] = (4 * r0 + 3 * r1) / 7; // bit code 100
471  color_table[5] = (3 * r0 + 4 * r1) / 7; // bit code 101
472  color_table[6] = (2 * r0 + 5 * r1) / 7; // bit code 110
473  color_table[7] = (1 * r0 + 6 * r1) / 7; // bit code 111
474  } else {
475  /* 4 interpolated color values */
476  color_table[2] = (4 * r0 + 1 * r1) / 5; // bit code 010
477  color_table[3] = (3 * r0 + 2 * r1) / 5; // bit code 011
478  color_table[4] = (2 * r0 + 3 * r1) / 5; // bit code 100
479  color_table[5] = (1 * r0 + 4 * r1) / 5; // bit code 101
480  color_table[6] = 0; /* min range */ // bit code 110
481  color_table[7] = 255; /* max range */ // bit code 111
482  }
483 
484  rgtc_block_internal(dst, stride, block, color_table, mono, offset, pix_size);
485 }
486 
487 /**
488  * Decompress one block of a RGRC1 texture with signed components
489  * and store the resulting RGBA pixels in 'dst'.
490  *
491  * @param dst output buffer.
492  * @param stride scanline in bytes.
493  * @param block block to decompress.
494  * @return how much texture data has been consumed.
495  */
496 static int rgtc1s_block(uint8_t *dst, ptrdiff_t stride, const uint8_t *block)
497 {
498  rgtc1_block_internal(dst, stride, block, 1, 0, 0, 4);
499 
500  return 8;
501 }
502 
503 /**
504  * Decompress one block of a RGRC1 texture with unsigned components
505  * and store the resulting RGBA pixels in 'dst'.
506  *
507  * @param dst output buffer.
508  * @param stride scanline in bytes.
509  * @param block block to decompress.
510  * @return how much texture data has been consumed.
511  */
512 static int rgtc1u_block(uint8_t *dst, ptrdiff_t stride, const uint8_t *block)
513 {
514  rgtc1_block_internal(dst, stride, block, 0, 0, 0, 4);
515 
516  return 8;
517 }
518 
519 /**
520  * Decompress one block of a RGTC1 texture with unsigned components
521  * and overwrite the alpha component in 'dst' (RGBA data).
522  *
523  * @param dst output buffer.
524  * @param stride scanline in bytes.
525  * @param block block to decompress.
526  * @return how much texture data has been consumed.
527  */
528 static int rgtc1u_alpha_block(uint8_t *dst, ptrdiff_t stride, const uint8_t *block)
529 {
530  rgtc1_block_internal(dst, stride, block, 0, 1, 3, 4);
531 
532  return 8;
533 }
534 
535 /**
536  * Decompress one block of a RGTC1 texture with unsigned components
537  * to Gray 8.
538  *
539  * @param dst output buffer.
540  * @param stride scanline in bytes.
541  * @param block block to decompress.
542  * @return how much texture data has been consumed.
543  */
544 static int rgtc1u_gray_block(uint8_t *dst, ptrdiff_t stride, const uint8_t *block)
545 {
546  rgtc1_block_internal(dst, stride, block, 0, 1, 0, 1);
547 
548  return 8;
549 }
550 
551 static inline void rgtc2_block_internal(uint8_t *dst, ptrdiff_t stride,
552  const uint8_t *block, int sign)
553 {
554  /* 4x4 block containing 4 component pixels. */
555  uint8_t c0[4 * 4 * 4];
556  uint8_t c1[4 * 4 * 4];
557  int x, y;
558 
559  /* Decompress the two channels separately and interleave them afterwards. */
560  rgtc1_block_internal(c0, 16, block, sign, 0, 0, 4);
561  rgtc1_block_internal(c1, 16, block + 8, sign, 0, 0, 4);
562 
563  /* B is rebuilt exactly like a normal map. */
564  for (y = 0; y < 4; y++) {
565  for (x = 0; x < 4; x++) {
566  uint8_t *p = dst + x * 4 + y * stride;
567  int r = c0[x * 4 + y * 16];
568  int g = c1[x * 4 + y * 16];
569  int b = 127;
570 
571  int d = (255 * 255 - r * r - g * g) / 2;
572  if (d > 0)
573  b = lrint(sqrtf(d));
574 
575  p[0] = r;
576  p[1] = g;
577  p[2] = b;
578  p[3] = 255;
579  }
580  }
581 }
582 
583 /**
584  * Decompress one block of a RGRC2 texture with signed components
585  * and store the resulting RGBA pixels in 'dst'. Alpha is fully opaque.
586  *
587  * @param dst output buffer.
588  * @param stride scanline in bytes.
589  * @param block block to decompress.
590  * @return how much texture data has been consumed.
591  */
592 static int rgtc2s_block(uint8_t *dst, ptrdiff_t stride, const uint8_t *block)
593 {
595 
596  return 16;
597 }
598 
599 /**
600  * Decompress one block of a RGRC2 texture with unsigned components
601  * and store the resulting RGBA pixels in 'dst'. Alpha is fully opaque.
602  *
603  * @param dst output buffer.
604  * @param stride scanline in bytes.
605  * @param block block to decompress.
606  * @return how much texture data has been consumed.
607  */
608 static int rgtc2u_block(uint8_t *dst, ptrdiff_t stride, const uint8_t *block)
609 {
611 
612  return 16;
613 }
614 
615 /**
616  * Decompress one block of a 3Dc texture with unsigned components
617  * and store the resulting RGBA pixels in 'dst'. Alpha is fully opaque.
618  *
619  * @param dst output buffer.
620  * @param stride scanline in bytes.
621  * @param block block to decompress.
622  * @return how much texture data has been consumed.
623  */
624 static int dxn3dc_block(uint8_t *dst, ptrdiff_t stride, const uint8_t *block)
625 {
626  int x, y;
628 
629  /* This is the 3Dc variant of RGTC2, with swapped R and G. */
630  for (y = 0; y < 4; y++) {
631  for (x = 0; x < 4; x++) {
632  uint8_t *p = dst + x * 4 + y * stride;
633  FFSWAP(uint8_t, p[0], p[1]);
634  }
635  }
636 
637  return 16;
638 }
639 
641 {
642  c->dxt1_block = dxt1_block;
643  c->dxt1a_block = dxt1a_block;
644  c->dxt2_block = dxt2_block;
645  c->dxt3_block = dxt3_block;
646  c->dxt4_block = dxt4_block;
647  c->dxt5_block = dxt5_block;
648  c->dxt5y_block = dxt5y_block;
649  c->dxt5ys_block = dxt5ys_block;
650  c->rgtc1s_block = rgtc1s_block;
651  c->rgtc1u_block = rgtc1u_block;
652  c->rgtc1u_gray_block = rgtc1u_gray_block;
653  c->rgtc1u_alpha_block = rgtc1u_alpha_block;
654  c->rgtc2s_block = rgtc2s_block;
655  c->rgtc2u_block = rgtc2u_block;
656  c->dxn3dc_block = dxn3dc_block;
657 }
658 
659 #define TEXTUREDSP_FUNC_NAME ff_texturedsp_exec_decompress_threads
660 #define TEXTUREDSP_TEX_FUNC(a, b, c) tex_funct(a, b, c)
661 #include "texturedsp_template.c"
dxt5_block
static int dxt5_block(uint8_t *dst, ptrdiff_t stride, const uint8_t *block)
Decompress one block of a DXT5 texture and store the resulting RGBA pixels in 'dst'.
Definition: texturedsp.c:338
dxt3_block
static int dxt3_block(uint8_t *dst, ptrdiff_t stride, const uint8_t *block)
Decompress one block of a DXT3 texture and store the resulting RGBA pixels in 'dst'.
Definition: texturedsp.c:219
r
const char * r
Definition: vf_curves.c:127
AV_WL32
#define AV_WL32(p, v)
Definition: intreadwrite.h:422
libm.h
dxt4_block
static int dxt4_block(uint8_t *dst, ptrdiff_t stride, const uint8_t *block)
Decompress one block of a DXT4 texture and store the resulting RGBA pixels in 'dst'.
Definition: texturedsp.c:314
tmp
static uint8_t tmp[11]
Definition: aes_ctr.c:28
b
#define b
Definition: input.c:41
TextureDSPContext
Definition: texturedsp.h:45
c1
static const uint64_t c1
Definition: murmur3.c:52
rgtc1s_block
static int rgtc1s_block(uint8_t *dst, ptrdiff_t stride, const uint8_t *block)
Decompress one block of a RGRC1 texture with signed components and store the resulting RGBA pixels in...
Definition: texturedsp.c:496
extract_color
static av_always_inline void extract_color(uint32_t colors[4], uint16_t color0, uint16_t color1, int dxtn, int alpha)
Definition: texturedsp.c:40
decompress_indices
static void decompress_indices(uint8_t *dst, const uint8_t *src)
Decompress a BC 16x3 index block stored as h g f e d c b a p o n m l k j i.
Definition: texturedsp.c:240
texturedsp.h
b1
static double b1(void *priv, double x, double y)
Definition: vf_xfade.c:2034
dxn3dc_block
static int dxn3dc_block(uint8_t *dst, ptrdiff_t stride, const uint8_t *block)
Decompress one block of a 3Dc texture with unsigned components and store the resulting RGBA pixels in...
Definition: texturedsp.c:624
rgtc1u_gray_block
static int rgtc1u_gray_block(uint8_t *dst, ptrdiff_t stride, const uint8_t *block)
Decompress one block of a RGTC1 texture with unsigned components to Gray 8.
Definition: texturedsp.c:544
lrint
#define lrint
Definition: tablegen.h:53
av_cold
#define av_cold
Definition: attributes.h:90
rgtc1u_block
static int rgtc1u_block(uint8_t *dst, ptrdiff_t stride, const uint8_t *block)
Decompress one block of a RGRC1 texture with unsigned components and store the resulting RGBA pixels ...
Definition: texturedsp.c:512
rgtc2_block_internal
static void rgtc2_block_internal(uint8_t *dst, ptrdiff_t stride, const uint8_t *block, int sign)
Definition: texturedsp.c:551
intreadwrite.h
s
#define s(width, name)
Definition: cbs_vp9.c:198
rgtc1u_alpha_block
static int rgtc1u_alpha_block(uint8_t *dst, ptrdiff_t stride, const uint8_t *block)
Decompress one block of a RGTC1 texture with unsigned components and overwrite the alpha component in...
Definition: texturedsp.c:528
g
const char * g
Definition: vf_curves.c:128
ff_texturedsp_init
av_cold void ff_texturedsp_init(TextureDSPContext *c)
Definition: texturedsp.c:640
AV_RL16
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_RL16
Definition: bytestream.h:94
dxt3_block_internal
static void dxt3_block_internal(uint8_t *dst, ptrdiff_t stride, const uint8_t *block)
Definition: texturedsp.c:139
dxt5y_block
static int dxt5y_block(uint8_t *dst, ptrdiff_t stride, const uint8_t *block)
Decompress one block of a DXT5 texture with classic YCoCg and store the resulting RGBA pixels in 'dst...
Definition: texturedsp.c:378
rgtc1_block_internal
static void rgtc1_block_internal(uint8_t *dst, ptrdiff_t stride, const uint8_t *block, int sign, int mono, int offset, int pix_size)
Definition: texturedsp.c:447
RGBA
#define RGBA(r, g, b, a)
Definition: texturedsp.c:35
pixel
uint8_t pixel
Definition: tiny_ssim.c:41
sqrtf
static __device__ float sqrtf(float a)
Definition: cuda_runtime.h:184
rgtc_block_internal
static void rgtc_block_internal(uint8_t *dst, ptrdiff_t stride, const uint8_t *block, const int *color_tab, int mono, int offset, int pix_size)
Definition: texturedsp.c:417
rgtc2u_block
static int rgtc2u_block(uint8_t *dst, ptrdiff_t stride, const uint8_t *block)
Decompress one block of a RGRC2 texture with unsigned components and store the resulting RGBA pixels ...
Definition: texturedsp.c:608
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
dxt1_block_internal
static void dxt1_block_internal(uint8_t *dst, ptrdiff_t stride, const uint8_t *block, uint8_t alpha)
Definition: texturedsp.c:85
dst
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition: dsp.h:83
AV_RL24
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_RL24
Definition: bytestream.h:93
a
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
Definition: undefined.txt:41
premult2straight
static av_always_inline void premult2straight(uint8_t *src)
Convert a premultiplied alpha pixel to a straight alpha pixel.
Definition: texturedsp.c:171
offset
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf offset
Definition: writing_filters.txt:86
attributes.h
dxt5ys_block
static int dxt5ys_block(uint8_t *dst, ptrdiff_t stride, const uint8_t *block)
Decompress one block of a DXT5 texture with scaled YCoCg and store the resulting RGBA pixels in 'dst'...
Definition: texturedsp.c:402
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
code
and forward the test the status of outputs and forward it to the corresponding return FFERROR_NOT_READY If the filters stores internally one or a few frame for some it can consider them to be part of the FIFO and delay acknowledging a status change accordingly Example code
Definition: filter_design.txt:178
common.h
av_always_inline
#define av_always_inline
Definition: attributes.h:49
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
texturedsp_template.c
stride
#define stride
Definition: h264pred_template.c:537
FFSWAP
#define FFSWAP(type, a, b)
Definition: macros.h:52
AV_RL32
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
Definition: bytestream.h:92
U
#define U(x)
Definition: vpx_arith.h:37
dxt5_block_internal
static void dxt5_block_internal(uint8_t *dst, ptrdiff_t stride, const uint8_t *block)
Definition: texturedsp.c:256
av_clip_uint8
#define av_clip_uint8
Definition: common.h:106
dxt1a_block
static int dxt1a_block(uint8_t *dst, ptrdiff_t stride, const uint8_t *block)
Decompress one block of a DXT1 with 1-bit alpha texture and store the resulting RGBA pixels in 'dst'.
Definition: texturedsp.c:132
rgtc2s_block
static int rgtc2s_block(uint8_t *dst, ptrdiff_t stride, const uint8_t *block)
Decompress one block of a RGRC2 texture with signed components and store the resulting RGBA pixels in...
Definition: texturedsp.c:592
alpha
static const int16_t alpha[]
Definition: ilbcdata.h:55
dxt1_block
static int dxt1_block(uint8_t *dst, ptrdiff_t stride, const uint8_t *block)
Decompress one block of a DXT1 texture and store the resulting RGBA pixels in 'dst'.
Definition: texturedsp.c:115
block
The exact code depends on how similar the blocks are and how related they are to the block
Definition: filter_design.txt:207
b0
static double b0(void *priv, double x, double y)
Definition: vf_xfade.c:2033
dxt2_block
static int dxt2_block(uint8_t *dst, ptrdiff_t stride, const uint8_t *block)
Decompress one block of a DXT2 texture and store the resulting RGBA pixels in 'dst'.
Definition: texturedsp.c:195
color_table
static const ColorEntry color_table[]
Definition: xpmdec.c:51
src
#define src
Definition: vp8dsp.c:248
ycocg2rgba
static av_always_inline void ycocg2rgba(uint8_t *src, int scaled)
Convert a YCoCg buffer to RGBA.
Definition: texturedsp.c:351