Advertisement

using AngelCode for image processing?

Started by June 21, 2012 01:06 PM
1 comment, last by WitchLord 12 years, 5 months ago
Hi there,
I am thinking of using AngelCode to extend my image processing library for quickly testing out algorithms.
Right now I have in my C++ code a 1D array of size (image_width*image_height) with RGBA data for each pixel (either as byte or float).
Now I could of course loop over this array in my C++ code and call a AngelCode function c=Process(x,y,r,g,b,a) for each pixel, but that would be rather slow for large images.
Is it also possible to assign the initial C++ array directly to a AngelCode variable so that I can then access individual array values from AngelCode - without copying the whole array first to a temporary AngelCode aware-type of array?
Thanks in advance for any helpful insights here!

Mike
you dont need too create script side array to access in runtime.

just register
void Set(uint index);
Colour Get(uint index);
functions.
leave the array inside c++


a second way:

if your array is std::vector you can register it and expose you vector as a global property i think.

check this thread
http://www.gamedev.net/topic/583414-stdvector-registration/page__hl__%2Bstd+%2Bvector+%2Bregister
Advertisement
Yes, you can definitely expose the original array without the need to copy it. There are many different ways of doing it, and it will mostly depend on how you want the script to look like.

One suggestion is to create a simple wrapper class, that provides the interface for how you wish to expose the array.


struct SColour
{
float a,r,g,b;
void Construct(float ia, float ir, float ig, float ib) { a = ia; r = ir; g = ig; b = ib; }
};

class CImage
{
public:
float *imageBuffer; // This pointer will point to the real image 1D array
int width;
int height;

SColor &pixel(int x, int y); // This method returns a reference to the pixel in the array
};

void Register( asIScriptEngine *engine )
{
engine->RegisterObjectType("colour", sizeof(SColour), asOBJ_VALUE | asOBJ_POD | asOBJ_APP_CLASS); // Plain old data structure
engine->RegisterObjectBehaviour("colour", "void f(float, float, float, float)", asMETHOD(SColour, Construct), asCALL_THISCALL);
engine->RegisterObjectProperty("colour", "float a", asOFFSET(SColour, a));
engine->RegisterObjectProperty("colour", "float r", asOFFSET(SColour, r));
engine->RegisterObjectProperty("colour", "float g", asOFFSET(SColour, g));
engine->RegisterObjectProperty("colour", "float b", asOFFSET(SColour, b));

engine->RegisterObjectType("image", sizeof(CImage), asOBJ_REF | asOBJ_NOCOUNT); // Reference type, but we don't care about reference counts
engine->RegisterObjectProperty("image", "int width", asOFFSET(CImage, width));
engine->RegisterObjectProperty("image', "int height", asOFFSET(CImage, height));
engine->RegisterObjectMethod("image", "colour &pixel(int, int)", asMETHOD(CImage, pixel), asCALL_THISCALL);
}


With this the script would be able to work with the image like this:


void Process(image @img)
{
for( int y = 0; y < img.height; y++ )
for( int x = 0; x < img.width; x++ )
img.pixel(x, y) = colour(0,0,0,0);
}


It's not a complete example, but it should give you an idea of how you can do it.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

This topic is closed to new replies.

Advertisement