minor update
[AROS-Contrib.git] / scalos / main / dtimage.c
blob3a98819c38ab142490fcc1b958aa9684b1b305d1
1 // dtimage.c
2 // $Date$
3 // $Revision$
6 #include <exec/types.h>
7 #include <exec/memory.h>
8 #include <dos/dostags.h>
9 #ifdef __amigaos4__
10 #include <dos/anchorpath.h>
11 #endif
12 #include <graphics/gfx.h>
13 #if defined(__amigaos4__)
14 #include <graphics/blitattr.h>
15 #endif //defined(__amigaos4__)
16 #include <intuition/intuition.h>
17 #include <utility/tagitem.h>
18 #include <datatypes/pictureclass.h>
19 #include <string.h>
20 #include <stdio.h>
21 #include <limits.h>
23 #define __USE_SYSBASE
25 #include <proto/dos.h>
26 #include <proto/exec.h>
27 #include <proto/graphics.h>
28 #include <proto/intuition.h>
29 #include <proto/datatypes.h>
30 #include <proto/layers.h>
31 #include <proto/utility.h>
32 #include <proto/timer.h>
33 #include "debug.h"
34 #include <proto/scalos.h>
36 #include <clib/alib_protos.h>
38 #include <defs.h>
39 #include <Year.h> // +jmc+
41 #include <scalos/scalos.h>
43 #include "scalos_structures.h"
44 #include "functions.h"
45 #include "Variables.h"
47 #define PDTA_AlphaChannel (DTA_Dummy + 256) /* Alphachannel input */
49 //----------------------------------------------------------------------------
51 // local functions
53 static void FreeDatatypesImage(struct DatatypesImage *dti);
54 static struct DatatypesImage *NewDatatypesImage(CONST_STRPTR ImageName, ULONG Flags);
55 static struct DatatypesImage *FindDatatypesImage(CONST_STRPTR ImageName, ULONG Flags);
56 static LONG CreateTempFile(CONST_STRPTR TempFileName, CONST_STRPTR DtFileName);
57 static void DtImageNotify(struct internalScaWindowTask *iwt, struct NotifyMessage *msg);
58 static void CleanupTempFiles(void);
59 #if defined(__amigaos4__)
60 static BOOL DtImageCreateAlpha(struct DatatypesImage *dti);
61 #endif //defined(__amigaos4__)
63 //----------------------------------------------------------------------------
65 // local data items :
67 static struct List DataTypesImageList;
68 static BOOL Initialized = FALSE;
70 //----------------------------------------------------------------------------
72 BOOL InitDataTypesImage(void)
74 NewList(&DataTypesImageList);
76 CleanupTempFiles();
78 Initialized = TRUE;
80 return TRUE;
84 void CleanupDataTypesImage(void)
86 if (Initialized)
88 struct DatatypesImage *dti;
90 while ((dti = (struct DatatypesImage *) RemHead(&DataTypesImageList)))
92 d1(kprintf("%s/%s/%ld: Freeing dti(%lx)\n", __FILE__, __FUNC__, __LINE__, dti));
93 FreeDatatypesImage(dti);
99 void DisposeDatatypesImage(struct DatatypesImage **dti)
101 if (*dti)
103 if (0 == --(*dti)->dti_UseCount)
105 #if 0
106 Remove(&(*dti)->dti_Node);
107 FreeDatatypesImage(*dti);
108 #endif
109 *dti = NULL;
115 struct DatatypesImage *CreateDatatypesImage(CONST_STRPTR ImageName, ULONG Flags)
117 struct DatatypesImage *dti;
119 dti = FindDatatypesImage(ImageName, Flags);
120 if (dti)
121 dti->dti_UseCount++;
122 else
123 dti = NewDatatypesImage(ImageName, Flags);
125 d1(kprintf("%s/%s/%ld: Create image %s dti(%lx)\n", __FILE__, __FUNC__, __LINE__,
126 ImageName, dti));
128 return dti;
132 void FillBackground(struct RastPort *rp, struct DatatypesImage *dtImage,
133 WORD MinX, WORD MinY, WORD MaxX, WORD MaxY,
134 ULONG XStart, ULONG YStart)
136 if (dtImage && dtImage->dti_BitMap)
138 LONG x, y;
139 LONG h;
140 LONG SrcX, SrcY;
141 LONG bmHeight = dtImage->dti_BitMapHeader->bmh_Height;
142 LONG bmWidth = dtImage->dti_BitMapHeader->bmh_Width;
144 d1(KPrintF("%s/%s/%ld: MinX=%ld MinY=%ld MaxX=%ld MaxY=%ld XStart=%ld YStart=%ld\n", \
145 __FILE__, __FUNC__, __LINE__, MinX, MinY, MaxX, MaxY, XStart, YStart));
147 d1(KPrintF("%s/%s/%ld: Image w=%ld h=%ld\n", \
148 __FILE__, __FUNC__, __LINE__, bmWidth, bmHeight));
150 XStart %= bmWidth;
151 YStart %= bmHeight;
153 if (YStart < 0)
154 SrcY = bmHeight - (-YStart % bmHeight);
155 else
156 SrcY = YStart;
158 SrcY %= bmHeight;
159 h = bmHeight - SrcY;
161 for (y = MinY; y <= MaxY; )
163 LONG w;
165 if (XStart < 0)
166 SrcX = bmWidth - (-XStart % bmWidth);
167 else
168 SrcX = XStart;
170 SrcX %= bmWidth;
172 w = bmWidth - SrcX;
174 if ((y + h) > MaxY)
175 h = 1 + MaxY - y;
177 d1(kprintf("%s/%s/%ld: SrcX=%ld y=%ld h=%ld\n", __FILE__, __FUNC__, __LINE__, SrcX, y, h));
179 for (x = MinX; x <= MaxX; )
181 if (x + w > MaxX)
182 w = 1 + MaxX - x;
184 d1(KPrintF("%s/%s/%ld: x=%ld y=%ld w=%ld h=%ld\n", __FILE__, __FUNC__, __LINE__, x, y, w, h));
186 BltBitMapRastPort(dtImage->dti_BitMap,
187 SrcX, SrcY,
189 x, y,
190 w, h,
191 0xC0);
193 x += w;
194 w = bmWidth;
195 SrcX = 0;
198 y += h;
199 h = bmHeight;
200 SrcY = 0;
203 else
205 SetAPen(rp, iInfos.xii_iinfos.ii_DrawInfo->dri_Pens[BACKGROUNDPEN]);
206 SetDrMd(rp, JAM1);
208 RectFill(rp, MinX, MinY, MaxX, MaxY);
213 static void FreeDatatypesImage(struct DatatypesImage *dti)
215 if (dti->dti_ImageObj)
217 Object *ImageObject = dti->dti_ImageObj;
218 struct ExtGadget *gg = (struct ExtGadget *) ImageObject;
219 struct DTSpecialInfo *si = (struct DTSpecialInfo *) gg->SpecialInfo;
221 dti->dti_ImageObj = NULL;
222 dti->dti_BitMap = NULL;
224 if (dti->dti_NotifyNode)
226 RemFromMainNotifyList(dti->dti_NotifyNode);
227 dti->dti_NotifyNode = NULL;
230 d1(KPrintF("%s/%s/%ld: \n", __FILE__, __FUNC__, __LINE__));
232 // wait for pending PROCLAYOUT to complete
233 while (si && si->si_Flags & DTSIF_LAYOUTPROC)
234 Delay(10);
236 DisposeDTObject(ImageObject);
238 // now temporary image file can be deleted
239 DeleteFile(dti->dti_TempFilename);
241 d1(KPrintF("%s/%s/%ld: \n", __FILE__, __FUNC__, __LINE__));
243 if (dti->dti_ARGB)
245 ScalosFree(dti->dti_ARGB);
246 dti->dti_ARGB = NULL;
248 if (dti->dti_Filename)
250 d1(KPrintF("%s/%s/%ld: FileName=%08lx <%s>\n", __FILE__, __FUNC__, __LINE__, dti->dti_Filename, dti->dti_Filename));
251 FreeCopyString(dti->dti_Filename);
252 dti->dti_Filename = NULL;
254 if (dti->dti_TempFilename)
256 FreePathBuffer(dti->dti_TempFilename);
257 dti->dti_TempFilename = NULL;
261 ScalosFree(dti);
265 static struct DatatypesImage *NewDatatypesImage(CONST_STRPTR ImageName, ULONG Flags)
267 struct DatatypesImage *dti;
268 BOOL Success = FALSE;
270 do {
271 ULONG Result;
272 ULONG UseFriendBM;
273 ULONG DoRemap;
275 d1(KPrintF("%s/%s/%ld: START ImageName=<%s>\n", __FILE__, __FUNC__, __LINE__, ImageName));
277 dti = ScalosAlloc(sizeof(struct DatatypesImage));
278 if (NULL == dti)
280 d1(KPrintF("%s/%s/%ld: dti=%08lx\n", __FILE__, __FUNC__, __LINE__, dti));
281 break;
284 d1(KPrintF("%s/%s/%ld: dti=%08lx\n", __FILE__, __FUNC__, __LINE__, dti));
286 memset(dti, 0, sizeof(struct DatatypesImage));
288 dti->dti_Filename = AllocCopyString(ImageName);
289 if (NULL == dti->dti_Filename)
291 d1(KPrintF("%s/%s/%ld: dti_Filename=%08lx\n", __FILE__, __FUNC__, __LINE__, dti->dti_Filename));
292 break;
295 dti->dti_TempFilename = AllocPathBuffer();
296 if (NULL == dti->dti_TempFilename)
298 d1(KPrintF("%s/%s/%ld: dti_TempFilename=%08lx\n", __FILE__, __FUNC__, __LINE__, dti->dti_TempFilename));
299 break;
302 d1(KPrintF("%s/%s/%ld: \n", __FILE__, __FUNC__, __LINE__));
304 // Create pseudo-random name for temp. file
305 if (!TempName(dti->dti_TempFilename, Max_PathLen))
307 d1(KPrintF("%s/%s/%ld: TempName() failed\n", __FILE__, __FUNC__, __LINE__));
308 break;
311 d1(KPrintF("%s/%s/%ld: \n", __FILE__, __FUNC__, __LINE__));
313 // create a temporary copy of the datatypes image
314 // work around datatypes keeping a lock on the image file
315 if (RETURN_OK != CreateTempFile(dti->dti_TempFilename, dti->dti_Filename))
317 d1(KPrintF("%s/%s/%ld: CreateTempFile() failed\n", __FILE__, __FUNC__, __LINE__));
318 break;
321 dti->dti_MaskPlane = NULL;
322 dti->dti_BitMap = NULL;
323 dti->dti_BitMapHeader = NULL;
324 dti->dti_UseCount = 0;
325 dti->dti_Flags = Flags;
327 d1(KPrintF("%s/%s/%ld: dti=%08lx Temp=<%s> Orig=<%s>\n", \
328 __FILE__, __FUNC__, __LINE__, dti, dti->dti_TempFilename, dti->dti_Filename));
330 dti->dti_NotifyTab.nft_FileName = dti->dti_Filename;
331 dti->dti_NotifyTab.nft_Entry = DtImageNotify;
333 /* +dm+ Do not use a friend bitmap for 8bit or less screens */
334 UseFriendBM = !(Flags & DTI_NoFriendBitMap) && (GetBitMapAttr(iInfos.xii_iinfos.ii_Screen->RastPort.BitMap, BMA_DEPTH) > 8);
335 DoRemap = !(Flags & DTIFLAG_NoRemap);
337 // NewDTObjectA()
338 dti->dti_ImageObj = NewDTObject(dti->dti_TempFilename,
339 DTA_SourceType, DTST_FILE,
340 DTA_GroupID, GID_PICTURE,
341 PDTA_DestMode, PMODE_V43,
342 PDTA_Remap, DoRemap,
343 DoRemap ? PDTA_Screen : TAG_IGNORE, (IPTR) iInfos.xii_iinfos.ii_Screen,
344 PDTA_UseFriendBitMap, UseFriendBM,
345 TAG_END);
346 d1(KPrintF("%s/%s/%ld: dti_ImageObj=%08lx\n", __FILE__, __FUNC__, __LINE__, dti->dti_ImageObj));
347 if (NULL == dti->dti_ImageObj)
349 d1(KPrintF("%s/%s/%ld: dti_ImageObj=%08lx\n", __FILE__, __FUNC__, __LINE__, dti->dti_ImageObj));
350 break;
353 // DoDTMethodA()
354 if (!DoDTMethod(dti->dti_ImageObj, NULL, NULL, DTM_PROCLAYOUT, NULL, TRUE))
356 d1(KPrintF("%s/%s/%ld: DTM_PROCLAYOUT failed\n", __FILE__, __FUNC__, __LINE__));
357 break;
360 Result = GetDTAttrs(dti->dti_ImageObj,
361 PDTA_DestBitMap, (IPTR) &dti->dti_BitMap,
362 PDTA_BitMapHeader, (IPTR) &dti->dti_BitMapHeader,
363 TAG_END);
365 d1(KPrintF("%s/%s/%ld: Result=%ld dti_BitMap=%08lx dti_BitMapHeader=%08lx\n", \
366 __FILE__, __FUNC__, __LINE__, Result, dti->dti_BitMap, dti->dti_BitMapHeader));
367 if (Result < 2)
369 d1(KPrintF("%s/%s/%ld: GetDTAttrs failed\n", __FILE__, __FUNC__, __LINE__));
370 d1(KPrintF("%s/%s/%ld: Result=%ld dti_BitMap=%08lx dti_BitMapHeader=%08lx\n", \
371 __FILE__, __FUNC__, __LINE__, Result, dti->dti_BitMap, dti->dti_BitMapHeader));
372 break;
375 if (NULL == dti->dti_BitMap || NULL == dti->dti_BitMapHeader)
376 break;
378 switch (dti->dti_BitMapHeader->bmh_Masking)
380 case mskHasAlpha:
381 #if defined(__amigaos4__)
382 DtImageCreateAlpha(dti);
383 #endif //defined(__amigaos4__)
384 case mskHasMask:
385 case mskHasTransparentColor:
386 GetDTAttrs(dti->dti_ImageObj,
387 PDTA_MaskPlane, (IPTR) &dti->dti_MaskPlane,
388 TAG_END);
389 break;
390 default:
391 dti->dti_MaskPlane = NULL;
392 break;
395 d1(kprintf("%s/%s/%ld: <%s> Masking=%ld MaskPlane=%08lx\n", __FILE__, __FUNC__, __LINE__, \
396 ImageName, dti->dti_BitMapHeader->bmh_Masking, dti->dti_MaskPlane));
398 dti->dti_NotifyNode = AddToMainNotifyList(&dti->dti_NotifyTab, 0);
400 Success = TRUE;
401 } while (0);
403 if (Success)
405 AddTail(&DataTypesImageList, &dti->dti_Node);
406 dti->dti_UseCount++;
408 else if (dti)
410 FreeDatatypesImage(dti);
411 dti = NULL;
414 d1(KPrintF("%s/%s/%ld: END dti=%08lx\n", __FILE__, __FUNC__, __LINE__, dti));
416 return dti;
420 static struct DatatypesImage *FindDatatypesImage(CONST_STRPTR ImageName, ULONG Flags)
422 struct DatatypesImage *dti;
424 for (dti = (struct DatatypesImage *) DataTypesImageList.lh_Head;
425 dti != (struct DatatypesImage *) &DataTypesImageList.lh_Tail;
426 dti = (struct DatatypesImage *) dti->dti_Node.ln_Succ)
428 if ((dti->dti_Flags == Flags) && (0 == Stricmp(ImageName, dti->dti_Filename)))
429 return dti;
432 return NULL;
436 BOOL TempName(STRPTR Buffer, size_t MaxLen)
438 T_TIMEVAL tv;
439 char TimeBuffer[80];
441 GetSysTime(&tv);
443 if (MaxLen <= strlen(CurrentPrefs.pref_ImageCacheDir))
444 return FALSE;
446 stccpy(Buffer, CurrentPrefs.pref_ImageCacheDir, MaxLen);
448 snprintf(TimeBuffer, sizeof(TimeBuffer), "Scalos%08lx%08lx", (unsigned long) tv.tv_secs, (unsigned long) tv.tv_micro);
450 return AddPart(Buffer, TimeBuffer, MaxLen);
454 static LONG CreateTempFile(CONST_STRPTR TempFileName, CONST_STRPTR DtFileName)
456 LONG Result = RETURN_OK;
457 BPTR fdOrig;
458 BPTR fdCopy = BNULL;
459 STRPTR CopyBuffer = NULL;
460 const size_t BuffSize = 8192;
462 do {
463 fdOrig = Open(DtFileName, MODE_OLDFILE);
464 if (BNULL == fdOrig)
466 Result = IoErr();
467 d1(KPrintF("%s/%s/%ld: Result=%ld\n", __FILE__, __FUNC__, __LINE__, Result));
468 break;
470 fdCopy = Open(TempFileName, MODE_NEWFILE);
471 if (BNULL == fdCopy)
473 Result = IoErr();
474 d1(KPrintF("%s/%s/%ld: Result=%ld\n", __FILE__, __FUNC__, __LINE__, Result));
475 break;
477 CopyBuffer = ScalosAlloc(BuffSize);
478 if (NULL == CopyBuffer)
480 Result = ERROR_NO_FREE_STORE;
481 d1(KPrintF("%s/%s/%ld: Result=%ld\n", __FILE__, __FUNC__, __LINE__, Result));
482 break;
485 while (1)
487 LONG actualLength;
489 actualLength = Read(fdOrig, CopyBuffer, BuffSize);
490 if (actualLength <= 0)
492 if (actualLength < 0)
494 Result = IoErr();
495 d1(KPrintF("%s/%s/%ld: Result=%ld\n", __FILE__, __FUNC__, __LINE__, Result));
497 break;
500 if (actualLength != Write(fdCopy, CopyBuffer, actualLength))
502 Result = IoErr();
503 d1(KPrintF("%s/%s/%ld: Result=%ld\n", __FILE__, __FUNC__, __LINE__, Result));
504 break;
507 } while (0);
509 if (CopyBuffer)
510 ScalosFree(CopyBuffer);
511 if (fdOrig)
512 Close(fdOrig);
513 if (fdCopy)
514 Close(fdCopy);
516 if (RETURN_OK != Result)
517 DeleteFile(TempFileName);
519 return Result;
523 static void DtImageNotify(struct internalScaWindowTask *iwt, struct NotifyMessage *msg)
525 struct DatatypesImage *dti;
526 struct DatatypesImage *dtiNew;
528 // original file of <dti> has been modified
529 // try to create Datatypes object from new image file
530 // if we succeed, replace old datatypes image by new one
531 // if we fail, continue using old datatypes object
533 dti = (struct DatatypesImage *) (msg->nm_NReq->nr_UserData - offsetof(struct DatatypesImage, dti_NotifyTab));
535 d1(KPrintF("%s/%s/%ld: nr_Name=<%s> nr_UserData=%08lx dti=%08lx\n", \
536 __FILE__, __FUNC__, __LINE__, msg->nm_NReq->nr_Name, msg->nm_NReq->nr_UserData, dti));
538 do {
539 ULONG Result;
541 d1(KPrintF("%s/%s/%ld: \n", __FILE__, __FUNC__, __LINE__));
543 dtiNew = ScalosAlloc(sizeof(struct DatatypesImage));
544 if (NULL == dtiNew)
545 break;
547 d1(KPrintF("%s/%s/%ld: dtiNew=%08lx\n", __FILE__, __FUNC__, __LINE__, dtiNew));
549 memset(dtiNew, 0, sizeof(struct DatatypesImage));
551 dtiNew->dti_Filename = AllocCopyString(dti->dti_Filename);
552 if (NULL == dtiNew->dti_Filename)
553 break;
555 dtiNew->dti_TempFilename = AllocPathBuffer();
556 if (NULL == dtiNew->dti_TempFilename)
557 break;
559 d1(KPrintF("%s/%s/%ld: \n", __FILE__, __FUNC__, __LINE__));
561 // Create pseudo-random name for temp. file
562 if (!TempName(dtiNew->dti_TempFilename, Max_PathLen))
563 break;
565 d1(KPrintF("%s/%s/%ld: \n", __FILE__, __FUNC__, __LINE__));
567 // create a temporary copy of the datatypes image
568 // work around datatypes keeping a lock on the image file
569 if (RETURN_OK != CreateTempFile(dtiNew->dti_TempFilename, dtiNew->dti_Filename))
570 break;
572 d1(KPrintF("%s/%s/%ld: \n", __FILE__, __FUNC__, __LINE__));
574 // Try to create datatypes image from new file
575 // NewDTObjectA()
576 dtiNew->dti_ImageObj = NewDTObject(dtiNew->dti_TempFilename,
577 DTA_SourceType, DTST_FILE,
578 DTA_GroupID, GID_PICTURE,
579 PDTA_DestMode, PMODE_V43,
580 PDTA_Remap, TRUE,
581 PDTA_Screen, (IPTR) iInfos.xii_iinfos.ii_Screen,
582 PDTA_UseFriendBitMap, (GetBitMapAttr(iInfos.xii_iinfos.ii_Screen->RastPort.BitMap, BMA_DEPTH) <= 8 ? FALSE : TRUE ), /* +dm+ Do not use a friend bitmap for 8bit or less screens */
583 TAG_END);
584 d1(KPrintF("%s/%s/%ld: dti_ImageObj=%08lx\n", __FILE__, __FUNC__, __LINE__, dtiNew->dti_ImageObj));
585 if (NULL == dtiNew->dti_ImageObj)
586 break;
588 // dispose old datatypes object
589 DisposeDTObject(dti->dti_ImageObj);
591 // remove old temp image file
592 DeleteFile(dti->dti_TempFilename);
593 strcpy(dti->dti_TempFilename, dtiNew->dti_TempFilename);
594 strcpy(dtiNew->dti_TempFilename, "");
596 // use new Datatypes object
597 dti->dti_ImageObj = dtiNew->dti_ImageObj;
598 dtiNew->dti_ImageObj = NULL;
600 // Update information from new Datatypes object
602 // DoDTMethodA()
603 if (!DoDTMethod(dti->dti_ImageObj, NULL, NULL, DTM_PROCLAYOUT, NULL, TRUE))
604 break;
606 Result = GetDTAttrs(dti->dti_ImageObj,
607 PDTA_DestBitMap, (IPTR) &dti->dti_BitMap,
608 PDTA_BitMapHeader, (IPTR) &dti->dti_BitMapHeader,
609 TAG_END);
611 if (Result < 2)
612 break;
614 if (NULL == dti->dti_BitMap || NULL == dti->dti_BitMapHeader)
615 break;
617 switch (dti->dti_BitMapHeader->bmh_Masking)
619 case mskHasMask:
620 case mskHasAlpha:
621 case mskHasTransparentColor:
622 GetDTAttrs(dti->dti_ImageObj,
623 PDTA_MaskPlane, (IPTR) &dti->dti_MaskPlane,
624 TAG_END);
625 break;
626 default:
627 dti->dti_MaskPlane = NULL;
628 break;
630 } while (0);
632 FreeDatatypesImage(dtiNew);
636 static void CleanupTempFiles(void)
638 STRPTR Path = NULL;
639 struct AnchorPath *ap;
641 d1(KPrintF("%s/%s/%ld: START\n", __FILE__, __FUNC__, __LINE__));
643 do {
644 LONG rc;
646 ap = ScalosAllocAnchorPath(APF_DOWILD | APF_ITSWILD, Max_PathLen);
647 d1(KPrintF("%s/%s/%ld: ap=%08lx\n", __FILE__, __FUNC__, __LINE__, ap));
648 if (NULL == ap)
649 break;
651 Path = AllocPathBuffer();
652 d1(KPrintF("%s/%s/%ld: Path=%08lx\n", __FILE__, __FUNC__, __LINE__, Path));
653 if (NULL == Path)
654 break;
656 stccpy(Path, CurrentPrefs.pref_ImageCacheDir, Max_PathLen);
658 if (!AddPart(Path, "Scalos#?", Max_PathLen))
659 break;
661 d1(KPrintF("%s/%s/%ld: Path=<%s>\n", __FILE__, __FUNC__, __LINE__, Path));
663 rc = MatchFirst(Path, ap);
664 d1(KPrintF("%s/%s/%ld: MatchFirst rc=%ld\n", __FILE__, __FUNC__, __LINE__, rc));
665 while (RETURN_OK == rc)
667 #ifndef __amigaos4__
668 d1(KPrintF("%s/%s/%ld: ap_Buf=<%s>\n", __FILE__, __FUNC__, __LINE__, ap->ap_Buf));
669 (void) DeleteFile(ap->ap_Buf);
670 #else
671 d1(KPrintF("%s/%s/%ld: ap_Buf=<%s>\n", __FILE__, __FUNC__, __LINE__, ap->ap_Buffer));
672 (void) DeleteFile(ap->ap_Buffer);
673 #endif
675 rc = MatchNext(ap);
676 d1(KPrintF("%s/%s/%ld: MatchNext rc=%ld\n", __FILE__, __FUNC__, __LINE__, rc));
679 MatchEnd(ap);
680 } while (0);
682 if (ap)
683 ScalosFreeAnchorPath(ap);
685 if (Path)
686 FreePathBuffer(Path);
688 d1(KPrintF("%s/%s/%ld: END\n", __FILE__, __FUNC__, __LINE__));
692 #if defined(__amigaos4__)
693 static BOOL DtImageCreateAlpha(struct DatatypesImage *dti)
695 BOOL success = FALSE;
697 do {
698 size_t BytesPerPixel = dti->dti_BitMapHeader->bmh_Width * sizeof(ULONG);
700 if (mskHasAlpha != dti->dti_BitMapHeader->bmh_Masking)
701 break;
703 dti->dti_ARGB = ScalosAlloc(BytesPerPixel * dti->dti_BitMapHeader->bmh_Height);
704 if (NULL == dti->dti_ARGB)
705 break;
707 DoMethod(dti->dti_ImageObj,
708 PDTM_READPIXELARRAY,
709 dti->dti_ARGB,
710 PBPAFMT_ARGB,
711 BytesPerPixel,
714 dti->dti_BitMapHeader->bmh_Width,
715 dti->dti_BitMapHeader->bmh_Height
718 success = TRUE;
719 } while (0);
721 return success;
723 #endif //defined(__amigaos4__)
726 void DtImageDraw(struct DatatypesImage *dti, struct RastPort *rp,
727 LONG Left, LONG Top, LONG Width, LONG Height)
729 d1(kprintf("%s/%s/%ld: START\n", __FILE__, __FUNC__, __LINE__));
730 #if defined(__amigaos4__)
731 if (dti->dti_ARGB)
733 LONG rc;
735 d1(kprintf("%s/%s/%ld: \n", __FILE__, __FUNC__, __LINE__));
736 // BltBitMapTagList
737 rc = BltBitMapTags(
738 BLITA_Source, dti->dti_ARGB,
739 BLITA_Dest, rp,
740 BLITA_SrcX, 0,
741 BLITA_SrcY, 0,
742 BLITA_DestX, Left,
743 BLITA_DestY, Top,
744 BLITA_Width, Width,
745 BLITA_Height, Height,
746 BLITA_SrcType, BLITT_ARGB32,
747 BLITA_DestType, BLITT_RASTPORT,
748 BLITA_SrcBytesPerRow, dti->dti_BitMapHeader->bmh_Width * sizeof(ULONG),
749 BLITA_UseSrcAlpha, TRUE,
750 TAG_END);
752 d1(kprintf("%s/%s/%ld: rc=%ld\n", __FILE__, __FUNC__, __LINE__, rc));
754 else
755 #endif //defined(__amigaos4__)
757 ULONG rc;
759 d1(kprintf("%s/%s/%ld: \n", __FILE__, __FUNC__, __LINE__));
760 // returns 1 if successful, 0 on error
761 rc = DoMethod(dti->dti_ImageObj,
762 DTM_DRAW,
764 Left,
765 Top,
766 Width,
767 Height,
768 0, 0,
769 NULL
771 d1(kprintf("%s/%s/%ld: rc=%ld\n", __FILE__, __FUNC__, __LINE__, rc));
773 if (!rc)
775 if (dti->dti_MaskPlane)
777 d1(kprintf("%s/%s/%ld: \n", __FILE__, __FUNC__, __LINE__));
778 BltMaskBitMapRastPort(dti->dti_BitMap,
779 0, 0,
781 Left, Top,
782 Width, Height,
783 ABC | ABNC | ANBC,
784 dti->dti_MaskPlane);
786 else
788 d1(kprintf("%s/%s/%ld: \n", __FILE__, __FUNC__, __LINE__));
789 BltBitMapRastPort(dti->dti_BitMap,
790 0, 0,
792 Left, Top,
793 Width, Height,
794 ABC | ABNC);
798 d1(kprintf("%s/%s/%ld: END\n", __FILE__, __FUNC__, __LINE__));