Sprite help
Pages: 1 2
Rick Murray (539) 13840 posts |
I forgot that the old sprite format was so wasteful, using all that space to record a simple on/off value. You’re right. There ought to be a SpriteOp… There is a function in DeskLib that calculates the size of a sprite… #define XOS_ReadModeVariable 0x20035 /* Macro to round a number of BITS up to a multiple of words */ #define ROUND32(value) (((value) + 31) & ~31) extern int Sprite_MemorySize(int width, int height, int mode, spritemem_flags flags) { int log2bpp; /* Log base 2 bits per pixel, i.e. 2^log2bpp */ int bpp; /* Bits per pixel */ int bit_strlen; /* Bit string length */ int size; /* Memory requirements */ SWI(2, 3, XOS_ReadModeVariable, /* Get Log2BPC for mode */ mode, 10, /* (used to be Log2BPP */ /* TO */ NULL, NULL, &log2bpp ); bpp = 1 << log2bpp; /* Work out bits per pixel */ bit_strlen = ROUND32(width * bpp); /* Initial bit string length, * * rounded up to nearest word */ bit_strlen >>= 3; /* Convert bits to bytes (/= 8) */ size = bit_strlen * height; /* Multiply by number of columns */ if (flags & sprite_HASMASK) { if (flags & sprite_DEEPFORMAT) { Sizes += ROUND32(width) * height; // mask is a 1bpp of the same dimensions } else { size *= 2; // for older sprites, the mask is the same size as the data (!) } } size += sizeof( sprite_header); /* Add on 44 bytes for header */ if ((flags & sprite_HASPAL) && (bpp <= 8) ) /* Add on size of palette */ { static char bpptocols[] = { 0, 2, 4, 0, 16, 0, 0, 0, 64 }; // 0 1 2 3 4 5 6 7 8 // x x x x = invalid BPP size += bpptocols[bpp] * ( sizeof( palette_entry ) * 2 ); } return(size); } I have extended the code to calculate the mask for “newer” deep sprites, but it doesn’t yet deal with alpha transparency types. It’s a complicated thing. |
Colin (478) 2433 posts |
If the user passes a mode number or mode selector to your function presumably they will use the same mode number/selector in SpriteOp Create Sprite. If the user then uses SpriteOp Create Mask the user doesn’t know what type of mask will be created so can’t set the DEEPFORMAT flag in your function. You can create the sprite with a sprite mode word, so you know the mask type, but then you cant just read the current mode to create a sprite you’d have to convert it into a sprite mode word. As you say complicated. |
Pages: 1 2