mirror of
https://github.com/nothings/stb
synced 2025-01-18 20:29:20 +03:00
a few more stb_image_write fixes
This commit is contained in:
parent
9bf98d619f
commit
a84daa614e
@ -75,6 +75,7 @@ CREDITS:
|
|||||||
bugfixes:
|
bugfixes:
|
||||||
github:Chribba
|
github:Chribba
|
||||||
Guillaume Chereau
|
Guillaume Chereau
|
||||||
|
github:jry2
|
||||||
|
|
||||||
LICENSE
|
LICENSE
|
||||||
|
|
||||||
@ -109,6 +110,11 @@ STBIWDEF int stbi_write_hdr(char const *filename, int w, int h, int comp, const
|
|||||||
|
|
||||||
#ifdef STB_IMAGE_WRITE_IMPLEMENTATION
|
#ifdef STB_IMAGE_WRITE_IMPLEMENTATION
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
#define _CRT_SECURE_NO_WARNINGS
|
||||||
|
#define _CRT_NONSTDC_NO_DEPRECATE
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@ -287,7 +293,7 @@ void stbiw__write_dump_data(FILE *f, int length, unsigned char *data)
|
|||||||
fwrite(data, length, 1, f);
|
fwrite(data, length, 1, f);
|
||||||
}
|
}
|
||||||
|
|
||||||
void stbiw__write_hdr_scanline(FILE *f, int width, int comp, unsigned char *scratch, const float *scanline)
|
void stbiw__write_hdr_scanline(FILE *f, int width, int ncomp, unsigned char *scratch, const float *scanline)
|
||||||
{
|
{
|
||||||
unsigned char scanlineheader[4] = { 2, 2, 0, 0 };
|
unsigned char scanlineheader[4] = { 2, 2, 0, 0 };
|
||||||
unsigned char rgbe[4];
|
unsigned char rgbe[4];
|
||||||
@ -300,14 +306,14 @@ void stbiw__write_hdr_scanline(FILE *f, int width, int comp, unsigned char *scra
|
|||||||
/* skip RLE for images too small or large */
|
/* skip RLE for images too small or large */
|
||||||
if (width < 8 || width >= 32768) {
|
if (width < 8 || width >= 32768) {
|
||||||
for (x=0; x < width; x++) {
|
for (x=0; x < width; x++) {
|
||||||
switch (comp) {
|
switch (ncomp) {
|
||||||
case 4: /* fallthrough */
|
case 4: /* fallthrough */
|
||||||
case 3: linear[2] = scanline[x*comp + 2];
|
case 3: linear[2] = scanline[x*ncomp + 2];
|
||||||
linear[1] = scanline[x*comp + 1];
|
linear[1] = scanline[x*ncomp + 1];
|
||||||
linear[0] = scanline[x*comp + 0];
|
linear[0] = scanline[x*ncomp + 0];
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
linear[0] = linear[1] = linear[2] = scanline[x*comp + 0];
|
linear[0] = linear[1] = linear[2] = scanline[x*ncomp + 0];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
stbiw__linear_to_rgbe(rgbe, linear);
|
stbiw__linear_to_rgbe(rgbe, linear);
|
||||||
@ -317,14 +323,14 @@ void stbiw__write_hdr_scanline(FILE *f, int width, int comp, unsigned char *scra
|
|||||||
int c,r;
|
int c,r;
|
||||||
/* encode into scratch buffer */
|
/* encode into scratch buffer */
|
||||||
for (x=0; x < width; x++) {
|
for (x=0; x < width; x++) {
|
||||||
switch(comp) {
|
switch(ncomp) {
|
||||||
case 4: /* fallthrough */
|
case 4: /* fallthrough */
|
||||||
case 3: linear[2] = scanline[x*comp + 2];
|
case 3: linear[2] = scanline[x*ncomp + 2];
|
||||||
linear[1] = scanline[x*comp + 1];
|
linear[1] = scanline[x*ncomp + 1];
|
||||||
linear[0] = scanline[x*comp + 0];
|
linear[0] = scanline[x*ncomp + 0];
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
linear[0] = linear[1] = linear[2] = scanline[x*comp + 0];
|
linear[0] = linear[1] = linear[2] = scanline[x*ncomp + 0];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
stbiw__linear_to_rgbe(rgbe, linear);
|
stbiw__linear_to_rgbe(rgbe, linear);
|
||||||
@ -562,8 +568,9 @@ unsigned char * stbi_zlib_compress(unsigned char *data, int data_len, int *out_l
|
|||||||
|
|
||||||
{
|
{
|
||||||
// compute adler32 on input
|
// compute adler32 on input
|
||||||
unsigned int i=0, s1=1, s2=0, blocklen = data_len % 5552;
|
unsigned int k=0, s1=1, s2=0;
|
||||||
int j=0;
|
int blocklen = (int) (data_len % 5552);
|
||||||
|
j=0;
|
||||||
while (j < data_len) {
|
while (j < data_len) {
|
||||||
for (i=0; i < blocklen; ++i) s1 += data[j+i], s2 += s1;
|
for (i=0; i < blocklen; ++i) s1 += data[j+i], s2 += s1;
|
||||||
s1 %= 65521, s2 %= 65521;
|
s1 %= 65521, s2 %= 65521;
|
||||||
|
Loading…
Reference in New Issue
Block a user