Skip to content

Commit

Permalink
get rid of unused return value from write callback
Browse files Browse the repository at this point in the history
  • Loading branch information
nothings committed Sep 14, 2015
1 parent b447780 commit 93b2b82
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
13 changes: 8 additions & 5 deletions stb_image_write.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* stb_image_write - v1.00 - public domain - http://nothings.org/stb/stb_image_write.h
writes out PNG/BMP/TGA images to C stdio - Sean Barrett 2010
writes out PNG/BMP/TGA images to C stdio - Sean Barrett 2010-2015
no warranty implied; use at your own risk
Before #including,
Expand Down Expand Up @@ -44,6 +44,9 @@
int stbi_write_tga_to_func(stbi_write_func *func, void *context, int w, int h, int comp, const void *data);
int stbi_write_hdr_to_func(stbi_write_func *func, void *context, int w, int h, int comp, const float *data);
where the callback is:
void stbi_write_func(void *context, void *data, int size);
You can define STBI_WRITE_NO_STDIO to disable the file variant of these
functions, so the library will not use stdio.h at all. However, this will
also disable HDR writing, because it requires stdio for formatted output.
Expand Down Expand Up @@ -125,7 +128,7 @@ STBIWDEF int stbi_write_tga(char const *filename, int w, int h, int comp, const
STBIWDEF int stbi_write_hdr(char const *filename, int w, int h, int comp, const float *data);
#endif

typedef int stbi_write_func(void *context, void *data, int size);
typedef void stbi_write_func(void *context, void *data, int size);

STBIWDEF int stbi_write_png_to_func(stbi_write_func *func, void *context, int w, int h, int comp, const void *data, int stride_in_bytes);
STBIWDEF int stbi_write_bmp_to_func(stbi_write_func *func, void *context, int w, int h, int comp, const void *data);
Expand Down Expand Up @@ -192,15 +195,15 @@ static void stbi__start_write_callbacks(stbi__write_context *s, stbi_write_func

#ifndef STBI_WRITE_NO_STDIO

static int stbi__stdio_write(void *user, void *data, int size)
static void stbi__stdio_write(void *context, void *data, int size)
{
return (int) fwrite(data,1,size,(FILE*) user);
fwrite(data,1,size,(FILE*) context);
}

static int stbi__start_write_file(stbi__write_context *s, const char *filename)
{
FILE *f = fopen(filename, "wb");
stbi__start_write_callbacks(s, &stbi__stdio_write, (void *) f);
stbi__start_write_callbacks(s, stbi__stdio_write, (void *) f);
return f != NULL;
}

Expand Down
5 changes: 4 additions & 1 deletion tests/image_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ void test_ycbcr(void)

float hdr_data[200][200][3];

void dummy(void *context, void *data, int len)
void dummy_write(void *context, void *data, int len)
{
static char dummy[1024];
if (len > 1024) len = 1024;
Expand Down Expand Up @@ -97,6 +97,9 @@ int main(int argc, char **argv)
stbi_write_png(stb_sprintf("output/%s.png", fname), w, h, 4, data, w*4);
stbi_write_bmp(stb_sprintf("output/%s.bmp", fname), w, h, 4, data);
stbi_write_tga(stb_sprintf("output/%s.tga", fname), w, h, 4, data);
stbi_write_png_to_func(dummy_write,0, w, h, 4, data, w*4);
stbi_write_bmp_to_func(dummy_write,0, w, h, 4, data);
stbi_write_tga_to_func(dummy_write,0, w, h, 4, data);
free(data);
} else
printf("FAILED 4\n");
Expand Down

0 comments on commit 93b2b82

Please sign in to comment.