Colouring Sprites, with greyscaling? *solved*

Advanced game related topics
CadeX
Enthusiast
Enthusiast
Posts: 124
Joined: Mon Oct 02, 2006 2:56 pm
Location: Australia
Contact:

Colouring Sprites, with greyscaling? *solved*

Post by CadeX »

Hi guys, as far as i've looked i havent been able to find anything to do with grayscale + RGB colouring, has anyone else found a way to do this or did i miss something in the manual/search?

Sorry to be a bother.
Last edited by CadeX on Mon Feb 05, 2007 12:27 am, edited 1 time in total.
Pro-Gamer, Programmer, Pro-Grammer
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

please try to explain a bit clearer.

you can plot single dots on a sprite, each with it's own color.

you can use 256col-mode having a palette of colors,
and you can manipulate the colors.

color modes of a screen are the standard ones: 16col, 256col (= 8bit), 16bit,(24bit) 32bit

a gray color is always achieved when each color channel, red green and blue, have the save value.

so, what exacly is what you are looking for?
oh... and have a nice day.
CadeX
Enthusiast
Enthusiast
Posts: 124
Joined: Mon Oct 02, 2006 2:56 pm
Location: Australia
Contact:

Post by CadeX »

Pro-Gamer, Programmer, Pro-Grammer
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

so what?

I already knew what a Grayscale is.

but what do you want to do?
oh... and have a nice day.
User avatar
Fluid Byte
Addict
Addict
Posts: 2336
Joined: Fri Jul 21, 2006 4:41 am
Location: Berlin, Germany

Post by Fluid Byte »

I guess he wants something like this:

Code: Select all

Procedure GraySprite(SpriteNUM.w)
    StartDrawing(SpriteOutput(SpriteNUM))
    
    IW = SpriteWidth(SpriteNUM)
    IH = SpriteHeight(SpriteNUM)
    
    BufferPitch = DrawingBufferPitch() / SizeOf(LONG)

    If IW <> BufferPitch : IW = BufferPitch : EndIf
           
    *pxData.LONG = DrawingBuffer()
    
    For i=1 To (IW * IH)     
        R = Blue(*pxData\l)
        G = Green(*pxData\l)
        B = Red(*pxData\l)
 
		Average =(R + G + B)/3
		
		*pxData\l = RGB(Average,Average,Average) 				
		
		*pxData + 4
    Next
    
    StopDrawing()
EndProcedure

InitSprite() : InitKeyboard()

OpenScreen(640,480,32,"untitled")

CreateSprite(0,240,240)

StartDrawing(SpriteOutput(0))
For i=0 To 240-1
	CV = (i * 255) / (240-1)
	
	Box(0,i,240,1,RGB(255,CV,0))
Next
StopDrawing()

CopySprite(0,1) : GraySprite(1)

Repeat	
	ExamineKeyboard()
	
	ClearScreen(0)
	DisplaySprite(0,40,50)
	DisplaySprite(1,320,50)
	FlipBuffers()
	
Until KeyboardPushed(1)
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
Derek
Addict
Addict
Posts: 2354
Joined: Wed Apr 07, 2004 12:51 am
Location: England

Post by Derek »

Why not just say "is there anyway to turn a coloured sprite into a grayscale?"

Anyway, nice routine.
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

> Why not just say "is there anyway to turn a coloured sprite into a grayscale?"

yep, that's what I meant.

I see no use in covering people with codes who cannot even ask questions....


btw:
@Fluid

(R+G+B)/3 isn't the correct formula, you'll have to take the different lucency of the canals into account....

here is a proc by Olaf from the german forum that uses the correct factors:

Code: Select all

Global lumared.d=0.299,lumagreen.d=0.587,lumablue.d=0.114
Procedure Luma(color) 
  y=Int(lumared*Red(color)+lumagreen*Green(color)+lumablue*Blue(color)) 
  ProcedureReturn y 
EndProcedure 
oh... and have a nice day.
User avatar
Comtois
Addict
Addict
Posts: 1431
Joined: Tue Aug 19, 2003 11:36 am
Location: Doubs - France

Post by Comtois »

Kaeru Gaman wrote:@Fluid

(R+G+B)/3 isn't the correct formula, you'll have to take the different lucency of the canals into account....

here is a proc by Olaf from the german forum that uses the correct factors:

Code: Select all

Global lumared.d=0.299,lumagreen.d=0.587,lumablue.d=0.114
Procedure Luma(color) 
  y=Int(lumared*Red(color)+lumagreen*Green(color)+lumablue*Blue(color)) 
  ProcedureReturn y 
EndProcedure 
System YIQ

Code: Select all

|Y|    |0.299   0.587   0.114|   |R|
|I| =  |0.596  -0.275  -0.321| * |G|
|Q|    |0.212  -0.523  -0.311|   |B|
Please correct my english
http://purebasic.developpez.com/
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

@Comtois

cool.. thanx for the matrix. :D

...perhaps you could translate YIQ ?
seems to be a francois abkuerzung.
oh... and have a nice day.
User avatar
Comtois
Addict
Addict
Posts: 1431
Joined: Tue Aug 19, 2003 11:36 am
Location: Doubs - France

Post by Comtois »

The french one is YDbDr

Code: Select all

|Y |    | 0.299   0.587  0.114|   |R|
|Db| =  |-0.450  -0.883  1.333| * |G|
|Dr|    |-1.333   1.116  0.217|   |B|
Please correct my english
http://purebasic.developpez.com/
CadeX
Enthusiast
Enthusiast
Posts: 124
Joined: Mon Oct 02, 2006 2:56 pm
Location: Australia
Contact:

Post by CadeX »

Sorry guys, had a bad cold for the last week and i can't really think straight. Fluid knows exactly what i'm after, thanks a ton.
Pro-Gamer, Programmer, Pro-Grammer
Post Reply