Build Scalos and 3 of its libraries.
[AROS-Contrib.git] / scalos / libraries / scalosgfx / scalosgfx.c
blob891b9e380568a9f1f2b406654ce117496a138684
1 // scalosgfx.c
2 // $Date$
3 // $Revision$
6 #include <exec/types.h>
7 #include <exec/memory.h>
8 #include <exec/semaphores.h>
9 #include <exec/libraries.h>
10 #include <exec/execbase.h>
11 #include <exec/lists.h>
12 #include <exec/resident.h>
13 #include <dos/dos.h>
14 #include <dos/dostags.h>
15 #include <graphics/gfxbase.h>
16 #include <scalos/scalos.h>
17 #include <scalos/scalosgfx.h>
19 #include <clib/alib_protos.h>
21 #include <proto/dos.h>
22 #include <proto/exec.h>
23 #include <proto/intuition.h>
24 #include <proto/utility.h>
25 #include <proto/scalosgfx.h>
27 #include <string.h>
29 #include "scalosgfx_base.h"
30 #include "scalosgfx.h"
31 #include <defs.h>
32 #include <Year.h>
34 //----------------------------------------------------------------------------
36 #define IS_NOT_EVEN(len) ((len) & 1)
37 #define EVEN(len) (((len) + 1) & ~1)
38 #define MAGIC_PREFS_LIST_ENTRY_LIST ((UWORD) -1)
40 #define min(a,b) ((a) < (b) ? (a) : (b))
42 #ifdef __amigaos4__
43 #define ExtLib(base) ((struct ExtendedLibrary *)((ULONG)base + ((struct Library *)base)->lib_PosSize))
44 #define IScalosGfx ((struct ScaosGfxIFace *)ExtLib(ScalosGfxBase)->MainIFace)
45 #endif
47 //----------------------------------------------------------------------------
50 //----------------------------------------------------------------------------
52 // Standard library functions
54 //----------------------------------------------------------------------------
56 #if !defined(__AROS__)
57 struct ExecBase *SysBase;
58 #endif
59 struct IntuitionBase *IntuitionBase;
60 T_UTILITYBASE UtilityBase;
61 struct DosLibrary * DOSBase;
62 struct Library *CyberGfxBase;
63 struct GfxBase *GfxBase;
64 struct Library *LayersBase;
65 #ifdef __amigaos4__
66 struct Library *NewlibBase;
67 struct Interface *INewlib;
68 struct GraphicsIFace *IGraphics;
69 struct ExecIFace *IExec;
70 struct IntuitionIFace *IIntuition;
71 struct UtilityIFace *IUtility;
72 struct DOSIFace *IDOS;
73 struct CyberGfxIFace *ICyberGfx;
74 struct LayersIFace *ILayers;
75 #endif
77 //----------------------------------------------------------------------------
79 char ALIGNED libName[] = "scalosgfx.library";
80 char ALIGNED libIdString[] = "$VER: scalosgfx.library "
81 STR(LIB_VERSION) "." STR(LIB_REVISION)
82 " (29 Jul 2008 19:29:17) "
83 COMPILER_STRING
84 " ©2006" CURRENTYEAR " The Scalos Team";
86 //----------------------------------------------------------------------------
89 BOOL ScalosGfxInit(struct ScalosGfxBase *ScalosGfxBase)
91 d1(kprintf("%s/%ld: START ScalosGfxBase=%08lx procName=<%s>\n", __FUNC__, __LINE__, \
92 ScalosGfxBase, FindTask(NULL)->tc_Node.ln_Name));
94 NewList(&ScalosGfxBase->sgb_PrefsList);
96 InitSemaphore(&ScalosGfxBase->sgb_MemPoolSemaphore);
97 InitSemaphore(&ScalosGfxBase->sgb_PrefsListSem);
99 d1(kprintf("%s/%ld: END Success\n", __FUNC__, __LINE__));
101 return TRUE; // Success
104 //-----------------------------------------------------------------------------
106 BOOL ScalosGfxOpen(struct ScalosGfxBase *ScalosGfxBase)
108 BOOL Success = FALSE;
110 d1(kprintf("%s/%ld: START ScalosGfxBase=%08lx procName=<%s>\n", __FUNC__, __LINE__, \
111 ScalosGfxBase, FindTask(NULL)->tc_Node.ln_Name));
113 do {
114 IntuitionBase = (APTR) OpenLibrary( "intuition.library", 39 );
115 #ifdef __amigaos4__
116 if (IntuitionBase)
118 IIntuition = (APTR) GetInterface((struct Library *)IntuitionBase, "main", 1, NULL);
119 if (!IIntuition)
121 CloseLibrary((struct Library *)IntuitionBase);
122 IntuitionBase = NULL;
125 #endif
126 if (NULL == IntuitionBase)
127 break;
129 UtilityBase = (APTR) OpenLibrary( "utility.library", 39 );
130 #ifdef __amigaos4__
131 if (UtilityBase)
133 IUtility = (APTR) GetInterface((struct Library *)UtilityBase, "main", 1, NULL);
134 if (!IUtility)
136 CloseLibrary((struct Library *)UtilityBase);
137 UtilityBase = NULL;
140 #endif
141 if (NULL == UtilityBase)
142 break;
144 GfxBase = (struct GfxBase *) OpenLibrary(GRAPHICSNAME, 39);
145 #ifdef __amigaos4__
146 if (GfxBase != NULL)
148 IGraphics = (struct GraphicsIFace *)GetInterface((struct Library *)GfxBase, "main", 1, NULL);
149 if (IGraphics == NULL)
151 CloseLibrary((struct Library *)GfxBase);
152 GfxBase = NULL;
155 #endif
156 d1(kprintf("%s/%ld: GfxBase=%08lx\n", __FUNC__, __LINE__, GfxBase));
157 if (NULL == GfxBase)
158 return 0;
160 CyberGfxBase = (APTR) OpenLibrary( "cybergraphics.library", 40);
161 #ifdef __amigaos4__
162 if (CyberGfxBase)
164 ICyberGfx = (APTR) GetInterface((struct Library *)CyberGfxBase, "main", 1, NULL);
165 if (!ICyberGfx)
167 CloseLibrary(CyberGfxBase);
168 CyberGfxBase = NULL;
171 #endif
172 // CyberGfxBase may be NULL
174 DOSBase = (APTR) OpenLibrary( "dos.library", 39 );
175 #ifdef __amigaos4__
176 if (DOSBase)
178 IDOS = (APTR) GetInterface((struct Library *)DOSBase, "main", 1, NULL);
179 if (!IDOS)
181 CloseLibrary((struct Library *)DOSBase);
182 DOSBase = NULL;
185 #endif
186 if (NULL == DOSBase)
187 break;
189 LayersBase = OpenLibrary( "layers.library", 39 );
190 #ifdef __amigaos4__
191 if (LayersBase)
193 ILayers = (APTR) GetInterface(LayersBase, "main", 1, NULL);
194 if (!ILayers)
196 CloseLibrary(LayersBase);
197 LayersBase = NULL;
200 #endif
201 if (NULL == LayersBase)
202 break;
204 #ifdef __amigaos4__
205 NewlibBase = OpenLibrary("newlib.library", 0);
206 if (NULL == NewlibBase)
207 break;
208 INewlib = GetInterface(NewlibBase, "main", 1, NULL);
209 if (NULL == INewlib)
210 break;
211 #endif
213 ScalosGfxBase->sgb_MemPool = CreatePool(MEMF_PUBLIC | MEMF_CLEAR, 8192, 256);
214 if (NULL == ScalosGfxBase->sgb_MemPool)
215 break;
217 Success = TRUE;
218 } while (0);
220 d1(kprintf("%s/%ld: END Success=%ld\n", __FUNC__, __LINE__, Success));
222 return Success;
225 //-----------------------------------------------------------------------------
227 void ScalosGfxCleanup(struct ScalosGfxBase *ScalosGfxBase)
229 d1(kprintf("%s/%ld:\n", __FUNC__, __LINE__));
231 if (CyberGfxBase)
233 #ifdef __amigaos4__
234 DropInterface((struct Interface *)ICyberGfx);
235 #endif
236 CloseLibrary(CyberGfxBase);
237 CyberGfxBase = NULL;
239 if (NULL != GfxBase)
241 #ifdef __amigaos4__
242 DropInterface((struct Interface *)IGraphics);
243 #endif
244 CloseLibrary((struct Library *) GfxBase);
245 GfxBase = NULL;
247 if (UtilityBase)
249 #ifdef __amigaos4__
250 DropInterface((struct Interface *)IUtility);
251 #endif
252 CloseLibrary((struct Library *) UtilityBase);
253 UtilityBase = NULL;
255 if (IntuitionBase)
257 #ifdef __amigaos4__
258 DropInterface((struct Interface *)IIntuition);
259 #endif
260 CloseLibrary((struct Library *) IntuitionBase);
261 IntuitionBase = NULL;
263 if (DOSBase)
265 #ifdef __amigaos4__
266 DropInterface((struct Interface *)IDOS);
267 #endif
268 CloseLibrary((struct Library *) DOSBase);
269 DOSBase = NULL;
271 if (LayersBase)
273 #ifdef __amigaos4__
274 DropInterface((struct Interface *)ILayers);
275 #endif
276 CloseLibrary(LayersBase);
277 LayersBase = NULL;
279 #ifdef __amigaos4__
280 if (INewlib)
282 DropInterface(INewlib);
283 INewlib = NULL;
285 if (NewlibBase)
287 CloseLibrary(NewlibBase);
288 NewlibBase = NULL;
290 #endif
291 if (ScalosGfxBase->sgb_MemPool)
293 DeletePool(ScalosGfxBase->sgb_MemPool);
294 ScalosGfxBase->sgb_MemPool = NULL;
296 d1(kprintf("%s/%ld:\n", __FUNC__, __LINE__));
299 //-----------------------------------------------------------------------------
301 LIBFUNC_P1(struct ScalosBitMapAndColor *, LIBScalosGfxCreateEmptySAC,
302 A6, struct ScalosGfxBase *, ScalosGfxBase)
304 return AllocEmptySAC(ScalosGfxBase);
306 LIBFUNC_END
308 //-----------------------------------------------------------------------------
310 LIBFUNC_P6(struct ScalosBitMapAndColor *, LIBScalosGfxCreateSAC,
311 D0, ULONG, width,
312 D1, ULONG, height,
313 D2, ULONG, depth,
314 A0, struct BitMap *, friendBM,
315 A1, struct TagItem *, tagList,
316 A6, struct ScalosGfxBase *, ScalosGfxBase)
318 (void) tagList;
320 return AllocSAC(width, height, depth, friendBM, tagList, ScalosGfxBase);
322 LIBFUNC_END
324 //-----------------------------------------------------------------------------
326 LIBFUNC_P2(VOID, LIBScalosGfxFreeSAC,
327 A0, struct ScalosBitMapAndColor *, sac,
328 A6, struct ScalosGfxBase *, ScalosGfxBase)
330 FreeSAC(sac, ScalosGfxBase);
332 LIBFUNC_END
334 //-----------------------------------------------------------------------------
336 LIBFUNC_P4(struct gfxARGB *, LIBScalosGfxCreateARGB,
337 D0, ULONG, width,
338 D1, ULONG, height,
339 A0, struct TagItem *, tagList,
340 A6, struct ScalosGfxBase *, ScalosGfxBase)
342 (void) tagList;
344 return AllocARGB(width, height, ScalosGfxBase);
346 LIBFUNC_END
348 //-----------------------------------------------------------------------------
350 LIBFUNC_P2(VOID, LIBScalosGfxFreeARGB,
351 A0, struct gfxARGB **, argb,
352 A6, struct ScalosGfxBase *, ScalosGfxBase)
354 FreeARGB(argb, ScalosGfxBase);
356 LIBFUNC_END
358 //-----------------------------------------------------------------------------
360 LIBFUNC_P3(VOID, LIBScalosGfxARGBSetAlpha,
361 A0, struct ARGBHeader *, argbh,
362 D0, UBYTE, alpha,
363 A6, struct ScalosGfxBase *, ScalosGfxBase)
365 (void) ScalosGfxBase;
367 ARGBSetAlpha(argbh->argb_ImageData,
368 argbh->argb_Width, argbh->argb_Height, alpha);
370 LIBFUNC_END
372 //-----------------------------------------------------------------------------
374 LIBFUNC_P3(VOID, LIBScalosGfxARGBSetAlphaMask,
375 A0, struct ARGBHeader *, argbh,
376 A1, PLANEPTR, maskPlane,
377 A6, struct ScalosGfxBase *, ScalosGfxBase)
379 (void) ScalosGfxBase;
381 ARGBSetAlphaFromMask(argbh, maskPlane);
383 LIBFUNC_END
385 //-----------------------------------------------------------------------------
387 LIBFUNC_P7(struct gfxARGB *, LIBScalosGfxCreateARGBFromBitMap,
388 A0, struct BitMap *,bm,
389 D0, ULONG, width,
390 D1, ULONG, height,
391 D2, ULONG, numberOfColors,
392 A1, const ULONG *, colorTable,
393 A2, PLANEPTR, maskPlane,
394 A6, struct ScalosGfxBase *, ScalosGfxBase)
396 return CreateARGBFromBitMap(bm, width, height,
397 numberOfColors, colorTable, maskPlane, ScalosGfxBase);
399 LIBFUNC_END
401 //-----------------------------------------------------------------------------
403 LIBFUNC_P4(VOID, LIBScalosGfxFillARGBFromBitMap,
404 A0, struct ARGBHeader *, argbh,
405 A1, struct BitMap *, srcBM,
406 A2, PLANEPTR, maskPlane,
407 A6, struct ScalosGfxBase *, ScalosGfxBase)
409 (void) ScalosGfxBase;
411 FillARGBFromBitMap(argbh, srcBM, maskPlane);
413 LIBFUNC_END
415 //-----------------------------------------------------------------------------
417 LIBFUNC_P5(VOID, LIBScalosGfxWriteARGBToBitMap,
418 A0, struct ARGBHeader *, argbh,
419 A1, struct BitMap *, bm,
420 D0, ULONG, numberOfColors,
421 A2, const ULONG *, colorTable,
422 A6, struct ScalosGfxBase *, ScalosGfxBase)
424 (void) ScalosGfxBase;
426 WriteARGBToBitMap(argbh->argb_ImageData, bm,
427 argbh->argb_Width, argbh->argb_Height,
428 numberOfColors, colorTable, ScalosGfxBase);
430 LIBFUNC_END
432 //-----------------------------------------------------------------------------
434 LIBFUNC_P4(struct ScalosBitMapAndColor *, LIBScalosGfxMedianCut,
435 A0, struct ARGBHeader *, argbh,
436 D0, ULONG, depth,
437 A1, struct TagItem *, tagList,
438 A6, struct ScalosGfxBase *, ScalosGfxBase)
440 ULONG flags;
441 BOOL floyd;
442 struct BitMap *friendBM;
443 ULONG ReservedColors;
444 ULONG NewColors;
445 struct ScalosBitMapAndColor *sac = NULL;
447 d1(KPrintF(__FILE__ "/%s/%ld: START tagList=%08lx\n", __FUNC__, __LINE__, tagList));
449 flags = GetTagData(SCALOSGFX_MedianCutFlags, 0, tagList);
450 floyd = flags & SCALOSGFXFLAGF_MedianCut_FloydSteinberg;
451 ReservedColors = GetTagData(SCALOSGFX_MedianCutReservedColors, 0, tagList);
452 friendBM = (struct BitMap *) GetTagData(SCALOSGFX_MedianCutFriendBitMap, (ULONG)NULL, tagList);
454 d1(KPrintF(__FILE__ "/%s/%ld: flags=%08lx ReservedColors=%lu\n", __FUNC__, __LINE__, flags, ReservedColors));
456 NewColors = 1 << depth;
458 do {
459 NewColors += ReservedColors;
460 if (NewColors > 256)
461 break;
463 // adjst depth for reserved colors
464 while (NewColors > (1 << depth))
465 depth++;
467 d1(KPrintF("%s/%ld: NewColors=%lu depth=%lu ReservedColors=%lu\n", \
468 __FUNC__, __LINE__, NewColors, depth, ReservedColors));
470 sac = MedianCut(argbh, depth, NewColors, floyd, friendBM, ScalosGfxBase);
471 } while (0);
473 return sac;
475 LIBFUNC_END
477 //-----------------------------------------------------------------------------
479 LIBFUNC_P5(struct gfxARGB *, LIBScalosGfxScaleARGBArray,
480 A0, const struct ARGBHeader *, src,
481 A1, ULONG *, destWidth,
482 A2, ULONG *, destHeight,
483 A3, struct TagItem *, tagList,
484 A6, struct ScalosGfxBase *, ScalosGfxBase)
486 ULONG flags;
488 flags = GetTagData(SCALOSGFX_ScaleARGBArrayFlags, 0, tagList);
490 return ScaleARGBArray(src, destWidth, destHeight, flags, ScalosGfxBase);
492 LIBFUNC_END
494 //-----------------------------------------------------------------------------
496 LIBFUNC_P3(struct BitMap *, LIBScalosGfxScaleBitMap,
497 A0, struct ScaleBitMapArg *, sbma,
498 A1, struct TagItem *, tagList,
499 A6, struct ScalosGfxBase *, ScalosGfxBase)
501 (void) tagList;
503 return ScaleBitMap(sbma->sbma_SourceBM,
504 sbma->sbma_SourceWidth,
505 sbma->sbma_SourceHeight,
506 sbma->sbma_DestWidth,
507 sbma->sbma_DestHeight,
508 sbma->sbma_NumberOfColors,
509 sbma->sbma_ColorTable,
510 sbma->sbma_Flags,
511 sbma->sbma_ScreenBM,
512 ScalosGfxBase);
514 LIBFUNC_END
516 //-----------------------------------------------------------------------------
518 LIBFUNC_P5(VOID, LIBScalosGfxCalculateScaleAspect,
519 D0, ULONG, sourceWidth,
520 D1, ULONG, sourceHeight,
521 A0, ULONG *, destWidth,
522 A1, ULONG *, destHeight,
523 A6, struct ScalosGfxBase *, ScalosGfxBase)
525 (void) ScalosGfxBase;
527 CalculateScaleAspect(sourceWidth, sourceHeight, destWidth, destHeight);
529 LIBFUNC_END
531 //-----------------------------------------------------------------------------
533 LIBFUNC_P9(VOID, LIBScalosGfxBlitARGB,
534 A0, struct ARGBHeader *, DestARGB,
535 A1, const struct ARGBHeader *, SrcARGB,
536 D0, LONG, DestLeft,
537 D1, LONG, DestTop,
538 D2, LONG, SrcLeft,
539 D3, LONG, SrcTop,
540 D4, LONG, Width,
541 D5, LONG, Height,
542 A6, struct ScalosGfxBase *, ScalosGfxBase)
544 (void) ScalosGfxBase;
546 BlitARGB(DestARGB, SrcARGB, DestLeft, DestTop,
547 SrcLeft, SrcTop, Width, Height);
549 LIBFUNC_END
551 //-----------------------------------------------------------------------------
553 // Fill a rectangle with a given ARGB color.
555 LIBFUNC_P7(VOID, LIBScalosGfxFillRectARGB,
556 A0, struct ARGBHeader *, DestARGB,
557 A1, const struct gfxARGB *, fillARGB,
558 D0, LONG, left,
559 D1, LONG, top,
560 D2, LONG, width,
561 D3, LONG, height,
562 A6, struct ScalosGfxBase *, ScalosGfxBase)
564 (void) ScalosGfxBase;
566 FillARGB(DestARGB, fillARGB, left, top, width, height);
568 LIBFUNC_END
570 //-----------------------------------------------------------------------------
572 // Fill entire ARGB with given ARGB color
574 LIBFUNC_P3(VOID, LIBScalosGfxSetARGB,
575 A0, struct ARGBHeader *, DestARGB,
576 A1, const struct gfxARGB *, fillARGB,
577 A6, struct ScalosGfxBase *, ScalosGfxBase)
579 (void) ScalosGfxBase;
581 SetARGB(DestARGB, fillARGB);
583 LIBFUNC_END
585 //-----------------------------------------------------------------------------
587 // replace ColorMap in sac by given new one
589 LIBFUNC_P4(BOOL, LIBScalosGfxNewColorMap,
590 A0, struct ScalosBitMapAndColor *, sac,
591 A1, const ULONG *, colorMap,
592 D0, ULONG, colorEntries,
593 A6, struct ScalosGfxBase *, ScalosGfxBase)
595 (void) ScalosGfxBase;
597 return SetNewSacColorMap(sac, colorMap, colorEntries, ScalosGfxBase);
599 LIBFUNC_END
601 //-----------------------------------------------------------------------------
603 LIBFUNC_P8(VOID, LIBScalosGfxARGBRectMult,
604 A0, struct RastPort *, rp,
605 A1, const struct ARGB *, numerator,
606 A2, const struct ARGB *, denominator,
607 D0, WORD, xMin,
608 D1, WORD, yMin,
609 D2, WORD, xMax,
610 D3, WORD, yMax,
611 A6, struct ScalosGfxBase *, ScalosGfxBase)
613 ARGBRectMult(rp, *numerator, *denominator,
614 xMin, yMin,
615 xMax, yMax,
616 ScalosGfxBase);
618 LIBFUNC_END
620 //-----------------------------------------------------------------------------
622 LIBFUNC_P9(VOID, LIBScalosGfxBlitARGBAlpha,
623 A0, struct RastPort *, rp,
624 A1, const struct ARGBHeader *, srcH,
625 D0, ULONG, destLeft,
626 D1, ULONG, destTop,
627 D2, ULONG, srcLeft,
628 D3, ULONG, srcTop,
629 D4, ULONG, width,
630 D5, ULONG, height,
631 A6, struct ScalosGfxBase *, ScalosGfxBase)
633 BlitARGBAlpha(rp, srcH,
634 destLeft, destTop,
635 srcLeft, srcTop,
636 width, height,
637 ScalosGfxBase);
639 LIBFUNC_END
641 //-----------------------------------------------------------------------------
643 LIBFUNC_P7(VOID, LIBScalosGfxBlitARGBAlphaTagList,
644 A0, struct RastPort *, rp,
645 A1, const struct ARGBHeader *, srcH,
646 D0, ULONG, destLeft,
647 D1, ULONG, destTop,
648 A3, const struct IBox *, srcSize,
649 A2, struct TagItem *, tagList,
650 A6, struct ScalosGfxBase *, ScalosGfxBase)
652 const struct ARGB KDefault = { 255, 0, 0, 0 };
653 const struct ARGB *K;
654 ULONG Trans;
655 ULONG NoAlpha;
657 K = (const struct ARGB *) GetTagData(SCALOSGFX_BlitARGBHilight, (ULONG) NULL, tagList);
658 Trans = GetTagData(SCALOSGFX_BlitARGBTransparency, 255, tagList);
659 NoAlpha = GetTagData(SCALOSGFX_BlitARGBNoAlpha, FALSE, tagList);
661 if (NoAlpha)
663 if (NULL == K)
664 K = &KDefault;
666 d1(KPrintF("%s/%ld: Red=%ld Green=%ld Blue=%ld Trans=%lu\n", __FUNC__, __LINE__, K->Red, K->Green, K->Blue, Trans));
668 BlitARGBKT(rp, srcH,
669 destLeft, destTop,
670 srcSize->Left, srcSize->Top,
671 srcSize->Width, srcSize->Height,
672 K, Trans,
673 ScalosGfxBase);
675 else if (K || 255 != Trans)
677 d1(KPrintF("%s/%ld: Red=%ld Green=%ld Blue=%ld Trans=%lu\n", __FUNC__, __LINE__, K->Red, K->Green, K->Blue, Trans));
678 BlitARGBAlphaKT(rp, srcH,
679 destLeft, destTop,
680 srcSize->Left, srcSize->Top,
681 srcSize->Width, srcSize->Height,
682 K, Trans,
683 ScalosGfxBase);
685 else
687 BlitARGBAlpha(rp, srcH,
688 destLeft, destTop,
689 srcSize->Left, srcSize->Top,
690 srcSize->Width, srcSize->Height,
691 ScalosGfxBase);
694 LIBFUNC_END
696 //-----------------------------------------------------------------------------
698 LIBFUNC_P8(VOID, LIBScalosGfxBlitIcon,
699 A0, struct RastPort *, rpBackground,
700 A1, struct RastPort *, rpIcon,
701 D0, ULONG, left,
702 D1, ULONG, top,
703 D2, ULONG, width,
704 D3, ULONG, height,
705 A2, struct TagItem *, tagList,
706 A6, struct ScalosGfxBase *, ScalosGfxBase)
708 const struct ARGB *K;
709 const UBYTE *Alpha;
710 ULONG Trans;
712 K = (const struct ARGB *) GetTagData(SCALOSGFX_BlitIconHilight, (ULONG) NULL, tagList);
713 Alpha = (const UBYTE *) GetTagData(SCALOSGFX_BlitIconAlpha, (ULONG) NULL, tagList);
714 Trans = GetTagData(SCALOSGFX_BlitIconTransparency, 255, tagList);
716 if (Alpha)
718 if (K)
720 BlitTransparentAlphaK(rpBackground, rpIcon,
721 left, top, width, height,
722 K, Alpha, ScalosGfxBase);
724 else
726 BlitTransparentAlpha(rpBackground, rpIcon,
727 left, top, width, height,
728 Trans, Alpha, ScalosGfxBase);
731 else
733 if (K)
735 BlitTransparentK(rpBackground, rpIcon,
736 left, top, width, height,
737 K, ScalosGfxBase);
739 else
741 BlitTransparent(rpBackground, rpIcon,
742 left, top, width, height,
743 Trans, ScalosGfxBase);
747 LIBFUNC_END
749 //-----------------------------------------------------------------------------
751 LIBFUNC_P9(BOOL, LIBScalosGfxDrawGradient,
752 A0, struct ARGBHeader *, dest,
753 D0, LONG, left,
754 D1, LONG, top,
755 D2, LONG, width,
756 D3, LONG, height,
757 A1, struct gfxARGB *, start,
758 A2, struct gfxARGB *, stop,
759 D4, ULONG, gradType,
760 A6, struct ScalosGfxBase *, ScalosGfxBase)
762 return ScaDrawGradient(dest, left, top, width, height, start, stop, gradType, ScalosGfxBase);
764 LIBFUNC_END
766 //-----------------------------------------------------------------------------
768 LIBFUNC_P9(BOOL, LIBScalosGfxDrawGradientRastPort,
769 A0, struct RastPort *, rp,
770 D0, LONG, left,
771 D1, LONG, top,
772 D2, LONG, width,
773 D3, LONG, height,
774 A1, struct gfxARGB *, start,
775 A2, struct gfxARGB *, stop,
776 D4, ULONG, gradType,
777 A6, struct ScalosGfxBase *, ScalosGfxBase)
779 return DrawGradientRastPort(rp, left, top, width, height, start, stop, gradType, ScalosGfxBase);
781 LIBFUNC_END
783 //-----------------------------------------------------------------------------
785 LIBFUNC_P7(VOID, LIBScalosGfxDrawLine,
786 A0, struct ARGBHeader *, dest,
787 D0, LONG, fromX,
788 D1, LONG, fromY,
789 D2, LONG, toX,
790 D3, LONG, toY,
791 A1, const struct gfxARGB *, lineColor,
792 A6, struct ScalosGfxBase *, ScalosGfxBase)
794 (void) ScalosGfxBase;
796 DrawLine(dest, fromX, fromY, toX, toY, *lineColor);
798 LIBFUNC_END
800 //-----------------------------------------------------------------------------
802 LIBFUNC_P7(VOID, LIBScalosGfxDrawLineRastPort,
803 A0, struct RastPort *, rp,
804 D0, LONG, fromX,
805 D1, LONG, fromY,
806 D2, LONG, toX,
807 D3, LONG, toY,
808 A1, const struct gfxARGB *, lineColor,
809 A6, struct ScalosGfxBase *, ScalosGfxBase)
811 (void) ScalosGfxBase;
813 DrawLineRastPort(rp, fromX, fromY, toX, toY, *lineColor);
815 LIBFUNC_END
817 //-----------------------------------------------------------------------------
819 LIBFUNC_P9(VOID, LIBScalosGfxDrawEllipse,
820 A0, struct ARGBHeader *, dest,
821 D0, LONG, xCenter,
822 D1, LONG, yCenter,
823 D2, LONG, radiusX,
824 D3, LONG, radiusY,
825 D4, WORD, segment,
826 A1, const struct gfxARGB *, color1,
827 A2, const struct gfxARGB *, color2,
828 A6, struct ScalosGfxBase *, ScalosGfxBase)
830 (void) ScalosGfxBase;
832 DrawARGBEllipse(dest, xCenter, yCenter, radiusX, radiusY,
833 segment, *color1, *color2);
835 LIBFUNC_END
837 //-----------------------------------------------------------------------------
839 LIBFUNC_P9(VOID, LIBScalosGfxDrawEllipseRastPort,
840 A0, struct RastPort *, rp,
841 D0, LONG, xCenter,
842 D1, LONG, yCenter,
843 D2, LONG, radiusX,
844 D3, LONG, radiusY,
845 D4, WORD, segment,
846 A1, const struct gfxARGB *, color1,
847 A2, const struct gfxARGB *, color2,
848 A6, struct ScalosGfxBase *, ScalosGfxBase)
850 (void) ScalosGfxBase;
852 DrawARGBEllipseRastPort(rp, xCenter, yCenter, radiusX, radiusY,
853 segment, *color1, *color2);
855 LIBFUNC_END
857 //-----------------------------------------------------------------------------
859 APTR ScalosGfxAllocVecPooled(struct ScalosGfxBase *ScalosGfxBase, ULONG Size)
861 APTR ptr;
863 if (ScalosGfxBase->sgb_MemPool)
865 ObtainSemaphore(&ScalosGfxBase->sgb_MemPoolSemaphore);
866 ptr = AllocPooled(ScalosGfxBase->sgb_MemPool, Size + sizeof(size_t));
867 ReleaseSemaphore(&ScalosGfxBase->sgb_MemPoolSemaphore);
868 if (ptr)
870 size_t *sptr = (size_t *) ptr;
872 sptr[0] = Size;
874 d1(kprintf("%s/%ld: MemPool=%08lx Size=%lu mem=%08lx\n", __FUNC__, __LINE__, ScalosGfxBase->sgb_MemPool, Size, &sptr[1]));
875 return (APTR)(&sptr[1]);
879 d1(kprintf("%s/%ld: MemPool=%08lx Size=%lu\n", __FUNC__, __LINE__, ScalosGfxBase->sgb_MemPool, Size));
881 return NULL;
884 //-----------------------------------------------------------------------------
886 void ScalosGfxFreeVecPooled(struct ScalosGfxBase *ScalosGfxBase, APTR mem)
888 d1(kprintf("%s/%ld: MemPool=%08lx mem=%08lx\n", __FUNC__, __LINE__, ScalosGfxBase->sgb_MemPool, mem));
889 if (ScalosGfxBase->sgb_MemPool && mem)
891 size_t size;
892 size_t *sptr = (size_t *) mem;
894 mem = &sptr[-1];
895 size = sptr[-1];
897 ObtainSemaphore(&ScalosGfxBase->sgb_MemPoolSemaphore);
898 FreePooled(ScalosGfxBase->sgb_MemPool, mem, size + sizeof(size_t));
899 ReleaseSemaphore(&ScalosGfxBase->sgb_MemPoolSemaphore);
903 //-----------------------------------------------------------------------------
905 #if !defined(__SASC) && !defined(__amigaos4__)
906 void exit(int x)
908 (void) x;
909 while (1)
913 #endif /* !defined(__SASC) */
915 //-----------------------------------------------------------------------------
917 #if defined(__SASC)
918 void _XCEXIT(long x)
921 #endif /* defined(__SASC) */
923 //-----------------------------------------------------------------------------
925 #if defined(__AROS__)
927 #include "aros/symbolsets.h"
929 ADD2INITLIB(ScalosGfxInit, 0);
930 ADD2EXPUNGELIB(ScalosGfxCleanup, 0);
931 ADD2OPENLIB(ScalosGfxOpen, 0);
933 #endif
935 //-----------------------------------------------------------------------------