NetSurf
bitmap.c
Go to the documentation of this file.
1/*
2 * Copyright 2008-2025 Chris Young <chris@unsatisfactorysoftware.co.uk>
3 *
4 * This file is part of NetSurf, http://www.netsurf-browser.org/
5 *
6 * NetSurf is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * NetSurf is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#include "amiga/os3support.h"
20
21#include <stdlib.h>
22#include <string.h>
23#include <proto/exec.h>
24#ifdef __amigaos4__
25#include <graphics/blitattr.h>
26#include <graphics/composite.h>
27#endif
28#include <graphics/gfxbase.h>
29#include <proto/datatypes.h>
30#include <datatypes/pictureclass.h>
31#include <proto/dos.h>
32#include <proto/intuition.h>
33#include <proto/utility.h>
34
35#include <proto/guigfx.h>
36#include <guigfx/guigfx.h>
37#include <render/render.h>
38#ifndef __amigaos4__
39#include <inline/guigfx.h>
40#endif
41
42#ifdef __amigaos4__
43#include <exec/extmem.h>
44#include <sys/param.h>
45#endif
46#include "assert.h"
47
48#include "utils/log.h"
49#include "utils/nsoption.h"
50#include "utils/nsurl.h"
51#include "utils/messages.h"
52#include "netsurf/bitmap.h"
53#include "netsurf/content.h"
54
55#include "amiga/gui.h"
56#include "amiga/bitmap.h"
57#include "amiga/plotters.h"
58#include "amiga/memory.h"
59#include "amiga/misc.h"
60#include "amiga/rtg.h"
61#include "amiga/schedule.h"
62
63// disable use of "triangle mode" for scaling
64#ifdef AMI_NS_TRIANGLE_SCALING
65#undef AMI_NS_TRIANGLE_SCALING
66#endif
67
68struct bitmap {
69 int width;
70 int height;
71 UBYTE *pixdata;
72 struct ExtMemIFace *iextmem;
74 bool opaque;
75 int native;
76 struct BitMap *nativebm;
79 PLANEPTR native_mask;
80 Object *dto;
81 struct nsurl *url; /* temporary storage space */
82 char *title; /* temporary storage space */
83 ULONG *icondata; /* for appicons */
84 colour bg; /* alpha blended */
85 APTR drawhandle; /* guigfx */
86};
87
88enum {
92};
93
94struct vertex {
95 float x, y;
96 float s, t, w;
97};
98
99#define VTX(I,X,Y,S,T) vtx[I].x = X; vtx[I].y = Y; vtx[I].s = S; vtx[I].t = T; vtx[I].w = 1.0f;
100#define VTX_RECT(SX,SY,SW,SH,DX,DY,DW,DH) \
101 VTX(0, DX, DY, SX, SY); \
102 VTX(1, DX + DW, DY, SX + SW, SY); \
103 VTX(2, DX, DY + DH, SX, SY + SH); \
104 VTX(3, DX + DW, DY, SX + SW, SY); \
105 VTX(4, DX, DY + DH, SX, SY + SH); \
106 VTX(5, DX + DW, DY + DH, SX + SW, SY + SH);
107
108static APTR pool_bitmap = NULL;
109static bool guigfx_warned = false;
110
111/* exported function documented in amiga/bitmap.h */
113{
114 struct bitmap *bitmap;
115
116 if(pool_bitmap == NULL) pool_bitmap = ami_memory_itempool_create(sizeof(struct bitmap));
117
119 if(bitmap == NULL) return NULL;
120
121 bitmap->size = width * height * 4;
122
123#ifdef __amigaos4__
124 if(nsoption_bool(use_extmem) == true) {
125 uint64 size64 = bitmap->size;
126 bitmap->iextmem = AllocSysObjectTags(ASOT_EXTMEM,
127 ASOEXTMEM_Size, &size64,
128 ASOEXTMEM_AllocationPolicy, EXTMEMPOLICY_IMMEDIATE,
129 TAG_END);
130
131 bitmap->pixdata = NULL;
133 memset(pixdata, 0xff, bitmap->size);
134 } else
135#endif
136 {
138 }
139
140 bitmap->width = width;
142
144
145 bitmap->nativebm = NULL;
148 bitmap->native_mask = NULL;
149 bitmap->url = NULL;
150 bitmap->title = NULL;
151 bitmap->icondata = NULL;
153 bitmap->drawhandle = NULL;
154
155 return bitmap;
156}
157
158static void amiga_bitmap_unmap_buffer(void *p)
159{
160#ifdef __amigaos4__
161 struct bitmap *bm = p;
162
163 if((nsoption_bool(use_extmem) == true) && (bm->pixdata != NULL)) {
164 NSLOG(netsurf, INFO,
165 "Unmapping ExtMem object %p for bitmap %p",
166 bm->iextmem,
167 bm);
168 bm->iextmem->Unmap(bm->pixdata, bm->size);
169 bm->pixdata = NULL;
170 }
171#endif
172}
173
174/* exported function documented in amiga/bitmap.h */
175unsigned char *amiga_bitmap_get_buffer(void *bitmap)
176{
177 struct bitmap *bm = bitmap;
178
179#ifdef __amigaos4__
180 if(nsoption_bool(use_extmem) == true) {
181 if(bm->pixdata == NULL) {
182 NSLOG(netsurf, INFO,
183 "Mapping ExtMem object %p for bitmap %p",
184 bm->iextmem,
185 bm);
186 bm->pixdata = bm->iextmem->Map(NULL, bm->size, 0LL, 0);
187 }
188
189 /* unmap the buffer after one second */
191 }
192#endif
193
194 return bm->pixdata;
195}
196
197/* exported function documented in amiga/bitmap.h */
199{
200 struct bitmap *bm = bitmap;
201
202 if(bm)
203 {
204 return ((bm->width)*4);
205 }
206 else
207 {
208 return 0;
209 }
210}
211
212
213/* exported function documented in amiga/bitmap.h */
215{
216 struct bitmap *bm = bitmap;
217
218 if(bm)
219 {
220 if((bm->nativebm)) { // && (bm->native == AMI_NSBM_TRUECOLOUR)) {
222 }
223
224 if(bm->native_mask) FreeRaster(bm->native_mask, bm->width, bm->height);
225
226 if(bm->drawhandle) ReleaseDrawHandle(bm->drawhandle);
227 bm->drawhandle = NULL;
228
229#ifdef __amigaos4__
230 if(nsoption_bool(use_extmem) == true) {
233 FreeSysObject(ASOT_EXTMEM, bm->iextmem);
234 bm->iextmem = NULL;
235 } else
236#endif
237 {
239 }
240
241 if(bm->url) nsurl_unref(bm->url);
242 if(bm->title) free(bm->title);
243
244 bm->pixdata = NULL;
245 bm->nativebm = NULL;
246 bm->native_mask = NULL;
247 bm->url = NULL;
248 bm->title = NULL;
249
250 ami_memory_itempool_free(pool_bitmap, bm, sizeof(struct bitmap));
251 bm = NULL;
252 }
253}
254
255
256/* exported function documented in amiga/bitmap.h */
257bool amiga_bitmap_save(void *bitmap, const char *path, unsigned flags)
258{
259 int err = 0;
260 Object *dto = NULL;
261
263 {
264 if (flags & AMI_BITMAP_SCALE_ICON) {
265 IDoMethod(dto, PDTM_SCALE, 16, 16, 0);
266
267 if((DoDTMethod(dto, 0, 0, DTM_PROCLAYOUT, 0, 1)) == 0) {
268 return false;
269 }
270 }
271
272 err = SaveDTObjectA(dto, NULL, NULL, path, DTWM_IFF, FALSE, NULL);
273 DisposeDTObject(dto);
274 }
275
276 if(err == 0) return false;
277 else return true;
278}
279
280
281/* exported function documented in amiga/bitmap.h */
283{
284 struct bitmap *bm = bitmap;
285
286#ifdef __amigaos4__
287 /* unmap the buffer after 0.5s - we might need it imminently */
289#endif
290
292 if(bm->native_mask) FreeRaster(bm->native_mask, bm->width, bm->height);
293 bm->nativebm = NULL;
294 bm->native_mask = NULL;
295 bm->native = AMI_NSBM_NONE;
296}
297
298
299/* exported function documented in amiga/bitmap.h */
301{
302 struct bitmap *bm = bitmap;
303 assert(bitmap);
304 bm->opaque = opaque;
305}
306
307
308/* exported function documented in amiga/bitmap.h */
310{
311 struct bitmap *bm = bitmap;
312 assert(bitmap);
313 return bm->opaque;
314}
315
316/**
317 * get width of a bitmap.
318 */
320{
321 struct bitmap *bm = bitmap;
322
323 if(bm)
324 {
325 return(bm->width);
326 }
327 else
328 {
329 return 0;
330 }
331}
332
333/**
334 * get height of a bitmap.
335 */
337{
338 struct bitmap *bm = bitmap;
339
340 if(bm)
341 {
342 return(bm->height);
343 }
344 else
345 {
346 return 0;
347 }
348}
349
350#ifdef BITMAP_DUMP
351void bitmap_dump(struct bitmap *bitmap)
352{
353 int x,y;
354 ULONG *bm = (ULONG *)amiga_bitmap_get_buffer(bitmap);
355
356 printf("Width=%ld, Height=%ld, Opaque=%s\nnativebm=%lx, width=%ld, height=%ld\n",
357 bitmap->width, bitmap->height, bitmap->opaque ? "true" : "false",
359
360 for(y = 0; y < bitmap->height; y++) {
361 for(x = 0; x < bitmap->width; x++) {
362 printf("%lx ", bm[(y*bitmap->width) + x]);
363 }
364 printf("\n");
365 }
366}
367#endif
368
370{
371 Object *dto;
372 struct BitMapHeader *bmhd;
373
374 if((dto = NewDTObject(NULL,
375 DTA_SourceType,DTST_RAM,
376 DTA_GroupID,GID_PICTURE,
377 //DTA_BaseName,"ilbm",
378 PDTA_DestMode,PMODE_V43,
379 TAG_DONE)))
380 {
381 if(GetDTAttrs(dto,PDTA_BitMapHeader,&bmhd,TAG_DONE))
382 {
383 bmhd->bmh_Width = (UWORD)bitmap_get_width(bitmap);
384 bmhd->bmh_Height = (UWORD)bitmap_get_height(bitmap);
385 bmhd->bmh_Depth = (UBYTE)32;
386 if(!amiga_bitmap_get_opaque(bitmap)) bmhd->bmh_Masking = mskHasAlpha;
387 }
388
389 SetDTAttrs(dto,NULL,NULL,
390 DTA_ObjName, bitmap->url ? nsurl_access(bitmap->url) : "",
391 DTA_ObjAnnotation,bitmap->title,
392 DTA_ObjAuthor,messages_get("NetSurf"),
393 DTA_NominalHoriz,bitmap_get_width(bitmap),
394 DTA_NominalVert,bitmap_get_height(bitmap),
395 PDTA_SourceMode,PMODE_V43,
396 TAG_DONE);
397
398 IDoMethod(dto, PDTM_WRITEPIXELARRAY, amiga_bitmap_get_buffer(bitmap),
399 PBPAFMT_ARGB, amiga_bitmap_get_rowstride(bitmap), 0, 0,
401 }
402
403 return dto;
404}
405
406/* Quick way to get an object on disk into a struct bitmap */
407struct bitmap *ami_bitmap_from_datatype(char *filename)
408{
409 Object *dto;
410 struct bitmap *bm = NULL;
411
412 if((dto = NewDTObject(filename,
413 DTA_GroupID, GID_PICTURE,
414 PDTA_DestMode, PMODE_V43,
415 PDTA_PromoteMask, TRUE,
416 TAG_DONE))) {
417 struct BitMapHeader *bmh;
418
419 if(GetDTAttrs(dto, PDTA_BitMapHeader, &bmh, TAG_DONE))
420 {
421 bm = amiga_bitmap_create(bmh->bmh_Width, bmh->bmh_Height, 0);
422
423 IDoMethod(dto, PDTM_READPIXELARRAY, amiga_bitmap_get_buffer(bm),
424 PBPAFMT_ARGB, amiga_bitmap_get_rowstride(bm), 0, 0,
425 bmh->bmh_Width, bmh->bmh_Height);
426
428 }
429 DisposeDTObject(dto);
430 }
431
432 return bm;
433}
434
435static inline struct BitMap *ami_bitmap_get_guigfx(struct bitmap *bitmap,
436 int width, int height, struct BitMap *restrict friendbm, int type, colour bg)
437{
438 struct BitMap *restrict tbm = NULL;
439 struct Screen *scrn = ami_gui_get_screen();
440
442 tbm = ami_rtg_allocbitmap(width, height, 32, 0,
443 friendbm, AMI_BITMAP_FORMAT);
444 if(tbm == NULL) return NULL;
445 } else {
447 8, 0, friendbm, AMI_BITMAP_FORMAT);
448 if(tbm == NULL) return NULL;
449 }
450
451 if(GuiGFXBase != NULL) {
452 struct RastPort rp;
453 InitRastPort(&rp);
454 rp.BitMap = tbm;
455 ULONG dithermode = DITHERMODE_NONE;
456
457 if(nsoption_int(dither_quality) == 1) {
458 dithermode = DITHERMODE_EDD;
459 } else if(nsoption_int(dither_quality) == 2) {
460 dithermode = DITHERMODE_FS;
461 }
462
463 if((!bitmap->opaque) && nsoption_bool(invert_alpha)) {
464 /* invert alpha */
465 unsigned char *bmbuffer = amiga_bitmap_get_buffer(bitmap);
466 for(int i = 0; i < (bitmap->width * bitmap->height * 4); i+=4) {
467 bmbuffer[i] = 255 - bmbuffer[i];
468 }
469 }
470
471 APTR picture = MakePicture(amiga_bitmap_get_buffer(bitmap), bitmap->width, bitmap->height,
472 GGFX_PixelFormat, PIXFMT_0RGB_32,
473 GGFX_AlphaPresent, !bitmap->opaque,
474 GGFX_Independent, TRUE,
475 GGFX_DestWidth, width,
476 GGFX_DestHeight, height,
477 TAG_DONE);
478
479 if((!bitmap->opaque) && nsoption_bool(invert_alpha)) {
480 /* invert alpha */
481 unsigned char *bmbuffer = amiga_bitmap_get_buffer(bitmap);
482 for(int i = 0; i < (bitmap->width * bitmap->height * 4); i+=4) {
483 bmbuffer[i] = 255 - bmbuffer[i];
484 }
485 }
486
487 if(picture == NULL) {
488 amiga_warn_user("BMConvErr", NULL);
489 }
490
491 /* Alpha-blend the image to the provided background colour.
492 * This appears to be using an inverted alpha on OS3
493 */
494 if((!bitmap->opaque) && (bg != NS_TRANSPARENT)) {
495 DoPictureMethod(picture, PICMTHD_TINTALPHA, colour_rb_swap(bg), TAG_DONE);
496 }
497
498 if(bitmap->drawhandle) ReleaseDrawHandle(bitmap->drawhandle);
499
500 bitmap->drawhandle = ObtainDrawHandle(
501 NULL,
502 &rp,
503 scrn->ViewPort.ColorMap,
504 GGFX_DitherMode, dithermode,
505 TAG_DONE);
506
507 if(bitmap->drawhandle) {
508 DrawPicture(bitmap->drawhandle, picture, 0, 0, TAG_DONE);
509 }
510
511 DeletePicture(picture);
512
513 } else {
514 if(guigfx_warned == false) {
515 amiga_warn_user("BMConvErr", NULL);
516 guigfx_warned = true;
517 }
518 }
519
520 if(((type == AMI_NSBM_TRUECOLOUR) && (nsoption_int(cache_bitmaps) == 2)) ||
521 ((type == AMI_NSBM_PALETTEMAPPED) && (((bitmap->width == width) &&
522 (bitmap->height == height) && (nsoption_int(cache_bitmaps) == 2)) ||
523 (nsoption_int(cache_bitmaps) >= 1)))) {
524 bitmap->nativebm = tbm;
527 bitmap->native = type;
528 bitmap->bg = bg;
529 }
530
531 return tbm;
532}
533
534static inline struct BitMap *ami_bitmap_get_generic(struct bitmap *bitmap,
535 int width, int height, struct BitMap *restrict friendbm, int type, colour bg)
536{
537 struct BitMap *restrict tbm = NULL;
538 struct Screen *scrn = ami_gui_get_screen();
539
540 if(bitmap->nativebm)
541 {
542#ifndef __amigaos4__
543 BOOL nativebmalphablend = ((bitmap->bg == bg) || bitmap->opaque);
544#else
545 /* No pre-blend alpha on OS4 */
546 BOOL nativebmalphablend = TRUE;
547#endif
548 if((bitmap->nativebmwidth == width) && (bitmap->nativebmheight == height) && nativebmalphablend)
549 {
550 tbm = bitmap->nativebm;
551 return tbm;
552 } else if((bitmap->nativebmwidth == bitmap->width) &&
553 (bitmap->nativebmheight == bitmap->height) && nativebmalphablend) { // >= width/height ?
554 tbm = bitmap->nativebm;
555 } else {
557 }
558 }
559
560 if(tbm == NULL) {
561 /* If palette mapped or OS3, use guigfx */
562#ifdef __amigaos4__
564#endif
565 return ami_bitmap_get_guigfx(bitmap, width, height, friendbm, type, bg);
566
567
570 friendbm, AMI_BITMAP_FORMAT);
571 if(tbm == NULL) return NULL;
572
574 tbm, bitmap->width, bitmap->height,
576 }
577
578 if(((type == AMI_NSBM_TRUECOLOUR) && (nsoption_int(cache_bitmaps) == 2)) ||
579 ((type == AMI_NSBM_PALETTEMAPPED) && (((bitmap->width == width) &&
580 (bitmap->height == height) && (nsoption_int(cache_bitmaps) == 2)) ||
581 (nsoption_int(cache_bitmaps) >= 1)))) {
582 bitmap->nativebm = tbm;
585 bitmap->native = type;
586 }
587 }
588
589 if((bitmap->width != width) || (bitmap->height != height)) {
591 return bitmap->nativebm;
592
593 struct BitMap *restrict scaledbm;
594 struct BitScaleArgs bsa;
595 int depth = 32;
596 if(type == AMI_NSBM_PALETTEMAPPED) depth = 8;
597
598 scaledbm = ami_rtg_allocbitmap(width, height, depth, 0,
599 friendbm, AMI_BITMAP_FORMAT);
600#ifdef __amigaos4__
601 if(__builtin_expect(((GfxBase->LibNode.lib_Version >= 53) &&
602 (type == AMI_NSBM_TRUECOLOUR)), 1)) {
603 /* AutoDoc says v52, but this function isn't in OS4.0, so checking for v53 (OS4.1)
604 * Additionally, when we use friend BitMaps in non 32-bit modes it freezes the OS */
605
606 uint32 flags = 0;
607 uint32 err = COMPERR_Success;
608#ifdef AMI_NS_TRIANGLE_SCALING
609 struct vertex vtx[6];
610 VTX_RECT(0, 0, bitmap->width, bitmap->height, 0, 0, width, height);
611
612 flags = COMPFLAG_HardwareOnly;
613 if(nsoption_bool(scale_quality) == true) flags |= COMPFLAG_SrcFilter;
614
615 err = CompositeTags(COMPOSITE_Src, tbm, scaledbm,
616 COMPTAG_VertexArray, vtx,
617 COMPTAG_VertexFormat, COMPVF_STW0_Present,
618 COMPTAG_NumTriangles, 2,
619 COMPTAG_Flags, flags,
620 COMPTAG_FriendBitMap, scrn->RastPort.BitMap,
621 TAG_DONE);
622
623 if (err != COMPERR_Success) {
624 NSLOG(netsurf, INFO,
625 "Composite error %ld - falling back",
626 err);
627 /* If it failed, do it again the way
628 * which works in software
629 */
630#else
631 {
632#endif
633 flags = 0;
634 if(nsoption_bool(scale_quality) == true) flags |= COMPFLAG_SrcFilter;
635
636 err = CompositeTags(COMPOSITE_Src, tbm, scaledbm,
637 COMPTAG_ScaleX, COMP_FLOAT_TO_FIX((float)width/bitmap->width),
638 COMPTAG_ScaleY, COMP_FLOAT_TO_FIX((float)height/bitmap->height),
639 COMPTAG_Flags, flags,
640 COMPTAG_FriendBitMap, scrn->RastPort.BitMap,
641 TAG_DONE);
642 /* If it still fails... it's non-fatal */
643 NSLOG(netsurf, INFO,
644 "Fallback returned error %ld", err);
645 }
646 } else /* Do it the old-fashioned way. This is pretty slow, even on OS4.1 */
647#endif
648 {
649 bsa.bsa_SrcX = 0;
650 bsa.bsa_SrcY = 0;
651 bsa.bsa_SrcWidth = bitmap->width;
652 bsa.bsa_SrcHeight = bitmap->height;
653 bsa.bsa_DestX = 0;
654 bsa.bsa_DestY = 0;
655 bsa.bsa_XSrcFactor = bitmap->width;
656 bsa.bsa_XDestFactor = width;
657 bsa.bsa_YSrcFactor = bitmap->height;
658 bsa.bsa_YDestFactor = height;
659 bsa.bsa_SrcBitMap = tbm;
660 bsa.bsa_DestBitMap = scaledbm;
661 bsa.bsa_Flags = 0;
662
663 BitMapScale(&bsa);
664 }
665
668 tbm = scaledbm;
669 bitmap->nativebm = NULL;
671
672 if(nsoption_int(cache_bitmaps) >= 1)
673 {
674 bitmap->nativebm = tbm;
677 bitmap->native = type;
678 bitmap->bg = bg;
679 }
680 }
681
682 return tbm;
683}
684
685
686static inline struct BitMap *ami_bitmap_get_truecolour(struct bitmap *bitmap,
687 int width, int height, struct BitMap *friendbm, colour bg)
688{
691 }
692
694}
695
697 int height, struct BitMap *n_bm)
698{
700 UBYTE maskbit = 0;
701 ULONG bm_width;
702 int y, x, bpr;
703
704 if((height != bitmap->height) || (width != bitmap->width)) return NULL;
705 if(amiga_bitmap_get_opaque(bitmap) == true) return NULL;
707
708 bm_width = GetBitMapAttr(n_bm, BMA_WIDTH);
709 bpr = RASSIZE(bm_width, 1);
710 bitmap->native_mask = AllocRaster(bm_width, height);
711 SetMem(bitmap->native_mask, 0, bpr * height);
712
713 for(y=0; y<height; y++) {
714 for(x=0; x<width; x++) {
715 if ((*bmi & 0xff000000U) <= (ULONG)nsoption_int(mask_alpha)) maskbit = 0;
716 else maskbit = 1;
717 bmi++;
718 bitmap->native_mask[(y*bpr) + (x/8)] |=
719 maskbit << (7 - (x % 8));
720 }
721 }
722
723 return bitmap->native_mask;
724}
725
726static inline struct BitMap *ami_bitmap_get_palettemapped(struct bitmap *bitmap,
727 int width, int height, struct BitMap *friendbm, colour bg)
728{
731 }
732
734}
735
736struct BitMap *ami_bitmap_get_native(struct bitmap *bitmap, int width, int height,
737 bool palette_mapped, struct BitMap *friendbm, colour bg)
738{
739 if(bitmap == NULL) return NULL;
740
741 if(__builtin_expect(palette_mapped == true, 0)) {
742 return ami_bitmap_get_palettemapped(bitmap, width, height, friendbm, bg);
743 } else {
744 return ami_bitmap_get_truecolour(bitmap, width, height, friendbm, bg);
745 }
746}
747
749{
751 pool_bitmap = NULL;
752}
753
755{
756 NSLOG(netsurf, INFO, "Entering bitmap_render");
757
758 int plot_width;
759 int plot_height;
760 struct gui_globals *bm_globals;
761
762 plot_width = MIN(content_get_width(content), bitmap->width);
763 plot_height = ((plot_width * bitmap->height) + (bitmap->width / 2)) /
764 bitmap->width;
765
766 bm_globals = ami_plot_ra_alloc(bitmap->width, bitmap->height, true, false);
767 ami_clearclipreg(bm_globals);
768
769 struct redraw_context ctx = {
770 .interactive = false,
771 .background_images = true,
772 .plot = &amiplot,
773 .priv = bm_globals
774 };
775
776 content_scaled_redraw(content, plot_width, plot_height, &ctx);
777
780
781 /**\todo In theory we should be able to move the bitmap to our native area
782 to try to avoid re-conversion (at the expense of memory) */
783
784 ami_plot_ra_free(bm_globals);
786
787 return NSERROR_OK;
788}
789
790void ami_bitmap_set_url(struct bitmap *bm, struct nsurl *url)
791{
792 if(bm->url != NULL) return;
793 bm->url = nsurl_ref(url);
794}
795
796void ami_bitmap_set_title(struct bitmap *bm, const char *title)
797{
798 if(bm->title != NULL) return;
799 bm->title = strdup(title);
800}
801
802void ami_bitmap_set_icondata(struct bitmap *bm, ULONG *icondata)
803{
804 bm->icondata = icondata;
805}
806
808{
809 if(bm->icondata) free(bm->icondata);
810 bm->icondata = NULL;
811}
812
813bool ami_bitmap_is_nativebm(struct bitmap *bm, struct BitMap *nbm)
814{
815 if(bm->nativebm == nbm) return true;
816 else return false;
817}
818
819
822 .destroy = amiga_bitmap_destroy,
823 .set_opaque = amiga_bitmap_set_opaque,
824 .get_opaque = amiga_bitmap_get_opaque,
825 .get_buffer = amiga_bitmap_get_buffer,
826 .get_rowstride = amiga_bitmap_get_rowstride,
827 .get_width = bitmap_get_width,
828 .get_height = bitmap_get_height,
829 .modified = amiga_bitmap_modified,
830 .render = bitmap_render,
831};
832
struct Screen * ami_gui_get_screen(void)
Get a pointer to the screen NetSurf is running on.
Definition: gui.c:404
static struct Screen * scrn
Definition: gui.c:328
nserror amiga_warn_user(const char *warning, const char *detail)
Warn the user of an event.
Definition: misc.c:79
const struct plotter_table amiplot
Definition: plotters.c:1148
void ami_plot_ra_free(struct gui_globals *gg)
Free a plotter render area.
Definition: plotters.c:257
struct BitMap * ami_plot_ra_get_bitmap(struct gui_globals *gg)
Get a drawing BitMap associated with a render area.
Definition: plotters.c:301
static bool palette_mapped
Definition: plotters.c:96
void ami_clearclipreg(struct gui_globals *gg)
Definition: plotters.c:317
struct gui_globals * ami_plot_ra_alloc(ULONG width, ULONG height, bool force32bit, bool alloc_pen_list)
Alloc a plotter render area.
Definition: plotters.c:111
nserror ami_schedule(int t, void(*callback)(void *p), void *p)
Schedule a callback.
Definition: schedule.c:331
bool bitmap_test_opaque(void *bitmap)
Test whether a bitmap is completely opaque (no transparency).
Definition: bitmap.c:316
nserror
Enumeration of error codes.
Definition: errors.h:29
@ NSERROR_OK
No error.
Definition: errors.h:30
const char * type
Definition: filetype.cpp:44
#define VTX_RECT(SX, SY, SW, SH, DX, DY, DW, DH)
Definition: bitmap.c:100
static struct BitMap * ami_bitmap_get_truecolour(struct bitmap *bitmap, int width, int height, struct BitMap *friendbm, colour bg)
Definition: bitmap.c:686
size_t amiga_bitmap_get_rowstride(void *bitmap)
Find the width of a pixel row in bytes.
Definition: bitmap.c:198
static struct gui_bitmap_table bitmap_table
Definition: bitmap.c:820
void * amiga_bitmap_create(int width, int height, enum gui_bitmap_flags flags)
Create a bitmap.
Definition: bitmap.c:112
void ami_bitmap_set_url(struct bitmap *bm, struct nsurl *url)
Set bitmap URL.
Definition: bitmap.c:790
int bitmap_get_width(void *bitmap)
get width of a bitmap.
Definition: bitmap.c:319
void ami_bitmap_free_icondata(struct bitmap *bm)
Free an icondata pointer.
Definition: bitmap.c:807
static nserror bitmap_render(struct bitmap *bitmap, struct hlcache_handle *content)
Definition: bitmap.c:754
void ami_bitmap_fini(void)
Cleanup bitmap allocations.
Definition: bitmap.c:748
int bitmap_get_height(void *bitmap)
get height of a bitmap.
Definition: bitmap.c:336
static struct BitMap * ami_bitmap_get_guigfx(struct bitmap *bitmap, int width, int height, struct BitMap *restrict friendbm, int type, colour bg)
Definition: bitmap.c:435
bool amiga_bitmap_save(void *bitmap, const char *path, unsigned flags)
Save a bitmap in the platform's native format.
Definition: bitmap.c:257
PLANEPTR ami_bitmap_get_mask(struct bitmap *bitmap, int width, int height, struct BitMap *n_bm)
Definition: bitmap.c:696
struct BitMap * ami_bitmap_get_native(struct bitmap *bitmap, int width, int height, bool palette_mapped, struct BitMap *friendbm, colour bg)
Definition: bitmap.c:736
static void amiga_bitmap_unmap_buffer(void *p)
Definition: bitmap.c:158
bool ami_bitmap_is_nativebm(struct bitmap *bm, struct BitMap *nbm)
Test if a BitMap is owned by a bitmap.
Definition: bitmap.c:813
struct bitmap * ami_bitmap_from_datatype(char *filename)
Definition: bitmap.c:407
struct gui_bitmap_table * amiga_bitmap_table
Definition: bitmap.c:833
static struct BitMap * ami_bitmap_get_palettemapped(struct bitmap *bitmap, int width, int height, struct BitMap *friendbm, colour bg)
Definition: bitmap.c:726
void ami_bitmap_set_title(struct bitmap *bm, const char *title)
Set bitmap title.
Definition: bitmap.c:796
void amiga_bitmap_modified(void *bitmap)
The bitmap image has changed, so flush any persistant cache.
Definition: bitmap.c:282
static APTR pool_bitmap
Definition: bitmap.c:108
void amiga_bitmap_set_opaque(void *bitmap, bool opaque)
Sets whether a bitmap should be plotted opaque.
Definition: bitmap.c:300
static struct BitMap * ami_bitmap_get_generic(struct bitmap *bitmap, int width, int height, struct BitMap *restrict friendbm, int type, colour bg)
Definition: bitmap.c:534
static bool guigfx_warned
Definition: bitmap.c:109
Object * ami_datatype_object_from_bitmap(struct bitmap *bitmap)
Definition: bitmap.c:369
@ AMI_NSBM_TRUECOLOUR
Definition: bitmap.c:90
@ AMI_NSBM_PALETTEMAPPED
Definition: bitmap.c:91
@ AMI_NSBM_NONE
Definition: bitmap.c:89
void ami_bitmap_set_icondata(struct bitmap *bm, ULONG *icondata)
Set an icondata pointer.
Definition: bitmap.c:802
bool amiga_bitmap_get_opaque(void *bitmap)
Gets whether a bitmap should be plotted opaque.
Definition: bitmap.c:309
unsigned char * amiga_bitmap_get_buffer(void *bitmap)
Return a pointer to the pixel data in a bitmap.
Definition: bitmap.c:175
void amiga_bitmap_destroy(void *bitmap)
Free a bitmap.
Definition: bitmap.c:214
#define AMI_BITMAP_SCALE_ICON
Definition: bitmap.h:31
#define AMI_BITMAP_FORMAT
Definition: bitmap.h:30
Generic bitmap handling interface.
gui_bitmap_flags
Bitmap creation flags.
Definition: bitmap.h:36
@ BITMAP_OPAQUE
image is opaque
Definition: bitmap.h:38
Public content interface.
int content_get_width(struct hlcache_handle *h)
Retrieve width of content.
Definition: content.c:1150
bool content_scaled_redraw(struct hlcache_handle *h, int width, int height, const struct redraw_context *ctx)
Redraw a content with scale set for horizontal fit.
Definition: content.c:583
#define NSLOG(catname, level, logmsg, args...)
Definition: log.h:116
void * ami_memory_clear_alloc(size_t size, UBYTE value)
Definition: memory.c:42
#define ami_memory_itempool_create(s)
Definition: memory.h:54
#define ami_memory_itempool_alloc(p, s)
Definition: memory.h:56
#define ami_memory_itempool_free(p, i, s)
Definition: memory.h:57
#define ami_memory_itempool_delete(p)
Definition: memory.h:55
#define ami_memory_clear_free(p)
Definition: memory.h:39
const char * messages_get(const char *key)
Fast lookup of a message by key from the standard Messages hash.
Definition: messages.c:256
Localised message support (interface).
NetSurf URL handling (interface).
void nsurl_unref(nsurl *url)
Drop a reference to a NetSurf URL object.
const char * nsurl_access(const nsurl *url)
Access a NetSurf URL object as a string.
nsurl * nsurl_ref(nsurl *url)
Increment the reference count to a NetSurf URL object.
struct nsurl nsurl
NetSurf URL object.
Definition: nsurl.h:31
void FreeSysObject(ULONG type, APTR obj)
Definition: os3support.c:350
Minimal compatibility header for AmigaOS 3.
#define AllocSysObjectTags(A, B, C, D)
Definition: os3support.h:157
#define PDTA_PromoteMask
Definition: os3support.h:75
#define MIN(a, b)
Definition: os3support.h:51
#define IDoMethod
Definition: os3support.h:169
uint64_t uint64
Definition: os3support.h:186
uint32_t uint32
Definition: os3support.h:184
#define SaveDTObjectA(O, W, R, F, M, I, A)
Definition: os3support.h:146
#define SetMem
Definition: os3support.h:175
#define colour_rb_swap(c)
Definition: plot_style.h:217
#define NS_TRANSPARENT
Transparent colour value.
Definition: plot_style.h:39
int width
Definition: gui.c:161
int height
Definition: gui.c:162
void ami_rtg_writepixelarray(UBYTE *pixdata, struct BitMap *bm, ULONG width, ULONG height, ULONG bpr, ULONG format)
Definition: rtg.c:44
void ami_rtg_freebitmap(struct BitMap *bm)
Definition: rtg.c:35
void ami_rtg_readpixelarray(struct BitMap *bm, UBYTE **pixdata, ULONG width, ULONG height, ULONG bpr, ULONG format)
Definition: rtg.c:70
struct BitMap * ami_rtg_allocbitmap(ULONG width, ULONG height, ULONG depth, ULONG flags, struct BitMap *friend, RGBFTYPE format)
Definition: rtg.c:25
Abstract RTG functions for newer/older/non-P96 systems.
Interface to utility string handling.
RISC OS wimp toolkit bitmap.
Definition: bitmap.c:68
char * title
Definition: bitmap.c:82
int nativebmwidth
Definition: bitmap.c:77
int native
Definition: bitmap.c:75
int width
width of bitmap
Definition: bitmap.c:69
struct BitMap * nativebm
Definition: bitmap.c:76
ULONG * icondata
Definition: bitmap.c:83
int height
height of bitmap
Definition: bitmap.c:70
Object * dto
Definition: bitmap.c:80
colour bg
Definition: bitmap.c:84
bool opaque
Whether the bitmap is opaque.
Definition: bitmap.c:74
UBYTE * pixdata
Definition: bitmap.c:71
struct ExtMemIFace * iextmem
Definition: bitmap.c:72
struct nsurl * url
Definition: bitmap.c:81
APTR drawhandle
Definition: bitmap.c:85
int nativebmheight
Definition: bitmap.c:78
PLANEPTR native_mask
Definition: bitmap.c:79
uint32 size
Definition: bitmap.c:73
Content which corresponds to a single URL.
Bitmap operations.
Definition: bitmap.h:125
void *(* create)(int width, int height, enum gui_bitmap_flags flags)
Create a new bitmap.
Definition: bitmap.h:136
High-level cache handle.
Definition: hlcache.c:66
Redraw context.
Definition: plotters.h:51
bool interactive
Redraw to show interactive features.
Definition: plotters.h:59
Definition: bitmap.c:94
float t
Definition: bitmap.c:96
float x
Definition: bitmap.c:95
float s
Definition: bitmap.c:96
float w
Definition: bitmap.c:96
float y
Definition: bitmap.c:95
uint32_t colour
Colour type: XBGR.
Definition: types.h:35
Option reading and saving interface.
#define nsoption_int(OPTION)
Get the value of an integer option.
Definition: nsoption.h:317
#define nsoption_bool(OPTION)
Get the value of a boolean option.
Definition: nsoption.h:308
static nserror path(const struct redraw_context *ctx, const plot_style_t *pstyle, const float *p, unsigned int n, const float transform[6])
Plots a path.
Definition: plot.c:821
static nserror bitmap(const struct redraw_context *ctx, struct bitmap *bitmap, int x, int y, int width, int height, colour bg, bitmap_flags_t flags)
Plot a bitmap.
Definition: plot.c:857