Browse Source

libpipi: replace large stack buffer allocations with malloc().

git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/libpipi/trunk@2941 92316355-f0b4-4df1-b90c-862c8a59935f
remotes/tiles
sam 16 years ago
parent
commit
d8f42fb418
1 changed files with 15 additions and 3 deletions
  1. +15
    -3
      pipi/codec/oric.c

+ 15
- 3
pipi/codec/oric.c View File

@@ -50,14 +50,18 @@ pipi_image_t *pipi_load_oric(char const *name)
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
}; };


uint8_t screen[WIDTH * HEIGHT / 6];
pipi_image_t *img; pipi_image_t *img;
pipi_pixels_t *p; pipi_pixels_t *p;
uint8_t *data;
uint8_t *screen, *data;
int x, y, i; int x, y, i;


screen = malloc(WIDTH * HEIGHT / 6);

if(read_screen(name, screen) < 0) if(read_screen(name, screen) < 0)
{
free(screen);
return NULL; return NULL;
}


img = pipi_new(WIDTH, HEIGHT); img = pipi_new(WIDTH, HEIGHT);
p = pipi_getpixels(img, PIPI_PIXELS_RGBA_C); p = pipi_getpixels(img, PIPI_PIXELS_RGBA_C);
@@ -99,6 +103,8 @@ pipi_image_t *pipi_load_oric(char const *name)
} }
} }


free(screen);

img->codec_priv = NULL; img->codec_priv = NULL;


img->wrap = 0; img->wrap = 0;
@@ -109,10 +115,10 @@ pipi_image_t *pipi_load_oric(char const *name)


int pipi_save_oric(pipi_image_t *img, char const *name) int pipi_save_oric(pipi_image_t *img, char const *name)
{ {
uint8_t screen[WIDTH * HEIGHT / 6];
pipi_image_t *tmp = NULL; pipi_image_t *tmp = NULL;
pipi_pixels_t *p; pipi_pixels_t *p;
float *data; float *data;
uint8_t *screen;
FILE *fp; FILE *fp;
size_t len; size_t len;


@@ -140,13 +146,19 @@ int pipi_save_oric(pipi_image_t *img, char const *name)
else else
p = pipi_getpixels(img, PIPI_PIXELS_RGBA_F); p = pipi_getpixels(img, PIPI_PIXELS_RGBA_F);
data = p->pixels; data = p->pixels;
screen = malloc(WIDTH * HEIGHT / 6);
write_screen(data, screen); write_screen(data, screen);
if(tmp) if(tmp)
{
free(screen);
pipi_free(tmp); pipi_free(tmp);
}


fwrite(screen, 1, WIDTH * HEIGHT / 6, fp); fwrite(screen, 1, WIDTH * HEIGHT / 6, fp);
fclose(fp); fclose(fp);


free(screen);

return 0; return 0;
} }




Loading…
Cancel
Save