SRL Archive - Research & Development Lounge

256 color mode [source]


wantonman

2013-01-13 00:44:29

Bitmaps

For the bitmap implantation we can distinguish roughly two different objects. The bitmap manager and the bitmap itself. The bitmap manager is a class that manages multiple bitmaps, later more about this.

The bitmap
When using Lazarus you will run into some compatibility issues when working with the normal TBitmap class. Therefore we decided to make our bitmap class: TMufasaBitmap. The aim of this class is to be fast and be able to run on Linux&Windows.
The image-data (32 bits) is stored in the FData property, an array of TRGB32. TRGB32 is a record with 4 members: B,G,R,A : byte. 32 Bits bitmaps have the advantage that their memory is better aligned (4-bytes), so easier accessible. As you can directly access the rawdata, bitmap functions will be fast and easy to use. Since the data is stored as an array you need to do convert your coordinate into a array-index using the following transformation: (x,y) -> y * w(width of the bitmap) + x.
For example we want to change pixel (5,20) to clWhite and our bitmaps width = 50:
Bitmap.FData[20 * 50 + 5].r := 255;
Bitmap.FData[20 * 50 + 5].g := 255;
Bitmap.FData[20 * 50 + 5].b := 255;
or
With Bitmap.FData[20 * 50 + 5] do
begin;
r:= 255;g:= 255;b:= 255;
end;

Also you can name a bitmap by setting the BmpName property. This may come in handy when handling multiple bitmaps (later more about this). A brief explanation of certain functions and there behaviour:
LoadFromFile/SaveToFile
Does, as the title says, loads or saves a bitmap. It should be able to load/save most of the standard extensions (bmp,png,jpg)
Width/Height
These are read-only properties, they return the bitmap width/height
SetSize
Use this to change the width&height of the bitmap. It kind-of crops the old image (if there was any). So if you make your bitmap bigger, you would get the old bitmap with a black border. If you would make your bitmap smaller, you would get only a part of the original bitmap.
ValidatePoint
Checks whether the point(x,y) is on the bitmap, if not throws an exception
TransparentColor
When using FindBitmap, the TransparentColor is used. If it hasn't been set yet, clBlack is used instead. Transparent color means every pixel with that color isn't checked in finding procedures. Also if set, it's used in FastDraw functions
CreateTMask
It creates a TMask from the bitmap, it doesn't check whether the bitmap actually is a mask, so be sure when to use this. (It checks if the red = 255, and then assumes the pixel is a white pixel, otherwise it assumes its black).
TheRest
Most of these functions speak for themselves. If it has the parameter TargetBitmap, it assumes this bitmap is already created.

TMBitmaps
If you need to manage multiple bitmaps, like scripts do, you can make use of the bitmap manager TMBitmaps. It takes care of your bitmaps, returns a new one when you need it, lets you free the bitmaps, and makes sure there aren't any unfreed bitmaps left.

CreateBMP
Creates a new bitmap with size w,h. Then returns you the index of this bitmap in the manager, use this index to retrieve the bitmap later.

Bmp[Index]/GetBMP
Gets the TMufasaBitmap stored at the index, checks if the bitmap exists, throws an exception otherwise

CreateBMPFromString
Creates a bmp based on a string. The string would be made like this:
1) Make a string with the following format: RGBRGBRGB; Where every RGB represents a pixel of the bitmap
2) Compress it with zLib, store the width/height of the bitmap
3) Encode it with base64, so that it doesn't have unreadable characters and can be freely spread over the internet.

CreateMirroredBitmap
Creates a copy of the bitmap, but mirrored with one of the mirror styles:
MirrorWidth: Mirror in the Y-axis
MirrorHeight: Mirror in the X-axis
MirrorLine: Mirror in the line y=x

Destroy
If you destroy the bitmap manager, it goes through every bitmap to check whether its freed or not, if not it will mention the BitmapName (if not set the bitmap index).



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


okay now with all that being said is it possible to modify the
FData property to hold 8-bit registers to accomodate fir the 256 colormode?

there are a few things to consitter like the color pallate difference
and dither algoritms…

wantonman

2013-01-27 18:54:37

This is something i may need a little help on… if any1 know how to do this please help… i really want this to be up and rolling…

i know that when i swich my adapter to 8 bit mode nothing is 24 or 32 bit anymore…
typically in 8 bit color you have 3 bits assigned for red and green
and 2 bits to blue…

anyways in mml's source i see mostly zero compatability for this type of mode… unfortunately.. ive tryied tampering with a few variables and typed but i just end up always hitting a wall of error…
if i do manage to get a sucessful compilation… theres no dierence x-cept ivemanaged to change some color values around… notebly only the
first section of the 8*8*8 byte structure… ughhh soo yehh wen a week has passed and i get no results it is time to stop and ask here.. thanks community

Brandon

2013-01-27 22:25:39

According to your first post, you seemed to have everything sorted and planned :S

Provide some advantages to 8-bit bitmaps and I'll see what I can do if it intrigues me.. Some others may be able to help you though.
Why not bother Wizzup or Ben a bit?

For now, I don't see any advantages to 256 colour mode.

i luffs yeww

2013-01-27 23:00:18

From: Brandon
According to your first post, you seemed to have everything sorted and planned :S

Provide some advantages to 8-bit bitmaps and I'll see what I can do if it intrigues me.. Some others may be able to help you though.
Why not bother Wizzup or Ben a bit?

For now, I don't see any advantages to 256 colour mode.


He did bother Wizzup and Ben. And everyone on irc. And the consensus was the same as yours - there's no point.

wantonman

2013-01-29 23:33:35

i play runescape in 640x480 256 color mode… just because theres just overall less power consumption… less colors = darker screen 640x480 resolution = nice big picture… its nice and comortable for long hours…

*note i use zero hardware acceleration
for true safemode when playing runesape
as it is less suspicious to why youd be
using safe mode if your agp is online

Brandon

2013-01-30 10:16:55

From: wantonman
i play runescape in 640x480 256 color mode… just because theres just overall less power consumption… less colors = darker screen 640x480 resolution = nice big picture… its nice and comortable for long hours…

*note i use zero hardware acceleration
for true safemode when playing runesape
as it is less suspicious to why youd be
using safe mode if your agp is online


Hmm.. Power is good, but I wouldn't exactly count it as an advantage.. You'd have to switch graphics mode to 256 colours which affects every thing else.. Unless you can switch it to 256 for a specific application..

Maybe in compatibility mode? But then again, who runs RS in compat mode?