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;
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);
115 sprite->left_bit = 0;
116 sprite->right_bit = 31;
117 sprite->image = sprite->mask = 44;
235 error = xosspriteop_save_sprite_file(osspriteop_USER_AREA,
239 "xosspriteop_save_sprite_file: 0x%x: %s",
251 osspriteop_header *hdr = (
void *) ((
char *) area + area->first);
252 unsigned width = hdr->width + 1,
height = hdr->height + 1;
254 unsigned char *chunk_buf;
255 unsigned *p, *elp, *eip;
259 osspriteop_area area;
260 osspriteop_header hdr;
265 if ((((
unsigned)hdr->mode >> 27)&15) != 6) {
266 assert(!
"Unsupported sprite format in bitmap_save");
276 file_hdr.area = *area;
282 file_hdr.hdr.mode = (os_mode)((
unsigned)file_hdr.hdr.mode
287 file_hdr.hdr.mode = (os_mode)((
unsigned)file_hdr.hdr.mode
291 file_hdr.area.sprite_count = 1;
292 file_hdr.area.first =
sizeof(file_hdr.area);
293 file_hdr.area.used =
sizeof(file_hdr) + image_size + mask_size;
295 file_hdr.hdr.image =
sizeof(file_hdr.hdr);
296 file_hdr.hdr.mask = file_hdr.hdr.image + image_size;
297 file_hdr.hdr.size = file_hdr.hdr.mask + mask_size;
299 error = xosfind_openoutw(0,
path, NULL, &fw);
301 NSLOG(netsurf, INFO,
"xosfind_openoutw: 0x%x: %s",
302 error->errnum, error->errmess);
308 p = (
void *) ((
char *) hdr + hdr->image);
311 error = xosgbpb_writew(fw, (
byte*)&file_hdr + 4,
312 sizeof(file_hdr)-4, NULL);
314 error = xosgbpb_writew(fw, (
byte*)p, image_size, NULL);
316 NSLOG(netsurf, INFO,
"xosgbpb_writew: 0x%x: %s",
317 error->errnum, error->errmess);
329 unsigned char *dp = chunk_buf;
330 unsigned *ep = p + chunk_pix;
331 if (ep > elp) ep = elp;
335 *dp++ = ((
unsigned char*)p)[3];
340 unsigned char mb = 0;
343 if (((
unsigned char*)p)[3]) mb |= (1 << msh);
351 if (msh > 0) *dp++ = mb;
356 while ((
int)dp & 3) *dp++ = 0;
360 error = xosgbpb_writew(fw, (
byte*)chunk_buf, dp-chunk_buf, NULL);
363 "xosgbpb_writew: 0x%x: %s",
373 error = xosfind_closew(fw);
375 NSLOG(netsurf, INFO,
"xosfind_closew: 0x%x: %s",
376 error->errnum, error->errmess);
380 error = xosfile_set_type(
path, osfile_TYPE_SPRITE);
382 NSLOG(netsurf, INFO,
"xosfile_set_type: 0x%x: %s",
383 error->errnum, error->errmess);
432 const osspriteop_header *s)
434 const os_colour *palette;
447 if ((
unsigned)s->mode & 0x80000000U)
450 error = xosspriteop_read_sprite_info(osspriteop_PTR,
451 (osspriteop_area *)0x100,
455 NSLOG(netsurf, INFO,
"xosspriteop_read_sprite_info: 0x%x:%s",
456 error->errnum, error->errmess);
459 sp_offset = ((s->width + 1) * 4) - w;
471 sp = (
byte*)s + s->image;
472 mp = (
byte*)s + s->mask;
474 sp += s->left_bit / 8;
475 mp += s->left_bit / 8;
477 if (s->image > (
int)
sizeof(*s))
478 palette = (os_colour*)(s + 1);
482 if (s->mask != s->image) {
492 for (y = 0; y < h; y++) {
494 for(x = 0; x < w; x++) {
495 os_colour d = ((unsigned)palette[(*sp) << 1]) >> 8;
500 d |= ((*mp << 24) ^ 0xff000000U);
507 dp = sdp + dp_offset;
524 osspriteop_header *sprite_header = NULL;
529 area_size =
sizeof(osspriteop_area) +
530 sizeof(osspriteop_header) +
534 if (!
opaque) area_size += image_size;
536 sprite_area = (osspriteop_area *)malloc(area_size);
538 NSLOG(netsurf, INFO,
"no memory for malloc()");
545 sprite_header = (osspriteop_header *)(
sprite_area + 1);
546 sprite_header->size = area_size -
sizeof(osspriteop_area);
547 memset(sprite_header->name, 0x00, 12);
548 strcpy(sprite_header->name,
"bitmap");
549 sprite_header->left_bit = 0;
551 sprite_header->mode = os_MODE8BPP90X90;
552 sprite_header->right_bit = ((
bitmap->
width << 3) - 1) & 31;
553 sprite_header->width = ((
bitmap->
width + 3) >> 2) - 1;
554 sprite_header->image =
sizeof(osspriteop_header) + 2048;
555 sprite_header->mask =
sizeof(osspriteop_header) + 2048;
556 if (!
opaque) sprite_header->mask += image_size;
561 xcolourtrans_read_palette((osspriteop_area *)os_MODE8BPP90X90,
563 (os_palette *)(sprite_header + 1), 2048,
564 (colourtrans_palette_flags)(1 << 1), 0);
574 osspriteop_header *sprite_header)
584 if (xosspriteop_read_save_area_size(osspriteop_PTR, sprite_area,
585 (osspriteop_id)sprite_header, &size)) {
591 save_area->save_area = malloc((
unsigned)size);
599 if (xosspriteop_switch_output_to_sprite(osspriteop_PTR, sprite_area,
600 (osspriteop_id)sprite_header,
save_area->save_area,
617 xosspriteop_switch_output_to_sprite(osspriteop_PTR,
620 (osspriteop_save_area *)
save_area->context3,
636 osspriteop_area *sprite_area = NULL;
637 osspriteop_header *sprite_header = NULL;
642 sprite_header = (osspriteop_header *)(sprite_area + 1);
652 _swix(
Tinct_Plot, _IN(2) | _IN(3) | _IN(4) | _IN(7),
658 if (sprite_header->image != sprite_header->mask) {
661 unsigned *dp = (
unsigned *) buf;
667 int mp_offset = ((sprite_header->width + 1) * 4) - w;
668 byte *mp = (
byte*)sprite_header + sprite_header->mask;
669 bool alpha = ((
unsigned)sprite_header->mode & 0x80000000U) != 0;
673 for(x = 0; x < w; x++) {
676 *mp++ = (d >> 24) ^ 0xff;
678 *mp++ = (d < 0xff000000U) ? 0 : 0xff;
699 unsigned int area_size;
700 osspriteop_area *sprite_area;
703 area_size =
sizeof(osspriteop_area) +
704 sizeof(osspriteop_header) +
sizeof(int);
705 if ((sprite_area = (osspriteop_area *)malloc(area_size)) == NULL) {
707 "Insufficient memory to perform sprite test.");
710 sprite_area->size = area_size + 1;
711 sprite_area->sprite_count = 0;
712 sprite_area->first = 16;
713 sprite_area->used = 16;
714 if (xosspriteop_create_sprite(osspriteop_NAME, sprite_area,
728 osspriteop_area *sprite_area = NULL;
729 osspriteop_header *sprite_header = NULL;
732 .background_images =
true,
753 sprite_header = (osspriteop_header *)(sprite_area + 1);
759 sprite_header = (osspriteop_header *)(sprite_area + 1);
773 rufl_invalidate_cache();
775 os_ACTION_OVERWRITE, 0);
781 rufl_invalidate_cache();
786 _kernel_oserror *error;
static osspriteop_save_area * save_area
The current save area.
nserror
Enumeration of error codes.
int bitmap_get_width(void *bitmap)
get width of a bitmap.
int bitmap_get_height(void *bitmap)
get height of a bitmap.
static void thumbnail_test(void)
Check to see whether 32bpp sprites are available.
osspriteop_area * riscos_bitmap_convert_8bpp(struct bitmap *bitmap)
Convert a bitmap to 8bpp.
static void bitmap_set_opaque(void *vbitmap, bool opaque)
Sets whether a bitmap should be plotted opaque.
void riscos_bitmap_destroy(void *vbitmap)
Free a bitmap.
void riscos_bitmap_overlay_sprite(struct bitmap *bitmap, const osspriteop_header *s)
unsigned char * riscos_bitmap_get_buffer(void *vbitmap)
Return a pointer to the pixel data in a bitmap.
static struct gui_bitmap_table bitmap_table
static void bitmap_modified(void *vbitmap)
The bitmap image has changed, so flush any persistent cache.
static int thumbnail_32bpp_available
Whether we can use 32bpp sprites.
struct gui_bitmap_table * riscos_bitmap_table
bitmap operations table
#define OVERLAY_INDEX
Colour in the overlay sprite that allows the bitmap to show through.
bool riscos_bitmap_save(void *vbitmap, const char *path, unsigned flags)
Save a bitmap in the platform's native format.
bool riscos_bitmap_get_opaque(void *vbitmap)
Gets whether a bitmap should be plotted opaque.
void * riscos_bitmap_create(int width, int height, enum gui_bitmap_flags flags)
Create a bitmap.
static size_t bitmap_get_rowstride(void *vbitmap)
Find the width of a pixel row in bytes.
static osspriteop_area * thumbnail_create_8bpp(struct bitmap *bitmap)
Creates an 8bpp canvas.
nserror riscos_bitmap_render(struct bitmap *bitmap, struct hlcache_handle *content)
Render content into bitmap.
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.
static bool bitmap_initialise(struct bitmap *bitmap)
Initialise a bitmaps sprite area.
#define SAVE_CHUNK_SIZE
Size of buffer used when constructing mask data to be saved.
static void thumbnail_restore_output(struct thumbnail_save_area *save_area)
Restores output to the specified context, and destroys it.
#define BITMAP_SAVE_FULL_ALPHA
save with full alpha channel (if not opaque)
gui_bitmap_flags
Bitmap creation flags.
@ BITMAP_CLEAR
memory should be wiped to 0
@ BITMAP_OPAQUE
image is opaque
Public content interface.
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.
Target independent plotting interface.
#define NSLOG(catname, level, logmsg, args...)
const char * messages_get(const char *key)
Fast lookup of a message by key from the standard Messages hash.
Localised message support (interface).
#define colourtrans_SET_BG_GCOL
After OSLib 6.90, there was a rename of colourtrans defines in order to avoid namespace clashes: svn ...
const os_colour default_palette8[]
Palette definitions for sprites.
nserror ro_warn_user(const char *warning, const char *detail)
Display a warning for a serious problem (eg memory exhaustion).
const struct plotter_table ro_plotters
RISC OS plotter operation table.
byte sprite_bpp(const osspriteop_header *s)
Returns the bit depth of a sprite.
Content for image/x-riscos-sprite (RISC OS interface).
Interface to utility string handling.
RISC OS wimp toolkit bitmap.
bool clear
Whether the bitmap should be initialised to zeros.
struct osspriteop_area * sprite_area
Uncompressed data, or NULL.
int height
height of bitmap
bool opaque
Whether the bitmap is opaque.
Content which corresponds to a single URL.
void *(* create)(int width, int height, enum gui_bitmap_flags flags)
Create a new bitmap.
bool interactive
Redraw to show interactive features.
Sprite output context saving.
osspriteop_save_area * save_area
Tinct SWI numbers and flags for version 0.11.
#define tinct_ERROR_DIFFUSE
#define tinct_SPRITE_MODE
#define Tinct_ConvertSprite
Converts a paletted sprite into its 32bpp equivalent.
#define Tinct_Plot
Plots a sprite at the specified coordinates with a constant 0xff value for the alpha channel,...
Option reading and saving interface.
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.
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.