}
}
+static inline unsigned short le16_to_cpu (unsigned short val)
+{
+ union {
+ unsigned char pval[2];
+ unsigned short val;
+ } swapped;
+ swapped.val = val;
+ return (swapped.pval[1] << 8) + swapped.pval[0];
+}
+
int image_load_tga (image_t *image, char *filename)
{
FILE *file ;
fread(&header, sizeof(header), 1, file);
+ /* byte swap: tga is little endian, host is ??? */
+ header.ColorMapOrigin = le16_to_cpu (header.ColorMapOrigin);
+ header.ColorMapLenght = le16_to_cpu (header.ColorMapLenght);
+ header.ImageXOrigin = le16_to_cpu (header.ImageXOrigin);
+ header.ImageYOrigin = le16_to_cpu (header.ImageYOrigin);
+ header.ImageWidth = le16_to_cpu (header.ImageWidth);
+ header.ImageHeight = le16_to_cpu (header.ImageHeight);
+
image->width = header.ImageWidth ;
image->height = header.ImageHeight ;