Category : Printer + Display Graphics
Archive   : GIFHDR.ZIP
Filename : GIFHDR.C

 
Output of file : GIFHDR.C contained in archive : GIFHDR.ZIP
#include
#include
#include



#define byte char
#define SIG_SIZ 6
#define GIF_SIG "GIF87a"



union clr_info {
unsigned m:1; /* m = 1, golbal color map follows descriptor */
unsigned cr:3; /* cr+1 = # bits of color resolution */
unsigned ub:1; /* unused bit, should be 0 */
unsigned pixel:3; /* pixel+1 = # bits/pixel in image */
byte clr_byte;
};



struct scr_des {
int width; /* Raster width in pixels */
int height; /* Raster height in pixels */
union clr_info color_info; /* Color information */
byte background; /* background=Color index of screen background
(color is defined from the global color map
or default map if none specified */
byte des_end; /* End of descriptor 0 0 0 0 0 0 0 */
};



struct map {
byte red;
byte green;
byte blue;
};



FILE *gif_file;



main()
{
struct scr_des screen_descriptor;
struct map *color_map;
int clr_map_entries;

if (read_sig ("TEST.GIF")) {
if (read_screen_descriptor (&screen_descriptor)) {
cprintf ("screen width: %d\r\n", screen_descriptor.width);
cprintf ("screen height: %d\r\n", screen_descriptor.height);
cprintf ("gobal color map?: %u\r\n", screen_descriptor.color_info.m);
cprintf ("bits of color res: %u\r\n", screen_descriptor.color_info.cr+1);
cprintf ("# bits/pixel in image: %u\r\n", screen_descriptor.color_info.pixel+1);
cprintf ("clr index of scr bg: %d\r\n", screen_descriptor.background);
if (screen_descriptor.color_info.m) {
cprintf ("Yes there is a color map.\r\n");
clr_map_entries = 2^(screen_descriptor.color_info.pixel+1);
color_map = (struct map *) malloc (clr_map_entries);
read_color_map (color_map, clr_map_entries);
}
}
}
getch();
}




int read_sig (char *file_name)
{
char signature [SIG_SIZ+1];

gif_file = fopen (file_name, "rb");
if (!gif_file) {
cprintf ("File not found.\r\n");
fclose (gif_file);
return (0);
}
else {
fread (signature, SIG_SIZ, 1, gif_file);
signature [SIG_SIZ] = '\0';
if (strcmp (signature, GIF_SIG)) {
cprintf ("This is not a valid GIF image file\r\n");
fclose (gif_file);
return (0);
}
else return (1);
}
}



int read_screen_descriptor (struct scr_des *descriptor)
{
int result;

result = fread (descriptor, sizeof (struct scr_des), 1, gif_file);
if (result == 1)
return (1);
else {
cprintf ("Error in reading screen descriptor.\r\n");
fclose (gif_file);
return (0);
}
}



int read_color_map (struct map *clr_map, int num)
{
int result;

result = fread (clr_map, sizeof (struct map), num, gif_file);
if (result == num)
return (1);
else {
cprintf ("Error in reading color map.\r\n");
fclose (gif_file);
return (0);
}
}


  3 Responses to “Category : Printer + Display Graphics
Archive   : GIFHDR.ZIP
Filename : GIFHDR.C

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/