home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Club Amiga de Montreal - CAM
/
CAM_CD_1.iso
/
files
/
460.lha
/
Qrt_to_IFF24
/
qrt2iff24.c
< prev
next >
Wrap
C/C++ Source or Header
|
1991-01-05
|
5KB
|
199 lines
/* Qrt2IFF24.c
Format: qrt2iff24 <infile> <outfile>
Converts QRT 24bit image files (put out by DKBTrace and QRT) into
C= Amiga IFF 24 ILBM file without byterun compression.
Works with any resolution QRT/DKB file.
I didn't check for file write errors so if you run out of
storage space it'll keep on going till the end...
Written on Lattice C V5.05.
-Viet Ho (Viet.Ho@samba.acs.unc.edu)
15-AUG-90 02:48
*/
#include <stdio.h>
#define EOL 0x0a
main(int argc, char *argv[])
{
typedef unsigned long int ULONG;
typedef unsigned short int UWORD;
typedef short int WORD;
typedef unsigned char UBYTE;
FILE *fr, *fw;
ULONG isize,fsize;
int l,i,j,k,z,rgb[3][1024];
UWORD w,h;
UBYTE d,*b,*c,*BMHDloc;
UBYTE filesize[3]; /* imgsize + IFF header size */
UBYTE imgsize[3]; /* w*h*3 for 24 bit images */
char bmhdname[] = { "ILBMBMHD",0,0,0x14 };
struct {
UWORD w,h; /* ViewPort size */
WORD x,y; /* Image offset */
UBYTE nPlanes;
UBYTE Mask;
UBYTE rle;
UBYTE pad;
UWORD TransColor;
UBYTE xAspect, yAspect;
UWORD pageWidth, pageHeight;
} BMHD;
if (argc < 3) {
printf("Not enough filenames given.\n");
printf("Format: %s <file read> <file write>\n",argv[0]);
return(1);
}
/* Set pointer fr for file read */
if (!(fr = fopen(argv[1],"r"))) {
printf("Error reading file %s.\n",argv[1]);
printf("Format: %s <file read> <file write>\n",argv[0]);
return(1);
}
/* Set pointer fw for file write */
if (!(fw = fopen(argv[2],"w"))) {
printf("Error opening file %s.\n",argv[2]);
printf("Format: %s <file read> <file write>\n",argv[0]);
return(1);
}
/* Take in the image resolution */
fread(&isize,4,1,fr); /* w-lohi h-lohi */
*b = *c = w = h = 0;
b = &isize;
c = &w;
*c = *(b+1) ; *(c+1) = *b;
c = &h;
*c = *(b+3); *(c+1) = *(b+2);
printf("\nWidth: %d Height: %d\n\n",w,h);
/* Image resolution imbedded in qrt file: */
/* w h */
/* lohi|lohi */
/* loc: 0 1 2 3 */
/* */
/* Create IFF ILBM header */
BMHD.w = w;
BMHD.h = h;
BMHD.nPlanes = 24;
BMHD.pageWidth = w;
BMHD.pageHeight = h;
BMHD.x = BMHD.y = BMHD.Mask = BMHD.rle = BMHD.pad = BMHD.TransColor = 0;
isize = w*h*3; /* Generate image size from resolution + 24bits */
fsize = isize + sizeof(BMHD) + 14;
b = &isize; /* We need to break C's 32 bit LONG type down */
c = &fsize; /* to three bytes (24 bit) IFF limitation. */
for (i=1;i<4;i++) { /* Break img/file length into 3 bytes */
imgsize[i] = *++b;
filesize[i] = *++c;
}
/* Dump out the header....don't laugh...it works */
fprintf(fw,"FORM%c%c%c%c",0,filesize[1],filesize[2],filesize[3]);
fwrite(bmhdname,1,sizeof(bmhdname),fw);
BMHDloc = &BMHD;
for (i=1;i<(sizeof(BMHD)+1);i++) putc(*BMHDloc++,fw);
fprintf(fw,"BODY%c%c%c%c",0,imgsize[1],imgsize[2],imgsize[3]);
/***Diagram******************
* R G B *
* rgb[i][j] i= 0 1 2 *
* ^ UBYTE *
* | *
* j= pixel index *
****************************/
/* IFF24 bit ordering for one scanline
Pixel 0 1 2 3 4 5 . . . . . --> WIDTH
Scanline 0 R0 R0 R0 R0 R0 R0 . . . . .
R1 R1 R1 R1 R1 R1 . . . . .
R2 R2 R2 R2 R2 R2 . . . . .
R3 R3 R3 R3 R3 R3 . . . . .
R4 R4 R4 R4 R4 R4 . . . . .
R5 R5 R5 R5 R5 R5 . . . . .
R6 R6 R6 R6 R6 R6 . . . . .
R7 R7 R7 R7 R7 R7 . . . . .
G0 G0 G0 G0 G0 G0 . . . . .
G1 G1 G1 G1 G1 G1 . . . . .
G2 G2 G2 G2 G2 G2 . . . . .
G3 G3 G3 G3 G3 G3 . . . . .
G4 G4 G4 G4 G4 G4 . . . . .
G5 G5 G5 G5 G5 G5 . . . . .
G6 G6 G6 G6 G6 G6 . . . . .
G7 G7 G7 G7 G7 G7 . . . . .
B0 B0 B0 B0 B0 B0 . . . . .
B1 B1 B1 B1 B1 B1 . . . . .
B2 B2 B2 B2 B2 B2 . . . . .
B3 B3 B3 B3 B3 B3 . . . . .
B4 B4 B4 B4 B4 B4 . . . . .
B5 B5 B5 B5 B5 B5 . . . . .
B6 B6 B6 B6 B6 B6 . . . . .
B7 B7 B7 B7 B7 B7 . . . . .
*/
l = 0;
while (l++ < h) {
/* Read in a scanline (w) of RGB's (pixels) */
getc(fr);getc(fr); /*Weed out scanline ### */
for (i=0;i<3;i++) for (j=0;j<w;j++) rgb[i][j] = getc(fr);
/* Transformation....this should be done in assembly..but..nahhh */
for (i=0;i<3;i++) {
for (z=0;z<8;z++) {
for (j=0;j<w;j += 8) {
d = 0;
for (k=0;k<8;k++) {
d <<= 1;
if (rgb[i][j+k] & 1) d |= 1; /* Last bit to be shifted, word shift first */
rgb[i][j+k] >>= 1;
}
putc(d,fw); /* Writes one byte back out */
}
}
}
printf(" Scanline: %d\r",l);
}
printf("\nDone.\n");
fclose(fr);
fclose(fw);
}