unsigned char filler[58]; /* fill to struct size of 128 */
};
+/* global PCX error value */
+int errno_pcx = PCX_Success;
+
static byte *PCX_ReadBitmap(Image *image, byte *buffer_ptr, byte *buffer_last)
{
/* Run Length Encoding: If the two high bits are set,
int width, height, depth;
int i;
+ errno_pcx = PCX_Success;
+
if (!(file = fopen(filename, "r")))
+ {
+ errno_pcx = PCX_OpenFailed;
return NULL;
+ }
if (fseek(file, 0, SEEK_END) == -1)
{
fclose(file);
+ errno_pcx = PCX_ReadFailed;
return NULL;
}
file_length = ftell(file);
rewind(file);
- if (file_length < PCX_HEADER_SIZE + PCX_COLORMAP_SIZE)
+ if (file_length < PCX_HEADER_SIZE)
{
+ /* PCX file is too short to contain a valid PCX header */
fclose(file);
+ errno_pcx = PCX_FileInvalid;
return NULL;
}
if (fread(file_buffer, 1, file_length, file) != file_length)
{
fclose(file);
+ errno_pcx = PCX_ReadFailed;
return NULL;
}
width < 0 || height < 0)
{
free(file_buffer);
+ errno_pcx = PCX_FileInvalid;
return NULL;
}
filename, pcx.xmax, pcx.ymax,
pcx.color_planes);
printf("depth: %d\n", pcx.bits_per_pixel);
+ printf("color_planes: %d\n", pcx.color_planes);
printf("bytes_per_line: %d\n", pcx.bytes_per_line);
printf("palette type: %s\n",
(pcx.palette_type == 1 ? "color" :
{
free(file_buffer);
freeImage(image);
+ errno_pcx = PCX_FileInvalid;
+ return NULL;
+ }
+
+ if (file_length < PCX_HEADER_SIZE + PCX_COLORMAP_SIZE)
+ {
+ /* PCX file is too short to contain a valid 256 colors colormap */
+ fclose(file);
+ errno_pcx = PCX_ColorFailed;
return NULL;
}
{
free(file_buffer);
freeImage(image);
+ errno_pcx = PCX_ColorFailed;
return NULL;
}