34 #include <unixlib/local.h> 35 #include <oslib/colourtrans.h> 36 #include <oslib/osfile.h> 37 #include <oslib/osfind.h> 38 #include <oslib/osgbpb.h> 39 #include <oslib/osspriteop.h> 40 #include <oslib/wimp.h> 57 #define OVERLAY_INDEX 0xfe 60 #define SAVE_CHUNK_SIZE 4096 86 unsigned int area_size;
87 osspriteop_area *sprite_area;
88 osspriteop_header *sprite;
92 area_size = 16 + 44 + bitmap->
width * bitmap->
height * 4;
103 sprite_area->size = area_size;
104 sprite_area->sprite_count = 1;
105 sprite_area->first = 16;
106 sprite_area->used = area_size;
109 sprite = (osspriteop_header *) (sprite_area + 1);
110 sprite->size = area_size - 16;
111 memset(sprite->name, 0x00, 12);
112 strncpy(sprite->name,
"bitmap", 12);
113 sprite->width = bitmap->
width - 1;
114 sprite->height = bitmap->
height - 1;
115 sprite->left_bit = 0;
116 sprite->right_bit = 31;
117 sprite->image = sprite->mask = 44;
129 if (width == 0 || height == 0)
132 bitmap = calloc(1,
sizeof(
struct bitmap));
158 return ((
unsigned char *) (bitmap->
sprite_area)) + 16 + 44;
188 return bitmap->
width * 4;
201 unsigned char *sprite;
203 osspriteop_header *sprite_header;
214 sprite_header = (osspriteop_header *) (bitmap->
sprite_area + 1);
216 height = (sprite_header->height + 1);
222 ep = (
void *) (sprite + (size & ~31));
225 if (((p[0] & p[1] & p[2] & p[3] & p[4] & p[5] & p[6] & p[7])
226 & 0xff000000U) != 0xff000000U)
231 ep = (
void *) (sprite + size);
233 if ((*p & 0xff000000U) != 0xff000000U)
return false;
272 if (bitmap == NULL) {
284 error = xosspriteop_save_sprite_file(osspriteop_USER_AREA,
288 "xosspriteop_save_sprite_file: 0x%x: %s",
300 osspriteop_header *hdr = (
void *) ((
char *) area + area->first);
301 unsigned width = hdr->width + 1,
height = hdr->height + 1;
302 unsigned image_size =
height * width * 4;
303 unsigned char *chunk_buf;
304 unsigned *p, *elp, *eip;
308 osspriteop_area area;
309 osspriteop_header hdr;
314 if ((((
unsigned)hdr->mode >> 27)&15) != 6) {
315 assert(!
"Unsupported sprite format in bitmap_save");
325 file_hdr.area = *area;
329 mask_size = ((width + 3) & ~3) *
height;
331 file_hdr.hdr.mode = (os_mode)((
unsigned)file_hdr.hdr.mode
334 mask_size = (((width + 31) & ~31)/8) *
height;
336 file_hdr.hdr.mode = (os_mode)((
unsigned)file_hdr.hdr.mode
340 file_hdr.area.sprite_count = 1;
341 file_hdr.area.first =
sizeof(file_hdr.area);
342 file_hdr.area.used =
sizeof(file_hdr) + image_size + mask_size;
344 file_hdr.hdr.image =
sizeof(file_hdr.hdr);
345 file_hdr.hdr.mask = file_hdr.hdr.image + image_size;
346 file_hdr.hdr.size = file_hdr.hdr.mask + mask_size;
348 error = xosfind_openoutw(0, path, NULL, &fw);
350 NSLOG(netsurf, INFO,
"xosfind_openoutw: 0x%x: %s",
351 error->errnum, error->errmess);
357 p = (
void *) ((
char *) hdr + hdr->image);
360 error = xosgbpb_writew(fw, (byte*)&file_hdr + 4,
361 sizeof(file_hdr)-4, NULL);
363 error = xosgbpb_writew(fw, (byte*)p, image_size, NULL);
365 NSLOG(netsurf, INFO,
"xosgbpb_writew: 0x%x: %s",
366 error->errnum, error->errmess);
374 eip = p + (width *
height);
378 unsigned char *dp = chunk_buf;
379 unsigned *ep = p + chunk_pix;
380 if (ep > elp) ep = elp;
382 if (flags & BITMAP_SAVE_FULL_ALPHA) {
384 *dp++ = ((
unsigned char*)p)[3];
389 unsigned char mb = 0;
392 if (((
unsigned char*)p)[3]) mb |= (1 << msh);
400 if (msh > 0) *dp++ = mb;
405 while ((
int)dp & 3) *dp++ = 0;
409 error = xosgbpb_writew(fw, (byte*)chunk_buf, dp-chunk_buf, NULL);
412 "xosgbpb_writew: 0x%x: %s",
422 error = xosfind_closew(fw);
424 NSLOG(netsurf, INFO,
"xosfind_closew: 0x%x: %s",
425 error->errnum, error->errmess);
429 error = xosfile_set_type(path, osfile_TYPE_SPRITE);
431 NSLOG(netsurf, INFO,
"xosfile_set_type: 0x%x: %s",
432 error->errnum, error->errmess);
462 return bitmap->
width;
481 const osspriteop_header *s)
483 const os_colour *palette;
496 if ((
unsigned)s->mode & 0x80000000U)
499 error = xosspriteop_read_sprite_info(osspriteop_PTR,
500 (osspriteop_area *)0x100,
504 NSLOG(netsurf, INFO,
"xosspriteop_read_sprite_info: 0x%x:%s",
505 error->errnum, error->errmess);
508 sp_offset = ((s->width + 1) * 4) - w;
510 if (w > bitmap->
width)
520 sp = (byte*)s + s->image;
521 mp = (byte*)s + s->mask;
523 sp += s->left_bit / 8;
524 mp += s->left_bit / 8;
526 if (s->image > (
int)
sizeof(*s))
527 palette = (os_colour*)(s + 1);
531 if (s->mask != s->image) {
541 for (y = 0; y < h; y++) {
543 for(x = 0; x < w; x++) {
544 os_colour d = ((unsigned)palette[(*sp) << 1]) >> 8;
549 d |= ((*mp << 24) ^ 0xff000000U);
556 dp = sdp + dp_offset;
571 unsigned image_size = ((bitmap->
width + 3) & ~3) * bitmap->
height;
573 osspriteop_header *sprite_header = NULL;
578 area_size =
sizeof(osspriteop_area) +
579 sizeof(osspriteop_header) +
583 if (!opaque) area_size += image_size;
585 sprite_area = (osspriteop_area *)malloc(area_size);
587 NSLOG(netsurf, INFO,
"no memory for malloc()");
590 sprite_area->size = area_size;
591 sprite_area->sprite_count = 1;
592 sprite_area->first = 16;
593 sprite_area->used = area_size;
594 sprite_header = (osspriteop_header *)(sprite_area + 1);
595 sprite_header->size = area_size -
sizeof(osspriteop_area);
596 memset(sprite_header->name, 0x00, 12);
597 strcpy(sprite_header->name,
"bitmap");
598 sprite_header->left_bit = 0;
599 sprite_header->height = bitmap->
height - 1;
600 sprite_header->mode = os_MODE8BPP90X90;
601 sprite_header->right_bit = ((bitmap->
width << 3) - 1) & 31;
602 sprite_header->width = ((bitmap->
width + 3) >> 2) - 1;
603 sprite_header->image =
sizeof(osspriteop_header) + 2048;
604 sprite_header->mask =
sizeof(osspriteop_header) + 2048;
605 if (!opaque) sprite_header->mask += image_size;
610 xcolourtrans_read_palette((osspriteop_area *)os_MODE8BPP90X90,
612 (os_palette *)(sprite_header + 1), 2048,
613 (colourtrans_palette_flags)(1 << 1), 0);
623 osspriteop_header *sprite_header)
630 if (save_area == NULL)
return NULL;
633 if (xosspriteop_read_save_area_size(osspriteop_PTR, sprite_area,
634 (osspriteop_id)sprite_header, &size)) {
640 save_area->
save_area = malloc((
unsigned)size);
648 if (xosspriteop_switch_output_to_sprite(osspriteop_PTR, sprite_area,
649 (osspriteop_id)sprite_header, save_area->
save_area,
666 xosspriteop_switch_output_to_sprite(osspriteop_PTR,
667 (osspriteop_area *)save_area->
context1,
669 (osspriteop_save_area *)save_area->
context3,
685 osspriteop_area *sprite_area = NULL;
686 osspriteop_header *sprite_header = NULL;
691 sprite_header = (osspriteop_header *)(sprite_area + 1);
696 if (save_area == NULL) {
701 _swix(
Tinct_Plot, _IN(2) | _IN(3) | _IN(4) | _IN(7),
707 if (sprite_header->image != sprite_header->mask) {
710 unsigned *dp = (
unsigned *) buf;
716 int mp_offset = ((sprite_header->width + 1) * 4) - w;
717 byte *mp = (byte*)sprite_header + sprite_header->mask;
718 bool alpha = ((
unsigned)sprite_header->mode & 0x80000000U) != 0;
722 for(x = 0; x < w; x++) {
725 *mp++ = (d >> 24) ^ 0xff;
727 *mp++ = (d < 0xff000000U) ? 0 : 0xff;
748 unsigned int area_size;
749 osspriteop_area *sprite_area;
752 area_size =
sizeof(osspriteop_area) +
753 sizeof(osspriteop_header) +
sizeof(int);
754 if ((sprite_area = (osspriteop_area *)malloc(area_size)) == NULL) {
756 "Insufficient memory to perform sprite test.");
759 sprite_area->size = area_size + 1;
760 sprite_area->sprite_count = 0;
761 sprite_area->first = 16;
762 sprite_area->used = 16;
763 if (xosspriteop_create_sprite(osspriteop_NAME, sprite_area,
777 osspriteop_area *sprite_area = NULL;
778 osspriteop_header *sprite_header = NULL;
781 .background_images =
true,
788 NSLOG(netsurf, INFO,
"content %p in bitmap %p", content, bitmap);
802 sprite_header = (osspriteop_header *)(sprite_area + 1);
808 sprite_header = (osspriteop_header *)(sprite_area + 1);
822 rufl_invalidate_cache();
824 os_ACTION_OVERWRITE, 0);
830 rufl_invalidate_cache();
835 _kernel_oserror *error;
Target independent plotting interface.
int bitmap_get_height(void *bitmap)
get height of a bitmap.
const struct plotter_table ro_plotters
RISC OS plotter operation table.
#define Tinct_ConvertSprite
Converts a paletted sprite into its 32bpp equivalent.
Interface to utility string handling.
static bool bitmap_test_opaque(void *vbitmap)
Tests whether a bitmap has an opaque alpha channel.
static struct gui_bitmap_table bitmap_table
Localised message support (interface).
Public content interface.
static void thumbnail_test(void)
Check to see whether 32bpp sprites are available.
#define OVERLAY_INDEX
Colour in the overlay sprite that allows the bitmap to show through.
#define Tinct_Plot
Plots a sprite at the specified coordinates with a constant 0xff value for the alpha channel...
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.
bool riscos_bitmap_get_opaque(void *vbitmap)
Gets whether a bitmap should be plotted opaque.
static void bitmap_set_opaque(void *vbitmap, bool opaque)
Sets whether a bitmap should be plotted opaque.
#define colourtrans_SET_BG_GCOL
After OSLib 6.90, there was a rename of colourtrans defines in order to avoid namespace clashes: svn ...
bool interactive
Redraw to show interactive features.
Option reading and saving interface.
static size_t bitmap_get_rowstride(void *vbitmap)
Find the width of a pixel row in bytes.
nserror
Enumeration of error codes.
int height
height of bitmap
Palette definitions for sprites.
Tinct SWI numbers and flags for version 0.11.
Content which corresponds to a single URL.
static bool bitmap_initialise(struct bitmap *bitmap)
Initialise a bitmaps sprite area.
bool clear
Whether the bitmap should be initialised to zeros.
struct osspriteop_area * sprite_area
Uncompressed data, or NULL.
#define NSLOG(catname, level, logmsg, args...)
RISC OS wimp toolkit bitmap.
struct gui_bitmap_table * riscos_bitmap_table
bitmap operations table
static void thumbnail_restore_output(struct thumbnail_save_area *save_area)
Restores output to the specified context, and destroys it.
void * riscos_bitmap_create(int width, int height, enum gui_bitmap_flags flags)
Create a bitmap.
gui_bitmap_flags
Bitmap creation flags.
memory should be wiped to 0
static struct thumbnail_save_area * thumbnail_switch_output(osspriteop_area *sprite_area, osspriteop_header *sprite_header)
Switches output to the specified sprite and returns the previous context.
byte sprite_bpp(const osspriteop_header *s)
Returns the bit depth of a sprite.
bool opaque
Whether the bitmap is opaque.
const char * messages_get(const char *key)
Fast lookup of a message by key from the standard Messages hash.
bool riscos_bitmap_save(void *vbitmap, const char *path, unsigned flags)
Save a bitmap in the platform's native format.
#define SAVE_CHUNK_SIZE
Size of buffer used when constructing mask data to be saved.
#define tinct_SPRITE_MODE
Sprite output context saving.
static void bitmap_modified(void *vbitmap)
The bitmap image has changed, so flush any persistent cache.
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.
void riscos_bitmap_destroy(void *vbitmap)
Free a bitmap.
nserror riscos_bitmap_render(struct bitmap *bitmap, struct hlcache_handle *content)
Render content into bitmap.
Content for image/x-riscos-sprite (RISC OS interface).
static osspriteop_area * thumbnail_create_8bpp(struct bitmap *bitmap)
Creates an 8bpp canvas.
nserror ro_warn_user(const char *warning, const char *detail)
Display a warning for a serious problem (eg memory exhaustion).
int bitmap_get_width(void *bitmap)
get width of a bitmap.
osspriteop_area * riscos_bitmap_convert_8bpp(struct bitmap *bitmap)
Convert a bitmap to 8bpp.
static int thumbnail_32bpp_available
Whether we can use 32bpp sprites.
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.
unsigned char * riscos_bitmap_get_buffer(void *vbitmap)
Return a pointer to the pixel data in a bitmap.
const os_colour default_palette8[]
osspriteop_save_area * save_area
#define BITMAP_SAVE_FULL_ALPHA
save with full alpha channel (if not opaque)
void riscos_bitmap_overlay_sprite(struct bitmap *bitmap, const osspriteop_header *s)
void *(* create)(int width, int height, enum gui_bitmap_flags flags)
Create a new bitmap.
#define tinct_ERROR_DIFFUSE