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,
};

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

screen = malloc(WIDTH * HEIGHT / 6);

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

img = pipi_new(WIDTH, HEIGHT);
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->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)
{
uint8_t screen[WIDTH * HEIGHT / 6];
pipi_image_t *tmp = NULL;
pipi_pixels_t *p;
float *data;
uint8_t *screen;
FILE *fp;
size_t len;

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

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

free(screen);

return 0;
}



Loading…
Cancel
Save