3 * By John Hodge (thePowersGang)
12 int main(int argc, char *argv[]);
13 void *SIF_Load(tURIFile *FP, int *Width, int *Height, uint32_t Magic);
20 void *(*Load)(tURIFile *FP, int *Width, int *Height, uint32_t Magic);
22 {"SIF", 0xFFFF, 0x51F0, SIF_Load}
24 #define NUM_FILE_TYPES (sizeof(caFileTypes)/sizeof(caFileTypes[0]))
27 int main(int argc, char *argv[])
39 // --- Parse Arguments
41 fprintf(stderr, "Usage: %s <image>\n", argv[0]);
47 uri = URI_Parse(imageURI);
48 printf("uri = {Proto:'%s',Host:'%s',Port:%i('%s'),Path:'%s'}\n",
49 uri->Proto, uri->Host, uri->PortNum, uri->PortStr, uri->Path);
50 fp = URI_Open(URI_MODE_READ, uri);
51 printf("fp = %p\n", fp);
53 fprintf(stderr, "ERROR: Unable to open '%s'\nFile unable to open\n", imageURI);
59 // --- Determine file type
60 i = URI_Read(fp, 4, &idDWord);
61 printf("i = %i\n", i);
62 printf("idDWord = 0x%08lx\n", idDWord);
63 for( i = 0; i < NUM_FILE_TYPES; i++ )
65 if( (idDWord & caFileTypes[i].Mask) == caFileTypes[i].Ident )
68 if( i == NUM_FILE_TYPES ) {
69 fprintf(stderr, "ERROR: Unable to open '%s'\nUnknown file type\n", imageURI);
74 buffer = caFileTypes[i].Load(fp, &w, &h, idDWord);
76 fprintf(stderr, "ERROR: Unable to open '%s'\nParsing failed\n", imageURI);
80 printf("w=%i,h=%i\n", w, h);
83 termW = ioctl(1, 5, NULL); termW *= 8; ioctl(1, 5, &termW);
84 termH = ioctl(1, 6, NULL); termH *= 16; ioctl(1, 6, &termH);
85 //printf("termW = %i, termH = %i\n", termW, termH);
86 tmp = 1; ioctl(1, 4, &tmp);
89 for( i = 0; i < (h < termH ? h : termH); i++ )
91 write(1, (w < termW ? w : termW) * 4, buffer + i*w);
93 seek(1, (termW-w)*4, SEEK_CUR);
101 // === Simple Image Format Loader ===
102 void *SIF_Load(tURIFile *FP, int *Width, int *Height, uint32_t Magic)
104 uint16_t flags = Magic >> 16;
106 int comp = flags & 3;
110 // First 4 bytes were read by main()
114 ret = malloc(w * h * 4);
118 // Uncompressed 32-bpp data
120 URI_Read( FP, w * h * 4, ret );
126 // (1 Flag, 7-bit size, 32-bit value)
133 URI_Read(FP, 1, &len);
136 URI_Read(FP, len, ret+ofs);
140 URI_Read(FP, 4, &val);
141 while(len--) ret[ofs++] = val;
152 URI_Read(FP, 1, &len);
156 URI_Read(FP, 1, &val);
157 ret[ofs++] = (uint32_t)val << 24;
161 URI_Read(FP, 1, &val);
163 ret[ofs++] = (uint32_t)val << 24;
167 for( i = 0; i < 4; i++ )
173 URI_Read(FP, 1, &len);
177 URI_Read(FP, 1, &val);
178 ret[ofs++] |= (uint32_t)val << (24-i*8);
182 URI_Read(FP, 1, &val);
184 ret[ofs++] |= (uint32_t)val << (24-i*8);
191 fprintf(stderr, "Warning: Unknown compression scheme %i for SIF\n", comp);