PDA

View Full Version : Drawing picture with different RGB



Jonne
15-10-2006, 03:02 PM
Hello.

I got picture, where pixels are "white"
http://pp.kpnet.fi/kmje/ukko.gif

And here, how I'd like to get it drawed.
http://www.netsoccer.biz/screenshot1.gif

So I'd like to get original image drawed with different RGB's
Is there some function in SDL or how it should be done?

tanffn
15-10-2006, 03:20 PM
sure you can, take a look at the game Catapults I made especially at ColorizeImage.

procedure ColorizeImage(var srcImage, destImage: PSDL_Surface;
srcRect, maskRect: TSDL_Rect; Color: UInt32);
var
ObjectOverLayColour, TempImage : PSDL_Surface;
begin
{the remark area is unnecessary IF you select you image carefully}
// Create a surface to hold the negative colour to be subtracted.
ObjectOverLayColour := SDL_CreateRGBSurface( SDL_SWSURFACE, destImage.w, destImage.h,
Screen.format.BitsPerPixel, Screen.format.RMask, Screen.format.GMask,
Screen.format.BMask, Screen.format.AMask );
// Create a temporary working surface.
TempImage := SDL_CreateRGBSurface( SDL_SWSURFACE, destImage.w, destImage.h,
Screen.format.BitsPerPixel, Screen.format.RMask, Screen.format.GMask,
Screen.format.BMask, Screen.format.AMask );
// Make sure that the temp image uses pink as the transparent colour
// SDL_SetColorKey( TempImage, SDL_SRCCOLORKEY or SDL_RLEACCEL or SDL_HWACCEL,
// 0{SDL_MapRGB( ObjectOverLayColour.format, 255, 0, 255 )} );

// Copy the sprite image to our work area
SDL_BlitSurface( srcImage, @srcRect, TempImage, nil);
// SDL_SaveBMP(TempImage, '1.bmp');

// Fill the Colour surface with the appropritate colour
SDL_FillRect( ObjectOverLayColour , nil, Color);
// SDL_SaveBMP(ObjectOverLayColour, '2.bmp');
// Subtract the colour from the work surface
SDL_SubSurface( ObjectOverLayColour, nil, TempImage, nil );
// SDL_SaveBMP(TempImage, '3.bmp');
// Blit our Mask onto the work area. This gets around the colour problem
// SDL_BlitSurface( srcImage, @maskRect, TempImage, nil);

// Make sure that the Image uses pink as the transparent colour
// SDL_SetColorKey( destImage, SDL_SRCCOLORKEY or SDL_RLEACCEL or SDL_HWACCEL,
// SDL_MapRGB( destImage.format, 255, 0, 255 ) );
// Blit the work surface to the Image
// SDL_SetColorKey( TempImage, SDL_SRCCOLORKEY or SDL_RLEACCEL or SDL_HWACCEL,
// 0 );
SDL_BlitSurface( TempImage, nil, destImage, nil );
// SDL_BlitSurface( srcImage, @maskRect, destImage, nil);
SDL_SetColorKey( destImage, SDL_SRCCOLORKEY or SDL_RLEACCEL or SDL_HWACCEL, 0 );

SDL_FreeSurface( TempImage );
SDL_FreeSurface( ObjectOverLayColour );
end;

I see I have a lot of comments in there... you’ll have to play around with it, it should work as it is.

Jonne
16-10-2006, 09:59 PM
Thanks.

I downloaded catapults source and have been "exploring" it for hours, but source seems too confusing to me. :?

Could you give small sample, how that it works?

Christian Knudsen
22-04-2008, 05:11 PM
I'm trying to use the above procedure to color my surfaces, but for some reason I'm getting an error with the 'AsciiMap.Format' part, when trying to set the transparency color of my surface:

VAR AsciiMap : PSDL_Surface;
TempImage : PSDL_Surface;

{...}

TempImage := SDL_LoadBMP('640x400.bmp');
AsciiMap := SDL_DisplayFormat(TempImage);
SDL_SetColorKey(AsciiMap, SDL_SRCCOLORKEY OR SDL_RLEACCEL, SDL_MapRGB(AsciiMap.Format, 255, 0, 255));


I can't figure out what I'm doing wrong. I believe I'm declaring the surfaces correctly.


EDIT: The compile error I'm getting is 'Unexpected identifier "Format"', so it seems there's something wrong with my AsciiMap surface - maybe I haven't declared it correctly? Any help would be appreciated!

Christian Knudsen
23-04-2008, 04:04 PM
A correction: The compiler error message I'm getting is:

Syntax error, ")" expected but "identifier FORMAT" found

waran
23-04-2008, 07:23 PM
AsciiMap is a pointer (hence the "P"). So

AsciiMap^.format
is what you want, actually.

Christian Knudsen
24-04-2008, 05:56 AM
Argh, of course! Such a simple mistake! Thanks! :D