Subversion Repositories Kolibri OS

Rev

Rev 5063 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5063 Rev 5373
Line 249... Line 249...
249
static INLINE void
249
static INLINE void
250
util_format_dxtn_rgb_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride,
250
util_format_dxtn_rgb_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride,
251
                                        const uint8_t *src_row, unsigned src_stride,
251
                                        const uint8_t *src_row, unsigned src_stride,
252
                                        unsigned width, unsigned height,
252
                                        unsigned width, unsigned height,
253
                                        util_format_dxtn_fetch_t fetch,
253
                                        util_format_dxtn_fetch_t fetch,
254
                                        unsigned block_size)
254
                                        unsigned block_size, boolean srgb)
255
{
255
{
256
   const unsigned bw = 4, bh = 4, comps = 4;
256
   const unsigned bw = 4, bh = 4, comps = 4;
257
   unsigned x, y, i, j;
257
   unsigned x, y, i, j;
258
   for(y = 0; y < height; y += bh) {
258
   for(y = 0; y < height; y += bh) {
259
      const uint8_t *src = src_row;
259
      const uint8_t *src = src_row;
260
      for(x = 0; x < width; x += bw) {
260
      for(x = 0; x < width; x += bw) {
261
         for(j = 0; j < bh; ++j) {
261
         for(j = 0; j < bh; ++j) {
262
            for(i = 0; i < bw; ++i) {
262
            for(i = 0; i < bw; ++i) {
263
               uint8_t *dst = dst_row + (y + j)*dst_stride/sizeof(*dst_row) + (x + i)*comps;
263
               uint8_t *dst = dst_row + (y + j)*dst_stride/sizeof(*dst_row) + (x + i)*comps;
264
               fetch(0, src, i, j, dst);
264
               fetch(0, src, i, j, dst);
-
 
265
               if (srgb) {
-
 
266
                  dst[0] = util_format_srgb_to_linear_8unorm(dst[0]);
-
 
267
                  dst[1] = util_format_srgb_to_linear_8unorm(dst[1]);
-
 
268
                  dst[2] = util_format_srgb_to_linear_8unorm(dst[2]);
-
 
269
               }
265
            }
270
            }
266
         }
271
         }
267
         src += block_size;
272
         src += block_size;
268
      }
273
      }
269
      src_row += src_stride;
274
      src_row += src_stride;
Line 276... Line 281...
276
                                        unsigned width, unsigned height)
281
                                        unsigned width, unsigned height)
277
{
282
{
278
   util_format_dxtn_rgb_unpack_rgba_8unorm(dst_row, dst_stride,
283
   util_format_dxtn_rgb_unpack_rgba_8unorm(dst_row, dst_stride,
279
                                           src_row, src_stride,
284
                                           src_row, src_stride,
280
                                           width, height,
285
                                           width, height,
281
                                           util_format_dxt1_rgb_fetch, 8);
286
                                           util_format_dxt1_rgb_fetch,
-
 
287
                                           8, FALSE);
282
}
288
}
Line 283... Line 289...
283
 
289
 
284
void
290
void
285
util_format_dxt1_rgba_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride,
291
util_format_dxt1_rgba_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride,
286
                                         const uint8_t *src_row, unsigned src_stride,
292
                                         const uint8_t *src_row, unsigned src_stride,
287
                                         unsigned width, unsigned height)
293
                                         unsigned width, unsigned height)
288
{
294
{
289
   util_format_dxtn_rgb_unpack_rgba_8unorm(dst_row, dst_stride,
295
   util_format_dxtn_rgb_unpack_rgba_8unorm(dst_row, dst_stride,
290
                                           src_row, src_stride,
296
                                           src_row, src_stride,
291
                                           width, height,
297
                                           width, height,
-
 
298
                                           util_format_dxt1_rgba_fetch,
292
                                           util_format_dxt1_rgba_fetch, 8);
299
                                           8, FALSE);
Line 293... Line 300...
293
}
300
}
294
 
301
 
295
void
302
void
296
util_format_dxt3_rgba_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride,
303
util_format_dxt3_rgba_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride,
297
                                         const uint8_t *src_row, unsigned src_stride,
304
                                         const uint8_t *src_row, unsigned src_stride,
298
                                         unsigned width, unsigned height)
305
                                         unsigned width, unsigned height)
299
{
306
{
300
   util_format_dxtn_rgb_unpack_rgba_8unorm(dst_row, dst_stride,
307
   util_format_dxtn_rgb_unpack_rgba_8unorm(dst_row, dst_stride,
301
                                           src_row, src_stride,
308
                                           src_row, src_stride,
-
 
309
                                           width, height,
302
                                           width, height,
310
                                           util_format_dxt3_rgba_fetch,
Line 303... Line 311...
303
                                           util_format_dxt3_rgba_fetch, 16);
311
                                           16, FALSE);
304
}
312
}
305
 
313
 
306
void
314
void
307
util_format_dxt5_rgba_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride,
315
util_format_dxt5_rgba_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride,
308
                                         const uint8_t *src_row, unsigned src_stride,
316
                                         const uint8_t *src_row, unsigned src_stride,
309
                                         unsigned width, unsigned height)
317
                                         unsigned width, unsigned height)
310
{
318
{
311
   util_format_dxtn_rgb_unpack_rgba_8unorm(dst_row, dst_stride,
319
   util_format_dxtn_rgb_unpack_rgba_8unorm(dst_row, dst_stride,
-
 
320
                                           src_row, src_stride,
312
                                           src_row, src_stride,
321
                                           width, height,
Line 313... Line 322...
313
                                           width, height,
322
                                           util_format_dxt5_rgba_fetch,
314
                                           util_format_dxt5_rgba_fetch, 16);
323
                                           16, FALSE);
315
}
324
}
316
 
325
 
317
static INLINE void
326
static INLINE void
318
util_format_dxtn_rgb_unpack_rgba_float(float *dst_row, unsigned dst_stride,
327
util_format_dxtn_rgb_unpack_rgba_float(float *dst_row, unsigned dst_stride,
319
                                       const uint8_t *src_row, unsigned src_stride,
328
                                       const uint8_t *src_row, unsigned src_stride,
320
                                       unsigned width, unsigned height,
329
                                       unsigned width, unsigned height,
321
                                       util_format_dxtn_fetch_t fetch,
330
                                       util_format_dxtn_fetch_t fetch,
322
                                       unsigned block_size)
331
                                       unsigned block_size, boolean srgb)
323
{
332
{
324
   unsigned x, y, i, j;
333
   unsigned x, y, i, j;
325
   for(y = 0; y < height; y += 4) {
334
   for(y = 0; y < height; y += 4) {
326
      const uint8_t *src = src_row;
335
      const uint8_t *src = src_row;
327
      for(x = 0; x < width; x += 4) {
336
      for(x = 0; x < width; x += 4) {
328
         for(j = 0; j < 4; ++j) {
337
         for(j = 0; j < 4; ++j) {
-
 
338
            for(i = 0; i < 4; ++i) {
-
 
339
               float *dst = dst_row + (y + j)*dst_stride/sizeof(*dst_row) + (x + i)*4;
-
 
340
               uint8_t tmp[4];
-
 
341
               fetch(0, src, i, j, tmp);
-
 
342
               if (srgb) {
-
 
343
                  dst[0] = util_format_srgb_8unorm_to_linear_float(tmp[0]);
329
            for(i = 0; i < 4; ++i) {
344
                  dst[1] = util_format_srgb_8unorm_to_linear_float(tmp[1]);
330
               float *dst = dst_row + (y + j)*dst_stride/sizeof(*dst_row) + (x + i)*4;
345
                  dst[2] = util_format_srgb_8unorm_to_linear_float(tmp[2]);
331
               uint8_t tmp[4];
346
               }
-
 
347
               else {
332
               fetch(0, src, i, j, tmp);
348
               dst[0] = ubyte_to_float(tmp[0]);
333
               dst[0] = ubyte_to_float(tmp[0]);
349
               dst[1] = ubyte_to_float(tmp[1]);
334
               dst[1] = ubyte_to_float(tmp[1]);
350
               dst[2] = ubyte_to_float(tmp[2]);
335
               dst[2] = ubyte_to_float(tmp[2]);
351
               }
336
               dst[3] = ubyte_to_float(tmp[3]);
352
               dst[3] = ubyte_to_float(tmp[3]);
Line 348... Line 364...
348
                                       unsigned width, unsigned height)
364
                                       unsigned width, unsigned height)
349
{
365
{
350
   util_format_dxtn_rgb_unpack_rgba_float(dst_row, dst_stride,
366
   util_format_dxtn_rgb_unpack_rgba_float(dst_row, dst_stride,
351
                                          src_row, src_stride,
367
                                          src_row, src_stride,
352
                                          width, height,
368
                                          width, height,
353
                                          util_format_dxt1_rgb_fetch, 8);
369
                                          util_format_dxt1_rgb_fetch,
-
 
370
                                          8, FALSE);
354
}
371
}
Line 355... Line 372...
355
 
372
 
356
void
373
void
357
util_format_dxt1_rgba_unpack_rgba_float(float *dst_row, unsigned dst_stride,
374
util_format_dxt1_rgba_unpack_rgba_float(float *dst_row, unsigned dst_stride,
358
                                        const uint8_t *src_row, unsigned src_stride,
375
                                        const uint8_t *src_row, unsigned src_stride,
359
                                        unsigned width, unsigned height)
376
                                        unsigned width, unsigned height)
360
{
377
{
361
   util_format_dxtn_rgb_unpack_rgba_float(dst_row, dst_stride,
378
   util_format_dxtn_rgb_unpack_rgba_float(dst_row, dst_stride,
362
                                          src_row, src_stride,
379
                                          src_row, src_stride,
363
                                          width, height,
380
                                          width, height,
-
 
381
                                          util_format_dxt1_rgba_fetch,
364
                                          util_format_dxt1_rgba_fetch, 8);
382
                                          8, FALSE);
Line 365... Line 383...
365
}
383
}
366
 
384
 
367
void
385
void
368
util_format_dxt3_rgba_unpack_rgba_float(float *dst_row, unsigned dst_stride,
386
util_format_dxt3_rgba_unpack_rgba_float(float *dst_row, unsigned dst_stride,
369
                                        const uint8_t *src_row, unsigned src_stride,
387
                                        const uint8_t *src_row, unsigned src_stride,
370
                                        unsigned width, unsigned height)
388
                                        unsigned width, unsigned height)
371
{
389
{
372
   util_format_dxtn_rgb_unpack_rgba_float(dst_row, dst_stride,
390
   util_format_dxtn_rgb_unpack_rgba_float(dst_row, dst_stride,
373
                                          src_row, src_stride,
391
                                          src_row, src_stride,
-
 
392
                                          width, height,
374
                                          width, height,
393
                                          util_format_dxt3_rgba_fetch,
Line 375... Line 394...
375
                                          util_format_dxt3_rgba_fetch, 16);
394
                                          16, FALSE);
376
}
395
}
377
 
396
 
378
void
397
void
379
util_format_dxt5_rgba_unpack_rgba_float(float *dst_row, unsigned dst_stride,
398
util_format_dxt5_rgba_unpack_rgba_float(float *dst_row, unsigned dst_stride,
380
                                        const uint8_t *src_row, unsigned src_stride,
399
                                        const uint8_t *src_row, unsigned src_stride,
381
                                        unsigned width, unsigned height)
400
                                        unsigned width, unsigned height)
382
{
401
{
383
   util_format_dxtn_rgb_unpack_rgba_float(dst_row, dst_stride,
402
   util_format_dxtn_rgb_unpack_rgba_float(dst_row, dst_stride,
-
 
403
                                          src_row, src_stride,
384
                                          src_row, src_stride,
404
                                          width, height,
Line 385... Line 405...
385
                                          width, height,
405
                                          util_format_dxt5_rgba_fetch,
386
                                          util_format_dxt5_rgba_fetch, 16);
406
                                          16, FALSE);
387
}
407
}
Line 388... Line 408...
388
 
408
 
389
 
409
 
390
/*
410
/*
391
 * Block compression.
411
 * Block compression.
-
 
412
 */
-
 
413
 
392
 */
414
static INLINE void
393
 
415
util_format_dxtn_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride,
394
void
416
                                      const uint8_t *src, unsigned src_stride,
395
util_format_dxt1_rgb_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride,
417
                                  unsigned width, unsigned height,
396
                                      const uint8_t *src, unsigned src_stride,
418
                                  enum util_format_dxtn format,
397
                                      unsigned width, unsigned height)
419
                                  unsigned block_size, boolean srgb)
398
{
420
{
399
   const unsigned bw = 4, bh = 4, bytes_per_block = 8;
421
   const unsigned bw = 4, bh = 4, comps = 4;
400
   unsigned x, y, i, j, k;
422
   unsigned x, y, i, j, k;
-
 
423
   for(y = 0; y < height; y += bh) {
401
   for(y = 0; y < height; y += bh) {
424
      uint8_t *dst = dst_row;
402
      uint8_t *dst = dst_row;
425
      for(x = 0; x < width; x += bw) {
-
 
426
         uint8_t tmp[4][4][4];  /* [bh][bw][comps] */
-
 
427
         for(j = 0; j < bh; ++j) {
403
      for(x = 0; x < width; x += bw) {
428
            for(i = 0; i < bw; ++i) {
-
 
429
               uint8_t src_tmp;
-
 
430
               for(k = 0; k < 3; ++k) {
404
         uint8_t tmp[4][4][3];  /* [bh][bw][comps] */
431
                  src_tmp = src[(y + j)*src_stride/sizeof(*src) + (x+i)*comps + k];
405
         for(j = 0; j < bh; ++j) {
432
                  if (srgb) {
-
 
433
                     tmp[j][i][k] = util_format_linear_to_srgb_8unorm(src_tmp);
-
 
434
                  }
-
 
435
                  else {
-
 
436
                     tmp[j][i][k] = src_tmp;
-
 
437
               }
406
            for(i = 0; i < bw; ++i) {
438
            }
407
               for(k = 0; k < 3; ++k) {
439
               /* for sake of simplicity there's an unneeded 4th component for dxt1_rgb */
408
                  tmp[j][i][k] = src[(y + j)*src_stride/sizeof(*src) + (x + i)*4 + k];
440
               tmp[j][i][3] = src[(y + j)*src_stride/sizeof(*src) + (x+i)*comps + 3];
409
               }
441
            }
410
            }
442
         }
-
 
443
         /* even for dxt1_rgb have 4 src comps */
411
         }
444
         util_format_dxtn_pack(4, 4, 4, &tmp[0][0][0], format, dst, 0);
Line 412... Line 445...
412
         util_format_dxtn_pack(3, 4, 4, &tmp[0][0][0], UTIL_FORMAT_DXT1_RGB, dst, 0);
445
         dst += block_size;
413
         dst += bytes_per_block;
446
      }
414
      }
447
      dst_row += dst_stride / sizeof(*dst_row);
415
      dst_row += dst_stride / sizeof(*dst_row);
448
   }
416
   }
449
 
417
}
450
}
418
 
-
 
419
void
-
 
420
util_format_dxt1_rgba_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride,
-
 
421
                                       const uint8_t *src, unsigned src_stride,
-
 
422
                                       unsigned width, unsigned height)
-
 
423
{
-
 
424
   const unsigned bw = 4, bh = 4, comps = 4, bytes_per_block = 8;
-
 
425
   unsigned x, y, i, j, k;
-
 
426
   for(y = 0; y < height; y += bh) {
-
 
427
      uint8_t *dst = dst_row;
-
 
428
      for(x = 0; x < width; x += bw) {
-
 
429
         uint8_t tmp[4][4][4];  /* [bh][bw][comps] */
-
 
430
         for(j = 0; j < bh; ++j) {
451
 
431
            for(i = 0; i < bw; ++i) {
-
 
432
               for(k = 0; k < comps; ++k) {
-
 
433
                  tmp[j][i][k] = src[(y + j)*src_stride/sizeof(*src) + (x + i)*comps + k];
452
void
434
               }
453
util_format_dxt1_rgb_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride,
-
 
454
                                      const uint8_t *src, unsigned src_stride,
-
 
455
                                      unsigned width, unsigned height)
-
 
456
{
-
 
457
   util_format_dxtn_pack_rgba_8unorm(dst_row, dst_stride, src, src_stride,
-
 
458
                                     width, height, UTIL_FORMAT_DXT1_RGB,
-
 
459
                                     8, FALSE);
-
 
460
}
-
 
461
 
-
 
462
void
435
            }
463
util_format_dxt1_rgba_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride,
Line 436... Line 464...
436
         }
464
                                       const uint8_t *src, unsigned src_stride,
437
         util_format_dxtn_pack(4, 4, 4, &tmp[0][0][0], UTIL_FORMAT_DXT1_RGBA, dst, 0);
465
                                       unsigned width, unsigned height)
438
         dst += bytes_per_block;
466
{
439
      }
467
   util_format_dxtn_pack_rgba_8unorm(dst_row, dst_stride, src, src_stride,
440
      dst_row += dst_stride / sizeof(*dst_row);
468
                                     width, height, UTIL_FORMAT_DXT1_RGBA,
441
   }
469
                                     8, FALSE);
442
}
-
 
443
 
-
 
444
void
-
 
445
util_format_dxt3_rgba_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride,
-
 
446
                                       const uint8_t *src, unsigned src_stride,
-
 
447
                                       unsigned width, unsigned height)
-
 
448
{
-
 
449
   const unsigned bw = 4, bh = 4, comps = 4, bytes_per_block = 16;
-
 
450
   unsigned x, y, i, j, k;
-
 
451
   for(y = 0; y < height; y += bh) {
-
 
452
      uint8_t *dst = dst_row;
-
 
453
      for(x = 0; x < width; x += bw) {
-
 
454
         uint8_t tmp[4][4][4];  /* [bh][bw][comps] */
470
}
455
         for(j = 0; j < bh; ++j) {
-
 
456
            for(i = 0; i < bw; ++i) {
-
 
457
               for(k = 0; k < comps; ++k) {
471
 
458
                  tmp[j][i][k] = src[(y + j)*src_stride/sizeof(*src) + (x + i)*comps + k];
-
 
459
               }
472
void
Line 460... Line 473...
460
            }
473
util_format_dxt3_rgba_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride,
461
         }
474
                                       const uint8_t *src, unsigned src_stride,
462
         util_format_dxtn_pack(4, 4, 4, &tmp[0][0][0], UTIL_FORMAT_DXT3_RGBA, dst, 0);
475
                                       unsigned width, unsigned height)
463
         dst += bytes_per_block;
476
{
464
      }
477
   util_format_dxtn_pack_rgba_8unorm(dst_row, dst_stride, src, src_stride,
465
      dst_row += dst_stride / sizeof(*dst_row);
478
                                     width, height, UTIL_FORMAT_DXT3_RGBA,
466
   }
-
 
467
}
-
 
468
 
-
 
469
void
-
 
470
util_format_dxt5_rgba_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride,
-
 
471
                                       const uint8_t *src, unsigned src_stride,
-
 
472
                                       unsigned width, unsigned height)
-
 
473
{
-
 
474
   const unsigned bw = 4, bh = 4, comps = 4, bytes_per_block = 16;
-
 
475
   unsigned x, y, i, j, k;
-
 
476
 
-
 
477
   for(y = 0; y < height; y += bh) {
-
 
478
      uint8_t *dst = dst_row;
-
 
479
      for(x = 0; x < width; x += bw) {
479
                                     16, FALSE);
480
         uint8_t tmp[4][4][4];  /* [bh][bw][comps] */
-
 
481
         for(j = 0; j < bh; ++j) {
-
 
482
            for(i = 0; i < bw; ++i) {
480
}
483
               for(k = 0; k < comps; ++k) {
-
 
484
                  tmp[j][i][k] = src[(y + j)*src_stride/sizeof(*src) + (x + i)*comps + k];
481
 
Line 485... Line 482...
485
               }
482
void
486
            }
483
util_format_dxt5_rgba_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride,
487
         }
484
                                       const uint8_t *src, unsigned src_stride,
488
         util_format_dxtn_pack(4, 4, 4, &tmp[0][0][0], UTIL_FORMAT_DXT5_RGBA, dst, 0);
485
                                       unsigned width, unsigned height)
-
 
486
{
-
 
487
   util_format_dxtn_pack_rgba_8unorm(dst_row, dst_stride, src, src_stride,
489
         dst += bytes_per_block;
488
                                     width, height, UTIL_FORMAT_DXT5_RGBA,
490
      }
489
                                     16, FALSE);
491
      dst_row += dst_stride / sizeof(*dst_row);
490
}
492
   }
491
 
493
}
492
static INLINE void
494
 
493
util_format_dxtn_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride,
495
void
494
                                     const float *src, unsigned src_stride,
496
util_format_dxt1_rgb_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride,
495
                                 unsigned width, unsigned height,
-
 
496
                                 enum util_format_dxtn format,
497
                                     const float *src, unsigned src_stride,
497
                                 unsigned block_size, boolean srgb)
498
                                     unsigned width, unsigned height)
498
{
-
 
499
   unsigned x, y, i, j, k;
-
 
500
   for(y = 0; y < height; y += 4) {
-
 
501
      uint8_t *dst = dst_row;
-
 
502
      for(x = 0; x < width; x += 4) {
-
 
503
         uint8_t tmp[4][4][4];
-
 
504
         for(j = 0; j < 4; ++j) {
499
{
505
            for(i = 0; i < 4; ++i) {
-
 
506
               float src_tmp;
-
 
507
               for(k = 0; k < 3; ++k) {
-
 
508
                  src_tmp = src[(y + j)*src_stride/sizeof(*src) + (x+i)*4 + k];
500
   unsigned x, y, i, j, k;
509
                  if (srgb) {
501
   for(y = 0; y < height; y += 4) {
510
                     tmp[j][i][k] = util_format_linear_float_to_srgb_8unorm(src_tmp);
502
      uint8_t *dst = dst_row;
511
                  }
503
      for(x = 0; x < width; x += 4) {
512
                  else {
504
         uint8_t tmp[4][4][3];
513
                     tmp[j][i][k] = float_to_ubyte(src_tmp);
505
         for(j = 0; j < 4; ++j) {
514
               }
506
            for(i = 0; i < 4; ++i) {
515
            }
507
               for(k = 0; k < 3; ++k) {
516
               /* for sake of simplicity there's an unneeded 4th component for dxt1_rgb */
Line 508... Line 517...
508
                  tmp[j][i][k] = float_to_ubyte(src[(y + j)*src_stride/sizeof(*src) + (x+i)*4 + k]);
517
               src_tmp = src[(y + j)*src_stride/sizeof(*src) + (x+i)*4 + 3];
509
               }
518
               tmp[j][i][3] = float_to_ubyte(src_tmp);
510
            }
519
            }
511
         }
520
         }
512
         util_format_dxtn_pack(3, 4, 4, &tmp[0][0][0], UTIL_FORMAT_DXT1_RGB, dst, 0);
521
         util_format_dxtn_pack(4, 4, 4, &tmp[0][0][0], format, dst, 0);
513
         dst += 8;
-
 
514
      }
-
 
515
      dst_row += 4*dst_stride/sizeof(*dst_row);
-
 
516
   }
-
 
517
}
-
 
518
 
-
 
519
void
-
 
520
util_format_dxt1_rgba_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride,
-
 
521
                                      const float *src, unsigned src_stride,
522
         dst += block_size;
522
                                      unsigned width, unsigned height)
-
 
523
{
-
 
524
   unsigned x, y, i, j, k;
-
 
525
   for(y = 0; y < height; y += 4) {
523
      }
526
      uint8_t *dst = dst_row;
-
 
527
      for(x = 0; x < width; x += 4) {
-
 
528
         uint8_t tmp[4][4][4];
524
      dst_row += 4*dst_stride/sizeof(*dst_row);
529
         for(j = 0; j < 4; ++j) {
525
   }
-
 
526
}
-
 
527
 
-
 
528
void
-
 
529
util_format_dxt1_rgb_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride,
-
 
530
                                     const float *src, unsigned src_stride,
-
 
531
                                     unsigned width, unsigned height)
-
 
532
{
-
 
533
   util_format_dxtn_pack_rgba_float(dst_row, dst_stride, src, src_stride,
-
 
534
                                    width, height, UTIL_FORMAT_DXT1_RGB,
530
            for(i = 0; i < 4; ++i) {
535
                                    8, FALSE);
Line 531... Line 536...
531
               for(k = 0; k < 4; ++k) {
536
}
532
                  tmp[j][i][k] = float_to_ubyte(src[(y + j)*src_stride/sizeof(*src) + (x+i)*4 + k]);
537
 
533
               }
538
void
534
            }
539
util_format_dxt1_rgba_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride,
535
         }
540
                                      const float *src, unsigned src_stride,
536
         util_format_dxtn_pack(4, 4, 4, &tmp[0][0][0], UTIL_FORMAT_DXT1_RGBA, dst, 0);
-
 
537
         dst += 8;
-
 
538
      }
-
 
539
      dst_row += 4*dst_stride/sizeof(*dst_row);
-
 
540
   }
-
 
541
}
-
 
542
 
-
 
543
void
-
 
544
util_format_dxt3_rgba_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride,
541
                                      unsigned width, unsigned height)
545
                                      const float *src, unsigned src_stride,
-
 
546
                                      unsigned width, unsigned height)
-
 
547
{
-
 
548
   unsigned x, y, i, j, k;
542
{
549
   for(y = 0; y < height; y += 4) {
-
 
550
      uint8_t *dst = dst_row;
-
 
551
      for(x = 0; x < width; x += 4) {
543
   util_format_dxtn_pack_rgba_float(dst_row, dst_stride, src, src_stride,
552
         uint8_t tmp[4][4][4];
-
 
553
         for(j = 0; j < 4; ++j) {
544
                                    width, height, UTIL_FORMAT_DXT1_RGBA,
Line 554... Line 545...
554
            for(i = 0; i < 4; ++i) {
545
                                    8, FALSE);
555
               for(k = 0; k < 4; ++k) {
546
}
556
                  tmp[j][i][k] = float_to_ubyte(src[(y + j)*src_stride/sizeof(*src) + (x+i)*4 + k]);
547
 
557
               }
548
void
558
            }
549
util_format_dxt3_rgba_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride,
559
         }
-
 
560
         util_format_dxtn_pack(4, 4, 4, &tmp[0][0][0], UTIL_FORMAT_DXT3_RGBA, dst, 0);
-
 
561
         dst += 16;
-
 
562
      }
-
 
563
      dst_row += 4*dst_stride/sizeof(*dst_row);
-
 
564
   }
-
 
565
}
-
 
566
 
-
 
567
void
550
                                      const float *src, unsigned src_stride,
568
util_format_dxt5_rgba_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride,
-
 
569
                                      const float *src, unsigned src_stride,
-
 
570
                                      unsigned width, unsigned height)
-
 
571
{
551
                                      unsigned width, unsigned height)
572
   unsigned x, y, i, j, k;
-
 
573
   for(y = 0; y < height; y += 4) {
-
 
574
      uint8_t *dst = dst_row;
552
{
575
      for(x = 0; x < width; x += 4) {
-
 
576
         uint8_t tmp[4][4][4];
553
   util_format_dxtn_pack_rgba_float(dst_row, dst_stride, src, src_stride,
Line 577... Line 554...
577
         for(j = 0; j < 4; ++j) {
554
                                    width, height, UTIL_FORMAT_DXT3_RGBA,
578
            for(i = 0; i < 4; ++i) {
555
                                    16, FALSE);
579
               for(k = 0; k < 4; ++k) {
-
 
580
                  tmp[j][i][k] = float_to_ubyte(src[(y + j)*src_stride/sizeof(*src) + (x+i)*4 + k]);
-
 
581
               }
556
}
Line 582... Line 557...
582
            }
557
 
583
         }
558
void
584
         util_format_dxtn_pack(4, 4, 4, &tmp[0][0][0], UTIL_FORMAT_DXT5_RGBA, dst, 0);
559
util_format_dxt5_rgba_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride,
-
 
560
                                      const float *src, unsigned src_stride,
585
         dst += 16;
561
                                      unsigned width, unsigned height)
-
 
562
{
-
 
563
   util_format_dxtn_pack_rgba_float(dst_row, dst_stride, src, src_stride,
-
 
564
                                    width, height, UTIL_FORMAT_DXT5_RGBA,
-
 
565
                                    16, FALSE);
586
      }
566
}
Line 587... Line 567...
587
      dst_row += 4*dst_stride/sizeof(*dst_row);
567
 
588
   }
568
 
589
}
569
/*
-
 
570
 * SRGB variants.
590
 
571
 */
-
 
572
 
-
 
573
void
-
 
574
util_format_dxt1_srgb_fetch_rgba_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j)
-
 
575
{
591
 
576
   uint8_t tmp[4];
Line 592... Line 577...
592
/*
577
   util_format_dxt1_rgb_fetch(0, src, i, j, tmp);
593
 * SRGB variants.
578
   dst[0] = util_format_srgb_to_linear_8unorm(tmp[0]);
594
 *
579
   dst[1] = util_format_srgb_to_linear_8unorm(tmp[1]);
-
 
580
   dst[2] = util_format_srgb_to_linear_8unorm(tmp[2]);
595
 * FIXME: shunts to RGB for now
581
   dst[3] = 255;
-
 
582
}
-
 
583
 
-
 
584
void
-
 
585
util_format_dxt1_srgba_fetch_rgba_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j)
596
 */
586
{
Line 597... Line 587...
597
 
587
   uint8_t tmp[4];
598
void
588
   util_format_dxt1_rgba_fetch(0, src, i, j, tmp);
599
util_format_dxt1_srgb_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
589
   dst[0] = util_format_srgb_to_linear_8unorm(tmp[0]);
-
 
590
   dst[1] = util_format_srgb_to_linear_8unorm(tmp[1]);
600
{
591
   dst[2] = util_format_srgb_to_linear_8unorm(tmp[2]);
-
 
592
   dst[3] = tmp[3];
-
 
593
}
-
 
594
 
-
 
595
void
601
   util_format_dxt1_rgb_unpack_rgba_8unorm(dst_row, dst_stride, src_row, src_stride, width, height);
596
util_format_dxt3_srgba_fetch_rgba_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j)
Line 602... Line 597...
602
}
597
{
603
 
598
   uint8_t tmp[4];
604
void
599
   util_format_dxt3_rgba_fetch(0, src, i, j, tmp);
-
 
600
   dst[0] = util_format_srgb_to_linear_8unorm(tmp[0]);
605
util_format_dxt1_srgb_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
601
   dst[1] = util_format_srgb_to_linear_8unorm(tmp[1]);
-
 
602
   dst[2] = util_format_srgb_to_linear_8unorm(tmp[2]);
-
 
603
   dst[3] = tmp[3];
-
 
604
}
-
 
605
 
606
{
606
void
Line 607... Line 607...
607
   util_format_dxt1_rgb_pack_rgba_8unorm(dst_row, dst_stride, src_row, src_stride, width, height);
607
util_format_dxt5_srgba_fetch_rgba_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j)
608
}
608
{
609
 
609
   uint8_t tmp[4];
-
 
610
   util_format_dxt5_rgba_fetch(0, src, i, j, tmp);
610
void
611
   dst[0] = util_format_srgb_to_linear_8unorm(tmp[0]);
-
 
612
   dst[1] = util_format_srgb_to_linear_8unorm(tmp[1]);
-
 
613
   dst[2] = util_format_srgb_to_linear_8unorm(tmp[2]);
-
 
614
   dst[3] = tmp[3];
-
 
615
}
611
util_format_dxt1_srgb_fetch_rgba_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j)
616
 
Line 612... Line 617...
612
{
617
void
613
   util_format_dxt1_rgb_fetch_rgba_8unorm(dst, src, i, j);
618
util_format_dxt1_srgb_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j)
614
}
619
{
-
 
620
   uint8_t tmp[4];
615
 
621
   util_format_dxt1_rgb_fetch(0, src, i, j, tmp);
-
 
622
   dst[0] = util_format_srgb_8unorm_to_linear_float(tmp[0]);
-
 
623
   dst[1] = util_format_srgb_8unorm_to_linear_float(tmp[1]);
-
 
624
   dst[2] = util_format_srgb_8unorm_to_linear_float(tmp[2]);
-
 
625
   dst[3] = 1.0f;
616
void
626
}
Line 617... Line 627...
617
util_format_dxt1_srgba_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
627
 
618
{
628
void
619
   util_format_dxt1_rgba_unpack_rgba_8unorm(dst_row, dst_stride, src_row, src_stride, width, height);
629
util_format_dxt1_srgba_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j)
-
 
630
{
620
}
631
   uint8_t tmp[4];
-
 
632
   util_format_dxt1_rgba_fetch(0, src, i, j, tmp);
-
 
633
   dst[0] = util_format_srgb_8unorm_to_linear_float(tmp[0]);
-
 
634
   dst[1] = util_format_srgb_8unorm_to_linear_float(tmp[1]);
-
 
635
   dst[2] = util_format_srgb_8unorm_to_linear_float(tmp[2]);
621
 
636
   dst[3] = ubyte_to_float(tmp[3]);
Line 622... Line 637...
622
void
637
}
623
util_format_dxt1_srgba_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
638
 
624
{
639
void
625
   util_format_dxt1_rgba_pack_rgba_8unorm(dst_row, dst_stride, src_row, src_stride, width, height);
640
util_format_dxt3_srgba_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j)
-
 
641
{
-
 
642
   uint8_t tmp[4];
-
 
643
   util_format_dxt3_rgba_fetch(0, src, i, j, tmp);
-
 
644
   dst[0] = util_format_srgb_8unorm_to_linear_float(tmp[0]);
626
}
645
   dst[1] = util_format_srgb_8unorm_to_linear_float(tmp[1]);
Line 627... Line 646...
627
 
646
   dst[2] = util_format_srgb_8unorm_to_linear_float(tmp[2]);
628
void
647
   dst[3] = ubyte_to_float(tmp[3]);
629
util_format_dxt1_srgba_fetch_rgba_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j)
648
}
630
{
649
 
-
 
650
void
-
 
651
util_format_dxt5_srgba_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j)
-
 
652
{
-
 
653
   uint8_t tmp[4];
631
   util_format_dxt1_rgba_fetch_rgba_8unorm(dst, src, i, j);
654
   util_format_dxt5_rgba_fetch(0, src, i, j, tmp);
Line 632... Line 655...
632
}
655
   dst[0] = util_format_srgb_8unorm_to_linear_float(tmp[0]);
633
 
656
   dst[1] = util_format_srgb_8unorm_to_linear_float(tmp[1]);
634
void
657
   dst[2] = util_format_srgb_8unorm_to_linear_float(tmp[2]);
635
util_format_dxt3_srgba_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
658
   dst[3] = ubyte_to_float(tmp[3]);
-
 
659
}
-
 
660
 
-
 
661
void
-
 
662
util_format_dxt1_srgb_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
636
{
663
{
Line 637... Line 664...
637
   util_format_dxt3_rgba_unpack_rgba_8unorm(dst_row, dst_stride, src_row, src_stride, width, height);
664
   util_format_dxtn_rgb_unpack_rgba_8unorm(dst_row, dst_stride,
638
}
665
                                           src_row, src_stride,
639
 
666
                                           width, height,
640
void
667
                                           util_format_dxt1_rgb_fetch,
-
 
668
                                           8, TRUE);
-
 
669
}
-
 
670
 
-
 
671
void
641
util_format_dxt3_srgba_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
672
util_format_dxt1_srgba_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
Line 642... Line 673...
642
{
673
{
643
   util_format_dxt3_rgba_pack_rgba_8unorm(dst_row, dst_stride, src_row, src_stride, width, height);
674
   util_format_dxtn_rgb_unpack_rgba_8unorm(dst_row, dst_stride,
644
}
675
                                           src_row, src_stride,
645
 
676
                                           width, height,
-
 
677
                                           util_format_dxt1_rgba_fetch,
-
 
678
                                           8, TRUE);
-
 
679
}
-
 
680
 
646
void
681
void
Line 647... Line 682...
647
util_format_dxt3_srgba_fetch_rgba_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j)
682
util_format_dxt3_srgba_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
648
{
683
{
649
   util_format_dxt3_rgba_fetch_rgba_8unorm(dst, src, i, j);
684
   util_format_dxtn_rgb_unpack_rgba_8unorm(dst_row, dst_stride,
650
}
685
                                           src_row, src_stride,
-
 
686
                                           width, height,
-
 
687
                                           util_format_dxt3_rgba_fetch,
-
 
688
                                           16, TRUE);
-
 
689
}
651
 
690
 
Line 652... Line 691...
652
void
691
void
653
util_format_dxt5_srgba_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
692
util_format_dxt5_srgba_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
654
{
693
{
655
   util_format_dxt5_rgba_unpack_rgba_8unorm(dst_row, dst_stride, src_row, src_stride, width, height);
694
   util_format_dxtn_rgb_unpack_rgba_8unorm(dst_row, dst_stride,
-
 
695
                                           src_row, src_stride,
-
 
696
                                           width, height,
-
 
697
                                           util_format_dxt5_rgba_fetch,
-
 
698
                                           16, TRUE);
656
}
699
}
Line 657... Line 700...
657
 
700
 
658
void
701
void
659
util_format_dxt5_srgba_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
702
util_format_dxt1_srgb_unpack_rgba_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
660
{
703
{
-
 
704
   util_format_dxtn_rgb_unpack_rgba_float(dst_row, dst_stride,
-
 
705
                                          src_row, src_stride,
-
 
706
                                          width, height,
-
 
707
                                          util_format_dxt1_rgb_fetch,
661
   util_format_dxt5_rgba_pack_rgba_8unorm(dst_row, dst_stride, src_row, src_stride, width, height);
708
                                          8, TRUE);
Line 662... Line 709...
662
}
709
}
663
 
710
 
664
void
711
void
665
util_format_dxt5_srgba_fetch_rgba_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j)
712
util_format_dxt1_srgba_unpack_rgba_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
-
 
713
{
-
 
714
   util_format_dxtn_rgb_unpack_rgba_float(dst_row, dst_stride,
666
{
715
                                          src_row, src_stride,
Line 667... Line 716...
667
   util_format_dxt5_rgba_fetch_rgba_8unorm(dst, src, i, j);
716
                                          width, height,
668
}
717
                                          util_format_dxt1_rgba_fetch,
669
 
718
                                          8, TRUE);
670
void
719
}
-
 
720
 
-
 
721
void
671
util_format_dxt1_srgb_unpack_rgba_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
722
util_format_dxt3_srgba_unpack_rgba_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
Line 672... Line 723...
672
{
723
{
673
   util_format_dxt1_rgb_unpack_rgba_float(dst_row, dst_stride, src_row, src_stride, width, height);
724
   util_format_dxtn_rgb_unpack_rgba_float(dst_row, dst_stride,
674
}
725
                                          src_row, src_stride,
675
 
726
                                          width, height,
-
 
727
                                          util_format_dxt3_rgba_fetch,
-
 
728
                                          16, TRUE);
676
void
729
}
Line 677... Line 730...
677
util_format_dxt1_srgb_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height)
730
 
678
{
731
void
679
   util_format_dxt1_rgb_pack_rgba_float(dst_row, dst_stride, src_row, src_stride, width, height);
732
util_format_dxt5_srgba_unpack_rgba_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
680
}
733
{
-
 
734
   util_format_dxtn_rgb_unpack_rgba_float(dst_row, dst_stride,
-
 
735
                                          src_row, src_stride,
681
 
736
                                          width, height,
Line 682... Line 737...
682
void
737
                                          util_format_dxt5_rgba_fetch,
683
util_format_dxt1_srgb_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j)
738
                                          16, TRUE);
684
{
739
}
685
   util_format_dxt1_rgb_fetch_rgba_float(dst, src, i, j);
740
 
-
 
741
void
-
 
742
util_format_dxt1_srgb_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
686
}
743
{
Line 687... Line 744...
687
 
744
   util_format_dxtn_pack_rgba_8unorm(dst_row, dst_stride, src_row, src_stride,
688
void
745
                                     width, height, UTIL_FORMAT_DXT1_RGB,
689
util_format_dxt1_srgba_unpack_rgba_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
746
                                     8, TRUE);
690
{
747
}
-
 
748
 
-
 
749
void
691
   util_format_dxt1_rgba_unpack_rgba_float(dst_row, dst_stride, src_row, src_stride, width, height);
750
util_format_dxt1_srgba_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
Line 692... Line 751...
692
}
751
{
693
 
752
   util_format_dxtn_pack_rgba_8unorm(dst_row, dst_stride, src_row, src_stride,
694
void
753
                                     width, height, UTIL_FORMAT_DXT1_RGBA,
695
util_format_dxt1_srgba_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height)
754
                                     8, TRUE);
-
 
755
}
-
 
756
 
696
{
757
void
Line 697... Line 758...
697
   util_format_dxt1_rgba_pack_rgba_float(dst_row, dst_stride, src_row, src_stride, width, height);
758
util_format_dxt3_srgba_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
698
}
759
{
699
 
760
   util_format_dxtn_pack_rgba_8unorm(dst_row, dst_stride, src_row, src_stride,
700
void
761
                                     width, height, UTIL_FORMAT_DXT3_RGBA,
-
 
762
                                     16, TRUE);
-
 
763
}
701
util_format_dxt1_srgba_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j)
764