Skip to content
Myr

a few more stb_image_write fixes

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Sean Barrett · committed by Sean Barrett · parent 9bf98d6 · Browse files · 1 file+20 added−13 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+20 added−13 removed

  • other:+20 added−13 removed

1 file+20 added−13 removed

modified:stb_image_write.h+20 added-13 removed
73 unmodified lines
74 Tim Kelsey75 bugfixes:76 github:Chribba77 Guillaume Chereau78 github:jry279 80LICENSE8182This software is in the public domain. Where that dedication is not
26 unmodified lines
109#endif//INCLUDE_STB_IMAGE_WRITE_H110111#ifdef STB_IMAGE_WRITE_IMPLEMENTATION112113#ifdef _WIN32114 #define _CRT_SECURE_NO_WARNINGS115 #define _CRT_NONSTDC_NO_DEPRECATE116#endif117118#include <stdarg.h>119#include <stdlib.h>120#include <stdio.h>121#include <string.h>
170 unmodified lines
292 fwrite(&lengthbyte, 1, 1, f);293 fwrite(data, length, 1, f);294}295290void stbiw__write_hdr_scanline(FILE *f, int width, int comp, unsigned char *scratch, const float *scanline)296void stbiw__write_hdr_scanline(FILE *f, int width, int ncomp, unsigned char *scratch, const float *scanline)297{298 unsigned char scanlineheader[4] = { 2, 2, 0, 0 };299 unsigned char rgbe[4];300 float linear[3];
4 unmodified lines
305306 /* skip RLE for images too small or large */307 if (width < 8 || width >= 32768) {308 for (x=0; x < width; x++) {303 switch (comp) {309 switch (ncomp) {310 case 4: /* fallthrough */305 case 3: linear[2] = scanline[x*comp + 2];306 linear[1] = scanline[x*comp + 1];307 linear[0] = scanline[x*comp + 0];311 case 3: linear[2] = scanline[x*ncomp + 2];312 linear[1] = scanline[x*ncomp + 1];313 linear[0] = scanline[x*ncomp + 0];314 break;315 default:310 linear[0] = linear[1] = linear[2] = scanline[x*comp + 0];316 linear[0] = linear[1] = linear[2] = scanline[x*ncomp + 0];317 break;318 }319 stbiw__linear_to_rgbe(rgbe, linear);320 fwrite(rgbe, 4, 1, f);
1 unmodified line
322 } else {323 int c,r;324 /* encode into scratch buffer */325 for (x=0; x < width; x++) {320 switch(comp) {326 switch(ncomp) {327 case 4: /* fallthrough */322 case 3: linear[2] = scanline[x*comp + 2];323 linear[1] = scanline[x*comp + 1];324 linear[0] = scanline[x*comp + 0];328 case 3: linear[2] = scanline[x*ncomp + 2];329 linear[1] = scanline[x*ncomp + 1];330 linear[0] = scanline[x*ncomp + 0];331 break;332 default:327 linear[0] = linear[1] = linear[2] = scanline[x*comp + 0];333 linear[0] = linear[1] = linear[2] = scanline[x*ncomp + 0];334 break;335 }336 stbiw__linear_to_rgbe(rgbe, linear);337 scratch[x + width*0] = rgbe[0];
229 unmodified lines
567 (void) stbiw__sbfree(hash_table[i]);568569 {570 // compute adler32 on input565 unsigned int i=0, s1=1, s2=0, blocklen = data_len % 5552;566 int j=0;571 unsigned int k=0, s1=1, s2=0;572 int blocklen = (int) (data_len % 5552);573 j=0;574 while (j < data_len) {575 for (i=0; i < blocklen; ++i) s1 += data[j+i], s2 += s1;576 s1 %= 65521, s2 %= 65521;577 j += blocklen;
174 unmodified lines