5 struct tga *tga_read(const char *filename) {
6 FILE *stream = fopen(filename, "rb");
12 struct tga *p = malloc(sizeof(struct tga));
17 if (fread(&p->head, sizeof(struct tga_head), 1, stream) != 1) {
22 if (p->head.image_type != 2) {
23 fprintf(stderr, "image_type %d, should be 2\n", p->head.image_type);
27 if (fseek(stream, p->head.id_length, SEEK_CUR)) {
35 p->head.image_depth / 8
37 if (fread(array_index0(p->data), p->data->stride[0], 1, stream) != 1) {
46 void tga_free(struct tga *self) {
47 array_free(self->data);