This document explains a fast way to get the data from an RGSS bitmap object,
which I have discovered.
Internally, RGSS bitmaps are stored as Windows bitmap data.
Using a Win32 DLL, it is possible to retrieve this data's internal
structure with the help of a little known trick using the Ruby object's ID:
Ruby code follows illustrating this technique with a hypothetical DLL "mydll.dll"
and a hypothetical function "MyFunction".
-
- o=Bitmap.new(10,10)
- function=Win32API.new("mydll.dll","MyFunction","l","")
- # Pass the object's ID to the function
- function.call(o.__id__)
-
Expand to see the code.
Having retrieved the object's ID, the DLL function can shift the ID left by 1 to get
a pointer to the object's internal data structure. C code follows illustrating
the technique.
-
- void __declspec(dllexport) __stdcall MyFunction(unsigned long object){
- RGSSBITMAP *data=(RGSSBITMAP *)(object<<1);
- // Process data pointer here...
- }
-
Expand to see the code.
In this case, the ID for a bitmap refers to the Ruby structure for
arbitrary data. This structure points to a bitmap structure, which in
turn points to the actual information on the bitmap. All three structures
are defined below. (The code below is in C.)
-
- #include <windows.h>
-
- // Actual bitmap info
- typedef struct{
- DWORD unk1;
- DWORD unk2;
- BITMAPINFOHEADER *infoheader;
- // First row of the bitmap, rows
- // are stored in descending order
- RGBQUAD *firstRow;
- // Last row of the bitmap
- RGBQUAD *lastRow;
- } RGSSBMINFO;
-
- // Bitmap data
- typedef struct{
- DWORD unk1;
- DWORD unk2;
- RGSSBMINFO *bminfo;
- } BITMAPSTRUCT;
-
- // Ruby data structure
- typedef struct{
- DWORD flags;
- DWORD klass;
- void (*dmark)(void*);
- void (*dfree)(void*);
- BITMAPSTRUCT *bm;
- } RGSSBITMAP;
-
Expand to see the code.
Using this knowledge, the DLL function can process the bitmap however it
wants. For example, it can save the bitmap, retrieve a whole row of it,
perform a complex effect on it, and so on.
I'm not sure whether this thread is appropriate here, but
this information may be known by no one until now.
A demo for the bitmap effects used to be here, but the link is now broken.