Grayscale image: Difference between revisions

Content added Content deleted
(Added 11l)
(Added solution for Action!)
Line 105: Line 105:
254 254 254 31 31 31 254 254 254 254 254 254
254 254 254 31 31 31 254 254 254 254 254 254
254 254 254 31 31 31 254 254 254 254 254 254
254 254 254 31 31 31 254 254 254 254 254 254
</pre>

=={{header|Action!}}==
Part of the solution is available in [http://www.rosettacode.org/wiki/Category:Action!_Bitmap_tools#RGB2GRAY.ACT RGB2GRAY.ACT].
{{libheader|Action! Bitmap tools}}
{{libheader|Action! Tool Kit}}
<lang Action!>INCLUDE "H6:RGB2GRAY.ACT" ;from task Grayscale image

PROC PrintB3(BYTE x)
IF x<10 THEN
Print(" ")
ELSEIF x<100 THEN
Print(" ")
FI
PrintB(x)
RETURN

PROC PrintRgbImage(RgbImage POINTER img)
BYTE x,y
RGB c

FOR y=0 TO img.h-1
DO
FOR x=0 TO img.w-1
DO
GetRgbPixel(img,x,y,c)
Put(32)
PrintB3(c.r) Put(32)
PrintB3(c.g) Put(32)
PrintB3(c.b) Put(32)
OD
PutE()
OD
RETURN

PROC PrintGrayImage(GrayImage POINTER img)
BYTE x,y,c

FOR y=0 TO img.h-1
DO
FOR x=0 TO img.w-1
DO
c=GetGrayPixel(img,x,y)
Put(32)
PrintB3(c)
OD
PutE()
OD
RETURN

PROC Main()
BYTE ARRAY rgbdata=[
0 0 0 0 0 255 0 255 0
255 0 0 0 255 255 255 0 255
255 255 0 255 255 255 31 63 127
63 31 127 127 31 63 127 63 31]
BYTE ARRAY graydata(12)
BYTE width=[3],height=[4],LMARGIN=$52,oldLMARGIN
RgbImage rgbimg
GrayImage grayimg

oldLMARGIN=LMARGIN
LMARGIN=0 ;remove left margin on the screen
Put(125) PutE() ;clear the screen
InitRgbToGray()
InitRgbImage(rgbimg,width,height,rgbdata)
InitGrayImage(grayimg,width,height,graydata)
PrintE("Original RGB image:")
PrintRgbImage(rgbimg) PutE()

RgbToGray(rgbimg,grayimg)
PrintE("RGB to grayscale image:")
PrintGrayImage(grayimg) PutE()

GrayToRgb(grayimg,rgbimg)
PrintE("Grayscale to RGB image:")
PrintRgbImage(rgbimg)

LMARGIN=oldLMARGIN ;restore left margin on the screen
RETURN</lang>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Grayscale_image.png Screenshot from Atari 8-bit computer]
<pre>
Original RGB image:
0 0 0 0 0 255 0 255 0
255 0 0 0 255 255 255 0 255
255 255 0 255 255 255 31 63 127
63 31 127 127 31 63 127 63 31

RGB to grayscale image:
0 18 182
54 201 73
237 255 61
45 54 74

Grayscale to RGB image:
0 0 0 18 18 18 182 182 182
54 54 54 201 201 201 73 73 73
237 237 237 255 255 255 61 61 61
45 45 45 54 54 54 74 74 74
</pre>
</pre>