Page 1 of 1
Colouring Sprites, with greyscaling? *solved*
Posted: Sun Feb 04, 2007 7:18 am
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.
Posted: Sun Feb 04, 2007 10:21 am
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?
Posted: Sun Feb 04, 2007 11:41 am
by CadeX
Posted: Sun Feb 04, 2007 3:05 pm
by Kaeru Gaman
so what?
I already knew what a Grayscale is.
but what do you want to do?
Posted: Sun Feb 04, 2007 5:41 pm
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)
Posted: Sun Feb 04, 2007 6:26 pm
by Derek
Why not just say "is there anyway to turn a coloured sprite into a grayscale?"
Anyway, nice routine.
Posted: Sun Feb 04, 2007 6:57 pm
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
Posted: Sun Feb 04, 2007 7:21 pm
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|
Posted: Sun Feb 04, 2007 7:27 pm
by Kaeru Gaman
@Comtois
cool.. thanx for the matrix.
...perhaps you could translate YIQ ?
seems to be a francois abkuerzung.
Posted: Sun Feb 04, 2007 10:43 pm
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|
Posted: Mon Feb 05, 2007 12:26 am
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.