New bitmap method SetRGBConversionFunction which can be used to
[tangerine.git] / rom / intuition / drawimagestate.c
blob75eee4975f0070a782c35de44cac2b069d7e53ef
1 /*
2 Copyright © 1995-2003, The AROS Development Team. All rights reserved.
3 Copyright © 2001-2003, The MorphOS Development Team. All Rights Reserved.
4 $Id$
5 */
7 #include <proto/graphics.h>
8 #include <proto/layers.h>
9 #include "intuition_intern.h"
10 #include <intuition/classusr.h>
11 #include <proto/alib.h>
13 #include <aros/macros.h>
15 #undef DEBUG
16 #define DEBUG 0
17 # include <aros/debug.h>
18 //#include <proto/arossupport.h>
20 #define USE_BLTBITMAPRASTPORT 1
21 #define USE_FASTPLANEPICK0 1
23 /*****************************************************************************
25 NAME */
26 #include <graphics/rastport.h>
27 #include <graphics/rpattr.h>
28 #include <intuition/intuition.h>
29 #include <intuition/imageclass.h>
30 #include <proto/intuition.h>
32 AROS_LH6(void, DrawImageState,
34 /* SYNOPSIS */
35 AROS_LHA(struct RastPort *, rp, A0),
36 AROS_LHA(struct Image *, image, A1),
37 AROS_LHA(LONG , leftOffset, D0),
38 AROS_LHA(LONG , topOffset, D1),
39 AROS_LHA(ULONG , state, D2),
40 AROS_LHA(struct DrawInfo *, drawInfo, A2),
42 /* LOCATION */
43 struct IntuitionBase *, IntuitionBase, 103, Intuition)
45 /* FUNCTION
46 This function renders an image in a certain state.
48 INPUTS
49 rp - Render in this RastPort
50 image - Render this image
51 leftOffset, topOffset - Add this offset to the position stored in the
52 image.
53 state - Which state (see intuition/imageclass.h for possible
54 valued).
55 drawInfo - The DrawInfo from the screen.
57 RESULT
58 None.
60 NOTES
61 DrawImageState(), handles both boopsi and conventional images.
63 EXAMPLE
65 BUGS
67 SEE ALSO
69 INTERNALS
71 HISTORY
72 29-10-95 digulla automatically created from
73 intuition_lib.fd and clib/intuition_protos.h
75 *****************************************************************************/
77 AROS_LIBFUNC_INIT
78 AROS_LIBBASE_EXT_DECL(struct IntuitionBase *,IntuitionBase)
80 ULONG apen, bpen, drmd, penmode;
82 EXTENDWORD(leftOffset);
83 EXTENDWORD(topOffset);
85 SANITY_CHECK(rp)
86 SANITY_CHECK(image)
88 if (rp->Layer) LockLayer(0,rp->Layer);
90 /* Store important variables of the RastPort */
91 #ifdef __MORPHOS__
92 GetRPAttrs(rp,RPTAG_PenMode,(ULONG)&penmode,RPTAG_APen,(ULONG)&apen,
93 RPTAG_BPen,(ULONG)&bpen,RPTAG_DrMd,(ULONG)&drmd,TAG_DONE);
94 #else
95 GetRPAttrs(rp,RPTAG_APen,(ULONG)&apen,
96 RPTAG_BPen,(ULONG)&bpen,RPTAG_DrMd,(ULONG)&drmd,TAG_DONE);
97 #endif
99 while(image)
101 if (image->Depth == CUSTOMIMAGEDEPTH)
103 struct impDraw method;
105 method.MethodID = IM_DRAW;
106 method.imp_RPort = rp;
107 method.imp_Offset.X = leftOffset;
108 method.imp_Offset.Y = topOffset;
109 method.imp_State = state;
110 method.imp_DrInfo = drawInfo;
111 DoMethodA ((Object *)image, (Msg)&method);
113 else
115 WORD x, y, d;
116 UWORD shift;
117 ULONG planeonoff, planepick;
119 #if !USE_BLTBITMAPRASTPORT
121 ULONG lastPen = 0;
122 ULONG pen = 0;
123 UWORD offset;
124 UWORD bitmask;
125 UWORD * bits[8];
126 WORD xoff, yoff, plane;
128 #define START_BITMASK 0x8000L
130 /* Change RastPort to the mode I need */
131 SetDrMd (rp, JAM1);
133 #endif
135 /* kprintf("*** Drawing Image %x. Next Image = %x\n widht = %d height = %d depth = %d planepick = %d planeonoff = %d\n",
136 image,image->NextImage,
137 image->Width,image->Height,image->Depth,image->PlanePick,image->PlaneOnOff);*/
140 planepick = image->PlanePick;
141 planeonoff = image->PlaneOnOff & ~planepick;
143 #if USE_FASTPLANEPICK0
145 if (planepick == 0)
147 SetAPen(rp, planeonoff);
148 RectFill(rp, leftOffset + image->LeftEdge,
149 topOffset + image->TopEdge,
150 leftOffset + image->LeftEdge + image->Width - 1,
151 topOffset + image->TopEdge + image->Height - 1);
153 image = image->NextImage;
154 continue;
157 #endif
159 /* Use x to store size of one image plane */
160 x = ((image->Width + 15) >> 4) * image->Height;
161 y = 0;
163 shift = 1;
165 #if USE_BLTBITMAPRASTPORT
167 struct BitMap bitmap;
168 int depth;
170 #if 0
171 /* The "8" (instead of image->Depth) seems to be correct,
172 as for example DOpus uses prop gadget knob images with
173 a depth of 0 (planepick 0, planeonoff color) */
175 depth = 8;
176 #else
177 /* That makes far more sense than just a 8
178 * R.Schmidt...still doesn`t resolve some weird icon problem i have
180 //depth = rp->BitMap->Depth;
183 ** Be system friendly. - Piru
185 depth = GetBitMapAttr(rp->BitMap, BMA_DEPTH);
186 if (depth > 8)
187 depth = 8;
188 #endif
189 InitBitMap(&bitmap, depth, image->Width, image->Height);
191 for(d = 0; d < depth; d++)
193 if (planepick & shift)
195 bitmap.Planes[d] = (PLANEPTR)(image->ImageData + (y++) * x);
197 else
199 bitmap.Planes[d] = (planeonoff & shift) ? (PLANEPTR)-1 : NULL;
201 shift <<= 1;
204 BltBitMapRastPort(&bitmap,
205 0, 0,
207 leftOffset + image->LeftEdge, topOffset + image->TopEdge,
208 image->Width, image->Height,
209 0xC0);
212 #else
215 for(d = 0; d < image->Depth;d++)
217 bits[d] = (planepick & shift) ? image->ImageData + (y++) * x : NULL;
218 shift <<= 1;
221 offset = 0;
223 yoff = image->TopEdge + topOffset;
225 for (y=0; y < image->Height; y++, yoff++)
228 bitmask = START_BITMASK;
230 xoff = image->LeftEdge + leftOffset;
232 for (x=0; x < image->Width; x++, xoff++)
234 pen = planeonoff;
235 shift = 1;
236 plane = 0;
238 for(d = 0; d < image->Depth; d++)
240 if (planepick & shift)
242 UWORD dat;
244 dat = bits[d][offset];
245 dat = AROS_WORD2BE(dat);
247 if (dat & bitmask)
249 pen |= shift;
253 shift <<= 1;
256 if (!x)
258 lastPen = pen;
259 Move (rp, xoff, yoff);
262 if (pen != lastPen)
264 SetAPen (rp, lastPen);
265 Draw (rp, xoff, yoff);
266 lastPen = pen;
269 bitmask >>= 1;
271 if (!bitmask)
273 bitmask = START_BITMASK;
274 offset ++;
277 } /* for (x=0; x < image->Width; x++, xoff++) */
279 SetAPen (rp, pen);
280 Draw (rp, xoff-1, yoff);
282 if (bitmask != START_BITMASK)
283 offset ++;
285 } /* for (y=0; y < image->Height; y++, yoff++) */
287 #endif
290 image = image->NextImage;
293 #ifdef __MORPHOS__
294 SetRPAttrs(rp,RPTAG_APen,apen,RPTAG_BPen,bpen,RPTAG_DrMd,drmd,RPTAG_PenMode,penmode,TAG_DONE);
295 #else
296 SetRPAttrs(rp,RPTAG_APen,apen,RPTAG_BPen,bpen,RPTAG_DrMd,drmd,TAG_DONE);
297 #endif
299 if (rp->Layer) UnlockLayer(rp->Layer);
301 AROS_LIBFUNC_EXIT
302 } /* DrawImageState */