Fixed read error with existing image data. Introduced tga_clear_error().
This commit is contained in:
@@ -41,6 +41,7 @@ typedef struct NyTGA_Image {
|
||||
TGAError TGA_ERR;
|
||||
|
||||
TGAError tga_error(void); /* Returns the current error, if any. */
|
||||
void tga_clear_error(void);
|
||||
TGAImage *read_tga_image(FILE *file);
|
||||
TGAImage *new_tga_image(TGAColorType type, uint8_t depth,
|
||||
uint16_t width, uint16_t height);
|
||||
|
||||
@@ -143,7 +143,8 @@ static int _read_tga_image_data(TGAImage *image, FILE *file)
|
||||
{
|
||||
if(!_tga_sanity(image))
|
||||
goto error;
|
||||
check(!image->data, TGA_IMAGE_IMMUTABLE_ERR, "Image data exists already.");
|
||||
if(image->data)
|
||||
free(image->data);
|
||||
check(file, TGA_INV_FILE_PNT, "Invalid File Pointer passed.");
|
||||
uint32_t offset = (uint32_t)TGA_HEADER_SIZE + image->_meta->id_length +
|
||||
(image->_meta->c_map_length * (image->_meta->c_map_depth/8)) +
|
||||
|
||||
@@ -287,3 +287,8 @@ TGAError tga_error()
|
||||
{
|
||||
return TGA_ERR;
|
||||
}
|
||||
|
||||
void tga_clear_error()
|
||||
{
|
||||
TGA_ERR = TGA_NO_ERR;
|
||||
}
|
||||
|
||||
10
src/test.c
10
src/test.c
@@ -19,10 +19,16 @@ int main(int argc, char **argv)
|
||||
|
||||
FILE *img_file = fopen(argv[1], "rb");
|
||||
if(!img_file)
|
||||
return 1;
|
||||
{
|
||||
fprintf(stderr, "Unable to open image file.\n");
|
||||
return tga_error();
|
||||
}
|
||||
TGAImage *img = read_tga_image(img_file);
|
||||
if(!img)
|
||||
return 1;
|
||||
{
|
||||
fprintf(stderr, "Unable to read image.");
|
||||
return tga_error();
|
||||
}
|
||||
print_tga_data(img);
|
||||
free_tga_image(img);
|
||||
fclose(img_file);
|
||||
|
||||
Reference in New Issue
Block a user