/* $Id: readtga.c,v 1.2 1996/03/10 19:44:28 dwarf Exp dwarf $ */ /* * (C) COPYRIGHT Vincent S. Cojot and others 1996-1997 * All Rights Reserved * Licensed Materials - Property of Vincent S. Cojot and others. * Use, duplication or disclosure restricted by Vincent S. Cojot. */ #include #include #include #include "defines.h" /* Image de type IMAGE: Image.header.vide[12]; Image.header.Width; Image.header.Length; Image.header.BitsPerPixel; Image.img[x][y].r; Image.img[x][y].g; Image.img[x][y].b; */ int read_Miss_tga (MISS_IMAGE *, char *, int width, int length); int read_Expl_tga (EXPL_IMAGE *, char *, int width, int length); int read_Miss_tga (MISS_IMAGE *mon_image, char *filename, int width, int length) { int compteur, i; unsigned short Width; unsigned short Length; FILE *pointeur; if ((pointeur = fopen (filename, "rb"))==NULL) { printf ("Error, cannot open %s.\n", filename); return -1; } if (fread (&(*mon_image).header, sizeof (TARGA), 1, pointeur) != 1) { printf ("Error, cannot read from %s.\n", filename); return -2; } #ifdef SHIFT Width = (*mon_image).header.Width >> 8; Length = (*mon_image).header.Length >> 8; #else Width = (*mon_image).header.Width; Length = (*mon_image).header.Length; #endif for (compteur = 0; compteur < width; compteur++) { for (i = 0; i < length; i++) { (*mon_image).img[compteur][i].r = 128; (*mon_image).img[compteur][i].g = 128; (*mon_image).img[compteur][i].b = 255; } } for (compteur = 0; compteur < Width; compteur++) { for (i = ((length/2)-(Length/2)); i < ((length/2)+(Length/2)); i++) { if (fread (&(*mon_image).img[compteur][i], sizeof(PIXEL), 1, pointeur) != 1) { printf ("Error, cannot read from %s.\n", filename); return -1; } } } fclose (pointeur); return 0; } int read_Expl_tga (EXPL_IMAGE *mon_image, char *filename, int width, int length) { int compteur, i; unsigned short Width; unsigned short Length; FILE *pointeur; if ((pointeur = fopen (filename, "rb"))==NULL) { printf ("Error, cannot open %s.\n", filename); return -1; } if (fread (&(*mon_image).header, sizeof (TARGA), 1, pointeur) != 1) { printf ("Error, cannot read from %s.\n", filename); return -2; } #ifdef SHIFT Width = (*mon_image).header.Width >> 8; Length = (*mon_image).header.Length >> 8; #else Width = (*mon_image).header.Width; Length = (*mon_image).header.Length; #endif for (compteur = 0; compteur < width; compteur++) { for (i = 0; i < length; i++) { (*mon_image).img[compteur][i].r = 128; (*mon_image).img[compteur][i].g = 128; (*mon_image).img[compteur][i].b = 255; } } for (compteur = 0; compteur < Width; compteur++) { for (i = ((length/2)-(Length/2)); i < ((length/2)+(Length/2)); i++) { if (fread (&(*mon_image).img[compteur][i], sizeof(PIXEL), 1, pointeur) != 1) { printf ("Error, cannot read from %s.\n", filename); return -1; } } } fclose (pointeur); return 0; }