Welcome Guest ( Log In | Register )

[ Big| Medium| Small] -



Post new topic Reply to topic  [ 14 posts ] 
    poccil
  Thu Feb 14, 2008 6:35 pm
Sponsor

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".

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.

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.)

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.

_________________
Peter O.
Multiple Tilesets Discussion


Last edited by poccil on Sun Aug 06, 2017 6:34 pm, edited 2 times in total.

Top Top
Profile      
 

    poccil
  Sun Feb 17, 2008 10:20 am
Sponsor

I have updated the bitmap effects demo today with some more effects, including all new effects from RGSS 2's Bitmap class.

_________________
Peter O.
Multiple Tilesets Discussion


Top Top
Profile      
 

    linkz0r
  Tue Feb 19, 2008 4:58 am
User avatar
Member

Where have you got all this info?

EDIT: Have i said this is the most damn interesting thread in all the forums? :D

_________________

http://img301.imageshack.us/img301/4022/rmxppro2gh.png[/img]



Umm... lol?


I *REALLY* miss the *old* Pencil Contest... -_-
Check it! My dA! xD


Last edited by linkz0r on Tue Feb 19, 2008 5:04 am, edited 1 time in total.

Top Top
Profile      
 

    khmp
  Tue Feb 19, 2008 5:46 pm
The glass is helpful.
User avatar
Sponsor


Location: Haddonfield, NJ
I know this sounds forward of me but can I have your babies? I had absolutely no idea left shifting the __id__ by 1 reveals the pointer to a Ruby object's data. I assume this is true for all Ruby objects then as well not just bitmaps? Very cool. Did you stumble upon that by yourself or happen to see it elsewhere? Modifying the bitmap data directly through C/C++ code like this was the very first question I had when I came here.

_________________


Top Top
Profile      
 

    poccil
  Tue Feb 19, 2008 6:04 pm
Sponsor

Thanks for asking.  I recently discovered that possibility by myself when I posted this topic.  I encourage users to try this technique.

_________________
Peter O.
Multiple Tilesets Discussion


Top Top
Profile      
 

    vgvgf
  Tue Feb 19, 2008 8:20 pm
User avatar


This is one of the greatest ideas I have ever heard for enhancing RMXP. Great discovery!
This can be revolutionary for RMXP, and maybe can be useful for anothers objects types.

_________________
Pseudo-Retired due to lack of time. Lack of time causes: working, studing.


Top Top
Profile      
 

    xpace
  Tue Feb 19, 2008 11:06 pm
User avatar
Member


Location: Missouri, USA
Wow! Very cool discovery!  :thumb:

I have one question:

Is the framerate of the bitmap demo being limited by a software limitation (such as RGSS)? Or did you put some sort of throttle in so it would only move the bitmaps slowly?

C/C++ code usually runs very fast. If that is as fast as it can display the bitmaps, then I think the usefulness of this technique might also be limited...  :sad:

_________________
"Single acts of tyranny may be ascribed to the accidental opinion of a day, but a series of oppressions, begun at a distinguished period, unalterable through every change of ministers, too plainly prove a deliberate, systematical plan of reducing us to slavery." -- Thomas Jefferson


Top Top
Profile      
 

    poccil
  Tue Feb 19, 2008 11:29 pm
Sponsor

No, it's just that the operation demonstrated, a radial blur, is a relatively time-intensive operation
compared with other bitmap effects, such as applying a gradient fill.  It would be considerably slower
using RGSS's set_pixel and get_pixel methods.

_________________
Peter O.
Multiple Tilesets Discussion


Top Top
Profile      
 

    xpace
  Wed Feb 20, 2008 10:22 am
User avatar
Member


Location: Missouri, USA
Does this bitmap demo use the RMXP window handle as a render target?

_________________
"Single acts of tyranny may be ascribed to the accidental opinion of a day, but a series of oppressions, begun at a distinguished period, unalterable through every change of ministers, too plainly prove a deliberate, systematical plan of reducing us to slavery." -- Thomas Jefferson


Top Top
Profile      
 

    poccil
  Wed Feb 20, 2008 12:30 pm
Sponsor

What the demo does is modify the bitmaps passed to it by their object IDs.  (In RGSS, graphics are drawn using sprites, which each hold bitmap objects.)  The technique doesn't need to know the RGSS player's window handle in order to do so.  The RGSS player then draws the modified bitmaps in the usual way.

_________________
Peter O.
Multiple Tilesets Discussion


Top Top
Profile      
 

    verballydecapitating
  Wed Feb 20, 2008 1:04 pm
Member

Any way to call a managed dll? (A .NET one)

EDIT: This rocks by the way. Might make my own functions and such, what did you use to compile?


Top Top
Profile      
 

    linkz0r
  Fri Feb 22, 2008 12:40 am
User avatar
Member

From what i could see, he just found a way to take out data from the interpreter and use it within external methods/functions from inside the interpterer itself. This way, he took bitmaps' data and used an external tool to modify it. Maybe it´d be possible to modify things with a managed DLL, but you´d need to describe the bitmap data in the language you use in such way it´d fit perfectly in the way it´s described in the C source code provided by poccil. If not, make some kind of interface that works byte-by-byte. But either way, i wonder if it´d be possible to actually call managed language's DLL calls from inside the RGSS with Win32API, as i´m only aware of that C/C++ are supported.

To compile it, i guess any regular compile should do. Borland, VC, Mingw... I personally recommend getting the VC compiler, as it generates smaller DLLs compared to any other compilers. If you don´t want to use it, Mingw is a good option too.

BTW that ID thing discovery was brilliant lol i wonder where you got that info :D
BTW2, i wonder why shifting the pointer by one bit anyway... What´d be the advantage of making it? Randomizing IDs?
BTW3, i see some GDI structs there. If they´re not meant to be only binary-compatible with some other data struct, this could explain why RMXP games are rather slow for such small work :)

_________________

http://img301.imageshack.us/img301/4022/rmxppro2gh.png[/img]



Umm... lol?


I *REALLY* miss the *old* Pencil Contest... -_-
Check it! My dA! xD


Last edited by linkz0r on Fri Feb 22, 2008 12:53 am, edited 1 time in total.

Top Top
Profile      
 

    verballydecapitating
  Fri Feb 22, 2008 9:26 am
Member

I made a C++ wrapper to my C# code and got some simple functions going like inverting bitmaps and such. Thanks a lot for the example code it helped immensely.


Top Top
Profile      
 

    Dargor
  Fri Feb 22, 2008 2:54 pm
User avatar
Retired Staff

Party Mascot

Location: Quebec / Canada
I - LOVE - YOU

lol really, I'm amazed. I've tried so many times to do something like that but RGSS was far too slow. If I can do a masking effect with that, this script is going straight into my FFVI SDK! (Along with your tilemap script ;))

One question: Is it possible for me to add custom effects without having to code them in C? If no then I guess it's time for me to learn C.

Once again, good work poccil!

Take care!
-Dargor

_________________
Final Fantasy VI SDK
Image

Stay in touch, ask me anything, receive updates and try out the lastest versions!

Image Image Image Image Image

Tutorials


Top Top
Profile      
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 14 posts ] 


Who is online

Users browsing this forum: No users and 11 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

cron
We are an independent, not-for-profit game making community.
Homepage
Board Index
About Us
Downloadable Games
Free Browser Games
Games in Development
RPG Maker Support
Game Maker Support
Construct 2 Support
HBGames the eZine
Advanced RPG Maker
Site Announcements
Powered by phpBB © phpBB Group