Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Returning an array or string using C++

Hi,

I'm trying to write a function in C++ that goes through all pixels in a bitmap and returns the x,y, and RGBA value of all these pixels. The problem is, I don't know what and how to return the result.

I want to use the returned value in Ruby.

Here's what I have right now:
Code:
 

extern "C" _declspec (dllexport) BOOL GetMappedPixels(long object){

    RGSSBMINFO *bitmap = ((RGSSBITMAP*) (object<<1)) -> bm -> bminfo;

    DWORD rowsize;

    DWORD width, height;

    LPBYTE row;

 

    // *********************

    // my string or array variable?

 

    long x, y;

 

    if(!bitmap) return false;

    width = bitmap -> infoheader -> biWidth;

    height = bitmap -> infoheader -> biHeight;

    rowsize = width * 4;

 

    row = (LPBYTE) (bitmap -> firstRow);

    for ( y = 0; y < (int) height; y++) {

        LPBYTE thisrow = row;

        for ( x = 0; x < (int) width; x++) {

 

            // *************************

            // add xyrgba values to my string or array?

 

            thisrow += 4;

        }

        row -= rowsize;

    }

    return colors;

}

 

The goal behind this is to create a palette system. The code above would gather all pixels in the bitmap and once I have this information back in Ruby, I want to assign an index to each color and map the index to the x/y values returned by the code above.

So, how can I do that?

Thanks in advance.
- Dargor
 
If my understanding is correct, you will need to return a pointer to the data ('p' as the fourth Win32API argument). You might need to store it in a C string instead of a C array, but it's not too hard to convert a Ruby string to a Ruby array once you have it.
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top