Initial import of Scalos. To decrease size I have
[AROS-Contrib.git] / scalos / libraries / scalosgfx / argb.c
blobaf8fbba94a6b49f703d97f6d771be05df705393f
1 // argb.c
2 // $Date$
3 // $Revision$
5 #include <exec/types.h>
6 #include <graphics/gels.h>
7 #include <graphics/rastport.h>
8 #include <graphics/scale.h>
9 #include <cybergraphx/cybergraphics.h>
10 #include <scalos/scalosgfx.h>
12 #define __USE_SYSBASE
14 #include <proto/dos.h>
15 #include <proto/exec.h>
16 #include <proto/graphics.h>
17 #include <proto/utility.h>
18 #include <proto/cybergraphics.h>
19 #include <proto/scalos.h>
20 #include <proto/layers.h>
22 #include <clib/alib_protos.h>
24 #include <defs.h>
26 #include <string.h>
27 #include <stdio.h>
28 #include <stdarg.h>
29 #include <limits.h>
31 #include "scalosgfx.h"
33 //-----------------------------------------------------------------------
35 //-----------------------------------------------------------------------
37 static ULONG FindBestPen(const ULONG *ColorTable, ULONG NumColors, ULONG Red, ULONG Green, LONG Blue);
38 static long GetColorDistance(const ULONG *ColorTableEntry, ULONG Red, ULONG Green, ULONG Blue);
40 //-----------------------------------------------------------------------
42 void ARGBSetAlpha(struct ARGB *argb, ULONG Width, ULONG Height, UBYTE Alpha)
44 ULONG y;
46 d1(KPrintF("%s/%ld: argb=%08lx Width=%lu Height=%lu Alpha=%lu\n", \
47 __FUNC__, __LINE__, argb, Width, Height, Alpha));
49 for (y = 0; y < Height; y++)
51 ULONG x;
53 for (x = 0; x < Width; x++)
55 argb->Alpha = Alpha;
56 argb++;
61 //-----------------------------------------------------------------------
63 void ARGBSetAlphaFromMask(struct ARGBHeader *argbh, PLANEPTR MaskPlane)
65 ULONG y;
66 ULONG MaskBytesPerRow = ((argbh->argb_Width + 15) & ~0x0f) / 8;
67 struct ARGB *pargb = argbh->argb_ImageData;
69 for (y = 0; y < argbh->argb_Height; y++)
71 ULONG x;
73 UWORD BitMask = 0x0080;
74 const UBYTE *MaskPtr2 = MaskPlane;
76 for (x = 0; x < argbh->argb_Width; x++, pargb++)
78 if (*MaskPtr2 & BitMask)
79 pargb->Alpha = 0xff;
80 else
81 pargb->Alpha = 0;
83 BitMask >>= 1;
84 if (0 == BitMask)
86 BitMask = 0x0080;
87 MaskPtr2++;
91 MaskPlane += MaskBytesPerRow;
95 //-----------------------------------------------------------------------
97 struct ARGB *CreateARGBFromBitMap(struct BitMap *bm,
98 ULONG Width, ULONG Height,
99 ULONG NumberOfColors, const ULONG *ColorTable, PLANEPTR MaskPlane,
100 struct ScalosGfxBase *ScalosGfxBase)
102 struct ARGB *argb;
103 UBYTE *LineArray = NULL;
104 struct BitMap *TempBM = NULL;
106 do {
107 struct RastPort rp;
108 ULONG Depth;
109 ULONG MaskBytesPerRow = ((Width + 15) & ~0x0f) / 8;
111 d1(KPrintF("%s/%ld: MaskPlane=%08lx MaskBytesPerRow=%lu\n", __FUNC__, __LINE__, MaskPlane, MaskBytesPerRow));
113 argb = AllocARGB(Width, Height, ScalosGfxBase);
114 if (NULL == argb)
115 break;
117 Depth = GetBitMapAttr(bm, BMA_DEPTH);
119 InitRastPort(&rp);
120 rp.BitMap = bm;
122 if (Depth <= 8 || (NULL == CyberGfxBase))
124 struct RastPort TempRp;
125 ULONG y;
126 struct ARGB *pargb = argb;
127 size_t ArraySize = (((Width + 15) >> 4) << 4);
129 LineArray = ScalosGfxAllocVecPooled(ScalosGfxBase, ArraySize);
130 if (NULL == LineArray)
131 break;
133 InitRastPort(&TempRp);
134 TempRp = rp;
135 TempRp.Layer = NULL;
136 TempRp.BitMap = TempBM = AllocBitMap(TEMPRP_WIDTH(Width), 1, 8, 0, NULL);
137 if (NULL == TempBM)
138 break;
140 for (y = 0; y < Height; y++)
142 ULONG x;
143 UBYTE *pLine = LineArray;
145 ReadPixelLine8(&rp,
146 0, y,
147 Width,
148 LineArray,
149 &TempRp);
151 if (MaskPlane)
153 UWORD BitMask = 0x0080;
154 const UBYTE *MaskPtr2 = MaskPlane;
156 for (x = 0; x < Width; x++, pargb++)
158 UBYTE col = *pLine++;
159 const ULONG *ColorReg = ColorTable + 3 * col;
161 pargb->Red = ColorReg[0] >> 24;
162 pargb->Green = ColorReg[1] >> 24;
163 pargb->Blue = ColorReg[2] >> 24;
165 if (*MaskPtr2 & BitMask)
166 pargb->Alpha = 0xff;
167 else
168 pargb->Alpha = 0;
170 BitMask >>= 1;
171 if (0 == BitMask)
173 BitMask = 0x0080;
174 MaskPtr2++;
178 MaskPlane += MaskBytesPerRow;
180 else
182 for (x = 0; x < Width; x++, pargb++)
184 UBYTE col = *pLine++;
185 const ULONG *ColorReg = ColorTable + 3 * col;
187 pargb->Alpha = 0xff;
188 pargb->Red = ColorReg[0] >> 24;
189 pargb->Green = ColorReg[1] >> 24;
190 pargb->Blue = ColorReg[2] >> 24;
195 else
197 ReadPixelArray(argb, 0, 0,
198 Width * sizeof(struct ARGB),
199 &rp, 0, 0,
200 Width, Height,
201 RECTFMT_ARGB);
202 if (MaskPlane)
204 struct ARGBHeader argbh;
206 argbh.argb_Width = Width;
207 argbh.argb_Height = Height;
208 argbh.argb_ImageData = argb;
210 d1(KPrintF("%s/%ld: MaskPlane=%08lx\n", __FUNC__, __LINE__, MaskPlane));
212 ARGBSetAlphaFromMask(&argbh, MaskPlane);
214 else
216 ARGBSetAlpha(argb, Width, Height, (UBYTE) ~0);
219 } while (0);
221 if (TempBM)
222 FreeBitMap(TempBM);
223 if (LineArray)
224 ScalosGfxFreeVecPooled(ScalosGfxBase, LineArray);
226 return argb;
229 //-----------------------------------------------------------------------
231 void WriteARGBToBitMap(struct ARGB *argb, struct BitMap *bm,
232 ULONG Width, ULONG Height,
233 ULONG NumberOfColors, const ULONG *ColorTable,
234 struct ScalosGfxBase *ScalosGfxBase)
236 ULONG Depth;
237 struct RastPort rp;
238 UBYTE *LineArray = NULL;
239 struct BitMap *TempBM = NULL;
241 do {
242 InitRastPort(&rp);
243 rp.BitMap = bm;
245 Depth = GetBitMapAttr(bm, BMA_DEPTH);
247 d1(KPrintF("%s/%ld: DestWidth=%lu DestHeight=%ld\n", __FUNC__, __LINE__, Width, Height));
249 if ((NULL == CyberGfxBase) || (Depth <= 8) || !GetCyberMapAttr(bm, CYBRMATTR_ISCYBERGFX))
251 struct RastPort TempRp;
252 ULONG y;
253 struct ARGB *pargb = argb;
254 size_t ArraySize = (((Width + 15) >> 4) << 4);
256 d1(KPrintF("%s/%ld: DestWidth=%lu DestHeight=%ld\n", __FUNC__, __LINE__, Width, Height));
258 LineArray = ScalosGfxAllocVecPooled(ScalosGfxBase, ArraySize);
259 if (NULL == LineArray)
260 break;
262 InitRastPort(&TempRp);
263 TempRp = rp;
264 TempRp.Layer = NULL;
265 TempRp.BitMap = TempBM = AllocBitMap(TEMPRP_WIDTH(Width), 1, 8, 0, NULL);
266 if (NULL == TempBM)
267 break;
269 for (y = 0; y < Height; y++)
271 ULONG x;
272 UBYTE *pLine = LineArray;
274 for (x = 0; x < Width; x++)
276 *pLine++ = FindBestPen(ColorTable, NumberOfColors,
277 pargb->Red << 24,
278 pargb->Green << 24,
279 pargb->Blue << 24);
280 pargb++;
283 WritePixelLine8(&rp,
284 0, y,
285 Width,
286 LineArray,
287 &TempRp);
290 else
292 WritePixelArray(argb, 0, 0,
293 Width * sizeof(struct ARGB),
294 &rp, 0, 0,
295 Width, Height,
296 RECTFMT_ARGB);
298 } while (0);
300 if (TempBM)
301 FreeBitMap(TempBM);
302 if (LineArray)
303 ScalosGfxFreeVecPooled(ScalosGfxBase, LineArray);
306 //-----------------------------------------------------------------------
308 void FreeARGB(struct ARGB **argb, struct ScalosGfxBase *ScalosGfxBase)
310 if (*argb)
312 WaitBlit();
313 d1(KPrintF("%s/%ld: argb=%08lx\n", __FUNC__, __LINE__, *argb));
314 ScalosGfxFreeVecPooled(ScalosGfxBase, *argb);
315 *argb = NULL;
319 //-----------------------------------------------------------------------
321 struct ARGB *AllocARGB(ULONG Width, ULONG Height, struct ScalosGfxBase *ScalosGfxBase)
323 struct ARGB *argb;
325 if (0 == Width || 0 == Height)
326 return NULL;
328 argb = ScalosGfxAllocVecPooled(ScalosGfxBase, Width * Height * sizeof(struct ARGB));
329 d1(KPrintF("%s/%ld: ARGB=%08lx Width=%lu Height=%ld\n", __FUNC__, __LINE__, argb, Width, Height));
331 return argb;
334 //-----------------------------------------------------------------------
336 void FillARGBFromBitMap(struct ARGBHeader *argbh, struct BitMap *srcBM,
337 PLANEPTR MaskPlane)
339 ULONG PixFmt;
340 ULONG BytesPerRow;
341 ULONG BytesPerPixel;
342 const UBYTE *src;
343 struct ARGB *dest;
344 APTR handle;
346 if ((NULL == CyberGfxBase) || !GetCyberMapAttr(srcBM, CYBRMATTR_ISCYBERGFX))
347 return;
349 d1(KPrintF("%s/%ld: Width=%ld Height=%ld\n", __FUNC__, __LINE__, argbh->argb_Width, argbh->argb_Height));
351 handle = LockBitMapTags(srcBM,
352 LBMI_PIXFMT, (ULONG) &PixFmt,
353 LBMI_BASEADDRESS, (ULONG) &src,
354 LBMI_BYTESPERROW, (ULONG) &BytesPerRow,
355 LBMI_BYTESPERPIX, (ULONG) &BytesPerPixel,
356 TAG_END);
358 d1(KPrintF(__FILE__ "/%s/%ld: handle=%08lx\n", __FUNC__, __LINE__, handle));
359 if (handle)
361 ULONG y;
363 d1(KPrintF("%s/%ld: src=%08lx\n", __FUNC__, __LINE__, src));
364 d1(KPrintF("%s/%ld: PixFmt=%ld BytesPerRow=%ld\n", __FUNC__, __LINE__, PixFmt, BytesPerRow));
366 dest = argbh->argb_ImageData;
368 switch (PixFmt)
370 case PIXFMT_BGR24:
371 for (y = 0; y < argbh->argb_Height; y++)
373 ULONG x;
374 const UBYTE *srcPtr = src;
376 for (x = 0; x < argbh->argb_Width; x++)
378 dest->Blue = srcPtr[0];
379 dest->Green = srcPtr[1];
380 dest->Red = srcPtr[2];
381 dest->Alpha = (UBYTE) ~0;
383 dest++;
384 srcPtr += BytesPerPixel;
387 src += BytesPerRow;
389 break;
390 case PIXFMT_BGRA32:
391 for (y = 0; y < argbh->argb_Height; y++)
393 ULONG x;
394 const UBYTE *srcPtr = src;
396 for (x = 0; x < argbh->argb_Width; x++)
398 dest->Blue = srcPtr[0];
399 dest->Green = srcPtr[1];
400 dest->Red = srcPtr[2];
401 dest->Alpha = srcPtr[3];
403 dest++;
404 srcPtr += BytesPerPixel;
407 src += BytesPerRow;
409 break;
411 case PIXFMT_RGB24:
412 for (y = 0; y < argbh->argb_Height; y++)
414 ULONG x;
415 const UBYTE *srcPtr = src;
417 for (x = 0; x < argbh->argb_Width; x++)
419 dest->Red = srcPtr[0];
420 dest->Green = srcPtr[1];
421 dest->Blue = srcPtr[2];
422 dest->Alpha = (UBYTE) ~0;
424 dest++;
425 srcPtr += BytesPerPixel;
428 src += BytesPerRow;
430 break;
431 case PIXFMT_RGBA32:
432 for (y = 0; y < argbh->argb_Height; y++)
434 ULONG x;
435 const UBYTE *srcPtr = src;
437 for (x = 0; x < argbh->argb_Width; x++)
439 dest->Red = srcPtr[0];
440 dest->Green = srcPtr[1];
441 dest->Blue = srcPtr[2];
442 dest->Alpha = srcPtr[3];
444 dest++;
445 srcPtr += BytesPerPixel;
448 src += BytesPerRow;
450 break;
452 case PIXFMT_ARGB32:
453 for (y = 0; y < argbh->argb_Height; y++)
455 ULONG x;
456 const UBYTE *srcPtr = src;
458 for (x = 0; x < argbh->argb_Width; x++)
460 dest->Red = srcPtr[1];
461 dest->Green = srcPtr[2];
462 dest->Blue = srcPtr[3];
463 dest->Alpha = srcPtr[0];
465 dest++;
466 srcPtr += BytesPerPixel;
469 src += BytesPerRow;
471 break;
473 case PIXFMT_RGB16:
474 for (y = 0; y < argbh->argb_Height; y++)
476 ULONG x;
477 const UWORD *srcPtr = (UWORD *) src;
479 for (x = 0; x < argbh->argb_Width; x++)
481 dest->Red = GET_RED_RGB16(srcPtr);
482 dest->Green = GET_GREEN_RGB16(srcPtr);
483 dest->Blue = GET_BLUE_RGB16(srcPtr);
484 dest->Alpha = (UBYTE) ~0;
486 srcPtr++;
487 dest++;
490 src += BytesPerRow;
492 break;
494 case PIXFMT_BGR16:
495 for (y = 0; y < argbh->argb_Height; y++)
497 ULONG x;
498 const UWORD *srcPtr = (UWORD *) src;
500 for (x = 0; x < argbh->argb_Width; x++)
502 dest->Red = GET_RED_BGR16(srcPtr);
503 dest->Green = GET_GREEN_BGR16(srcPtr);
504 dest->Blue = GET_BLUE_BGR16(srcPtr);
505 dest->Alpha = (UBYTE) ~0;
506 srcPtr++;
507 dest++;
510 src += BytesPerRow;
512 break;
514 case PIXFMT_RGB15:
515 for (y = 0; y < argbh->argb_Height; y++)
517 ULONG x;
518 const UWORD *srcPtr = (UWORD *) src;
520 for (x = 0; x < argbh->argb_Width; x++)
522 dest->Red = GET_RED_RGB15(srcPtr);
523 dest->Green = GET_GREEN_RGB15(srcPtr);
524 dest->Blue = GET_BLUE_RGB15(srcPtr);
525 dest->Alpha = (UBYTE) ~0;
526 srcPtr++;
527 dest++;
530 src += BytesPerRow;
532 break;
534 case PIXFMT_BGR15:
535 for (y = 0; y < argbh->argb_Height; y++)
537 ULONG x;
538 const UWORD *srcPtr = (UWORD *) src;
540 for (x = 0; x < argbh->argb_Width; x++)
542 dest->Red = GET_RED_BGR15(srcPtr);
543 dest->Green = GET_GREEN_BGR15(srcPtr);
544 dest->Blue = GET_BLUE_BGR15(srcPtr);
545 dest->Alpha = (UBYTE) ~0;
546 srcPtr++;
547 dest++;
550 src += BytesPerRow;
552 break;
554 case PIXFMT_RGB16PC:
555 for (y = 0; y < argbh->argb_Height; y++)
557 ULONG x;
558 const UWORD *srcPtr = (UWORD *) src;
560 for (x = 0; x < argbh->argb_Width; x++)
562 dest->Red = GET_RED_RGB16PC(srcPtr);
563 dest->Green = GET_GREEN_RGB16PC(srcPtr);
564 dest->Blue = GET_BLUE_RGB16PC(srcPtr);
565 dest->Alpha = (UBYTE) ~0;
566 srcPtr++;
567 dest++;
570 src += BytesPerRow;
572 break;
574 case PIXFMT_BGR16PC:
575 for (y = 0; y < argbh->argb_Height; y++)
577 ULONG x;
578 const UWORD *srcPtr = (UWORD *) src;
580 for (x = 0; x < argbh->argb_Width; x++)
582 dest->Red = GET_RED_BGR16PC(srcPtr);
583 dest->Green = GET_GREEN_BGR16PC(srcPtr);
584 dest->Blue = GET_BLUE_BGR16PC(srcPtr);
585 dest->Alpha = (UBYTE) ~0;
586 srcPtr++;
587 dest++;
590 src += BytesPerRow;
592 break;
594 case PIXFMT_RGB15PC:
595 for (y = 0; y < argbh->argb_Height; y++)
597 ULONG x;
598 const UWORD *srcPtr = (UWORD *) src;
600 for (x = 0; x < argbh->argb_Width; x++)
602 dest->Red = GET_RED_RGB15PC(srcPtr);
603 dest->Green = GET_GREEN_RGB15PC(srcPtr);
604 dest->Blue = GET_BLUE_RGB15PC(srcPtr);
605 dest->Alpha = (UBYTE) ~0;
606 srcPtr++;
607 dest++;
610 src += BytesPerRow;
612 break;
614 case PIXFMT_BGR15PC:
615 d1(KPrintF("%s/%ld: src=%08lx\n", __FUNC__, __LINE__, src));
617 dest = argbh->argb_ImageData;
619 for (y = 0; y < argbh->argb_Height; y++)
621 ULONG x;
622 const UWORD *srcPtr = (UWORD *) src;
624 for (x = 0; x < argbh->argb_Width; x++)
626 dest->Red = GET_RED_BGR15PC(srcPtr);
627 dest->Green = GET_GREEN_BGR15PC(srcPtr);
628 dest->Blue = GET_BLUE_BGR15PC(srcPtr);
629 dest->Alpha = (UBYTE) ~0;
630 srcPtr++;
631 dest++;
634 src += BytesPerRow;
636 break;
638 default:
639 break;
642 UnLockBitMap(handle);
643 if (MaskPlane)
644 ARGBSetAlphaFromMask(argbh, MaskPlane);
646 else
648 kprintf(__FILE__ "/%s/%ld: Can't lock bitmap\n", __FUNC__, __LINE__);
652 //-----------------------------------------------------------------------
654 static ULONG FindBestPen(const ULONG *ColorTable, ULONG NumColors, ULONG Red, ULONG Green, LONG Blue)
656 ULONG BestPen = 0;
657 long BestDistance = LONG_MAX;
658 ULONG n;
660 for (n = 0; n < NumColors; n++)
662 long ColorDistance = GetColorDistance(ColorTable, Red, Green, Blue);
664 d1(KPrintF("%s/%ld: R=%08lx G=%08lx b=%08lx Best=%ld Dist=%ld\n", \
665 __LINE__, ColorTable[0], ColorTable[1], ColorTable[2], BestDistance, ColorDistance));
667 if (ColorDistance < BestDistance)
669 BestDistance = ColorDistance;
670 BestPen = n;
673 ColorTable += 3;
676 d1(KPrintF("%s/%ld: R=%08lx G=%08lx B=%08lx NumColors=%lu BestPen=%lu\n", \
677 __LINE__, Red, Green, Blue, NumColors, BestPen));
679 return BestPen;
682 //-----------------------------------------------------------------------
684 static long GetColorDistance(const ULONG *ColorTableEntry, ULONG Red, ULONG Green, ULONG Blue)
686 LONG dRed,dGreen,dBlue;
688 dRed = (LONG) (Red >> 24) - (LONG) (ColorTableEntry[0] >> 24);
689 dGreen = (LONG) (Green >> 24) - (LONG) (ColorTableEntry[1] >> 24);
690 dBlue = (LONG) (Blue >> 24) - (LONG) (ColorTableEntry[2] >> 24);
692 return dRed * dRed + dGreen * dGreen +dBlue * dBlue;
695 //-----------------------------------------------------------------------
697 struct ScalosBitMapAndColor *AllocEmptySAC(struct ScalosGfxBase *ScalosGfxBase)
699 struct ScalosBitMapAndColor *sac;
701 sac = ScalosGfxAllocVecPooled(ScalosGfxBase, sizeof(struct ScalosBitMapAndColor));
702 if (sac)
703 memset(sac, 0, sizeof(struct ScalosBitMapAndColor));
705 d1(KPrintF(__FILE__ "/%s/%ld: END sac=%08lx\n", __FUNC__, __LINE__, sac));
707 return sac;
710 //-----------------------------------------------------------------------
712 struct ScalosBitMapAndColor *AllocSAC(ULONG Width, ULONG Height, ULONG Depth,
713 struct BitMap *FriendBM, struct TagItem *TagList,
714 struct ScalosGfxBase *ScalosGfxBase)
716 struct ScalosBitMapAndColor *sac = NULL;
717 BOOL Success = FALSE;
719 (void) TagList;
721 d1(KPrintF(__FILE__ "/%s/%ld: START Width=%lu Heioght=%lu Depth=%lu FriendBM=%08lx\n", \
722 __FUNC__, __LINE__, Width, Height, Depth, FriendBM));
724 do {
725 if (Depth < 1 || Depth > 8)
726 break;
727 if (Width < 1 || Height < 1)
728 break;
730 sac = AllocEmptySAC(ScalosGfxBase);
731 if (NULL == sac)
732 break;
734 sac->sac_Width = Width;
735 sac->sac_Height = Height;
736 sac->sac_Depth = Depth;
738 sac->sac_BitMap = AllocBitMap(Width, Height, 8, BMF_CLEAR, FriendBM);
739 d1(KPrintF(__FILE__ "/%s/%ld: sac_BitMap=%08lx\n", __FUNC__, __LINE__, sac->sac_BitMap));
740 if (NULL == sac->sac_BitMap)
741 break;
743 sac->sac_NumColors = 1 << Depth;
745 sac->sac_ColorTable = ScalosGfxAllocVecPooled(ScalosGfxBase, SAC_COLORTABLESIZE(sac));
746 d1(KPrintF(__FILE__ "/%s/%ld: sac_ColorTable=%08lx\n", __FUNC__, __LINE__, sac->sac_ColorTable));
747 if (NULL == sac->sac_ColorTable)
748 break;
750 Success = TRUE;
751 } while (0);
753 if (!Success)
755 FreeSAC(sac, ScalosGfxBase);
756 sac = NULL;
759 d1(KPrintF(__FILE__ "/%s/%ld: END sac=%08lx\n", __FUNC__, __LINE__, sac));
760 return sac;
763 //-----------------------------------------------------------------------
765 void FreeSAC(struct ScalosBitMapAndColor *sac, struct ScalosGfxBase *ScalosGfxBase)
767 d1(KPrintF(__FILE__ "/%s/%ld: START sac=%08lx\n", __FUNC__, __LINE__, sac));
768 if (sac)
770 d1(KPrintF(__FILE__ "/%s/%ld: sac_ColorTable=%08lx\n", __FUNC__, __LINE__, sac->sac_ColorTable));
771 if (sac->sac_ColorTable)
773 if (!(sac->sac_Flags & SACFLAGF_NO_FREE_COLORTABLE))
774 ScalosGfxFreeVecPooled(ScalosGfxBase, sac->sac_ColorTable);
775 sac->sac_ColorTable = NULL;
777 d1(KPrintF(__FILE__ "/%s/%ld: sac_Flags=%08lx sac_BitMap=%08lx\n", __FUNC__, __LINE__, sac->sac_Flags, sac->sac_BitMap));
778 if (sac->sac_BitMap)
780 if (!(sac->sac_Flags & SACFLAGF_NO_FREE_BITMAP))
781 FreeBitMap(sac->sac_BitMap);
782 sac->sac_BitMap = NULL;
784 ScalosGfxFreeVecPooled(ScalosGfxBase, sac);
786 d1(KPrintF(__FILE__ "/%s/%ld: END\n", __FUNC__, __LINE__));
789 //-----------------------------------------------------------------------
791 void BlitARGB(struct ARGBHeader *DestARGB, const struct ARGBHeader *SrcARGB,
792 LONG DestLeft, LONG DestTop, LONG SrcLeft, LONG SrcTop,
793 LONG Width, LONG Height)
795 struct ARGB *dest = DestARGB->argb_ImageData + DestTop * DestARGB->argb_Width;
796 const struct ARGB *src = SrcARGB->argb_ImageData + SrcTop * SrcARGB->argb_Width;
797 LONG y;
799 for (y = 0; y < Height; y++)
801 memcpy(dest + DestLeft, src + SrcLeft, Width * sizeof(struct ARGB));
802 dest += DestARGB->argb_Width;
803 src += SrcARGB->argb_Width;
807 //-----------------------------------------------------------------------
809 void FillARGB(struct ARGBHeader *DestARGB, const struct ARGB *fillARGB,
810 LONG left, LONG top, LONG width, LONG height)
812 struct ARGB *dest = DestARGB->argb_ImageData + top * DestARGB->argb_Width;
813 LONG y;
815 for (y = 0; y < height; y++)
817 LONG x;
818 struct ARGB *destRow = dest + left;
820 for (x = 0; x < width; x++)
821 *destRow++ = *fillARGB;
823 dest += DestARGB->argb_Width;
827 //-----------------------------------------------------------------------
829 void SetARGB(struct ARGBHeader *DestARGB, const struct ARGB *fillARGB)
831 struct ARGB *dest = DestARGB->argb_ImageData;
832 size_t Length = DestARGB->argb_Width * DestARGB->argb_Height;
834 while (Length--)
835 *dest++ = *fillARGB;
838 //-----------------------------------------------------------------------
840 BOOL SetNewSacColorMap(struct ScalosBitMapAndColor *sac, const ULONG *colorMap,
841 ULONG colorEntries, struct ScalosGfxBase *ScalosGfxBase)
843 BOOL Success = FALSE;
845 do {
846 if (NULL == sac)
847 break;
849 if (sac->sac_ColorTable)
851 if (!(sac->sac_Flags & SACFLAGF_NO_FREE_COLORTABLE))
852 ScalosGfxFreeVecPooled(ScalosGfxBase, sac->sac_ColorTable);
853 sac->sac_ColorTable = NULL;
856 sac->sac_NumColors = colorEntries;
857 sac->sac_Flags &= ~SACFLAGF_NO_FREE_COLORTABLE;
859 sac->sac_ColorTable = ScalosGfxAllocVecPooled(ScalosGfxBase, SAC_COLORTABLESIZE(sac));
860 if (NULL == sac->sac_ColorTable)
861 break;
863 memcpy(sac->sac_ColorTable, colorMap, SAC_COLORTABLESIZE(sac));
865 Success = TRUE;
866 } while (0);
868 return Success;
871 //-----------------------------------------------------------------------