grub2: bring back build of aros-side grub2 tools
[AROS.git] / workbench / demos / 2View / read.c
bloba2106aba6f5f1fb1666aa9500e43105321303244
1 #include <stdio.h>
2 #include <stdlib.h>
4 #include <exec/memory.h>
5 #include <libraries/iffparse.h>
6 #include <intuition/intuition.h>
8 #include <proto/exec.h>
9 #include <proto/graphics.h>
10 #include <proto/iffparse.h>
12 extern struct Library * IFFParseBase;
13 extern struct GfxBase * GfxBase;
15 static UBYTE Buffer[1024], * ptr;
16 static int Fill;
18 #define MAX_PLANES 8
20 int GetByte (struct IFFHandle * iff)
22 if (!Fill)
24 Fill = ReadChunkBytes (iff, Buffer, sizeof (Buffer));
26 if (Fill < 0)
27 return Fill;
29 ptr = Buffer;
32 Fill --;
34 return *ptr ++;
37 int ReadRow (struct IFFHandle * iff,
38 BYTE * planes[],
39 ULONG Width, UWORD Depth, BOOL Compression, BOOL masking)
41 int x,i,n;
42 BYTE c;
44 Width = (Width + 7) / 8;
46 for (i=0; i<Depth; i++)
48 if (!Compression)
50 for (x=0; x<Width; x++)
51 planes[i][x] = GetByte (iff);
53 else
55 for (x=0; x<Width; )
57 c = GetByte (iff);
59 if (c > 0)
61 n = c+1;
63 while (n--)
64 planes[i][x++] = GetByte (iff);
66 else if (c != -128)
68 n = -c + 1;
69 c = GetByte (iff);
71 while (n--)
72 planes[i][x++] = c;
78 return TRUE;
81 int ReadILBM (struct IFFHandle * iff,
82 struct Window * window, ULONG Width, ULONG Height, UWORD Depth,
83 BOOL Compression, BOOL masking)
85 struct RastPort * rp = window->RPort;
86 BYTE * planes[MAX_PLANES];
87 int t,x,bit,byte,row,pen = 0,lastpen;
89 printf ("ReadILBM iff=%p win=%p Size=%ldx%ld Depth=%d %s%s\n",
90 iff, window, (long)Width, (long)Height, Depth,
91 Compression ? "C":"",
92 masking ? "M":""
95 planes[0] = AllocMem (Width*Depth + ((masking) ? Width : 0), MEMF_ANY);
97 if (!planes[0])
98 return FALSE;
100 for (t=1; t<Depth; t++)
101 planes[t] = planes[t-1] + Width;
103 if (masking)
104 planes[t] = planes[t-1] + Width;
106 for ( ; t<MAX_PLANES; t++)
107 planes[t] = NULL;
109 for (row=0; row<Height; row++)
111 if (!ReadRow (iff, planes, Width, Depth, Compression, masking))
113 FreeMem (planes[0], Width*Depth + ((masking) ? Width : 0));
114 return FALSE;
117 /* printf ("row %d, %08lx\n", row, *(ULONG*)planes[0]); */
119 lastpen = -1;
121 Move (rp, 0, row);
123 for (x=0; x<Width; x++)
125 bit = 0x80 >> (x & 7);
126 byte = x / 8;
128 for (pen=t=0; t<Depth; t++)
129 if (planes[t][byte] & bit)
130 pen |= 1L << t;
132 if (lastpen == -1)
133 lastpen = pen;
135 /* SetAPen (rp, pen);
136 WritePixel (rp, x, row); */
138 if (lastpen != pen)
140 SetAPen (rp, lastpen);
141 Draw (rp, x+1, row);
142 lastpen = pen;
146 SetAPen (rp, pen);
147 Draw (rp, Width, row);
150 return TRUE;