MCPcopy Create free account
hub / github.com/DISTRHO/Cardinal / stbiw__write_hdr_scanline

Function stbiw__write_hdr_scanline

include/stb_image_write.h:515–602  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

513}
514
515void stbiw__write_hdr_scanline(stbi__write_context *s, int width, int ncomp, unsigned char *scratch, float *scanline)
516{
517 unsigned char scanlineheader[4] = { 2, 2, 0, 0 };
518 unsigned char rgbe[4];
519 float linear[3];
520 int x;
521
522 scanlineheader[2] = (width&0xff00)>>8;
523 scanlineheader[3] = (width&0x00ff);
524
525 /* skip RLE for images too small or large */
526 if (width < 8 || width >= 32768) {
527 for (x=0; x < width; x++) {
528 switch (ncomp) {
529 case 4: /* fallthrough */
530 case 3: linear[2] = scanline[x*ncomp + 2];
531 linear[1] = scanline[x*ncomp + 1];
532 linear[0] = scanline[x*ncomp + 0];
533 break;
534 default:
535 linear[0] = linear[1] = linear[2] = scanline[x*ncomp + 0];
536 break;
537 }
538 stbiw__linear_to_rgbe(rgbe, linear);
539 s->func(s->context, rgbe, 4);
540 }
541 } else {
542 int c,r;
543 /* encode into scratch buffer */
544 for (x=0; x < width; x++) {
545 switch(ncomp) {
546 case 4: /* fallthrough */
547 case 3: linear[2] = scanline[x*ncomp + 2];
548 linear[1] = scanline[x*ncomp + 1];
549 linear[0] = scanline[x*ncomp + 0];
550 break;
551 default:
552 linear[0] = linear[1] = linear[2] = scanline[x*ncomp + 0];
553 break;
554 }
555 stbiw__linear_to_rgbe(rgbe, linear);
556 scratch[x + width*0] = rgbe[0];
557 scratch[x + width*1] = rgbe[1];
558 scratch[x + width*2] = rgbe[2];
559 scratch[x + width*3] = rgbe[3];
560 }
561
562 s->func(s->context, scanlineheader, 4);
563
564 /* RLE each component separately */
565 for (c=0; c < 4; c++) {
566 unsigned char *comp = &scratch[width*c];
567
568 x = 0;
569 while (x < width) {
570 // find first run
571 r = x;
572 while (r+2 < width) {

Callers 1

stbi_write_hdr_coreFunction · 0.85

Calls 3

stbiw__linear_to_rgbeFunction · 0.85
stbiw__write_dump_dataFunction · 0.85
stbiw__write_run_dataFunction · 0.85

Tested by

no test coverage detected