Bitmap: Difference between revisions

938 bytes removed ,  10 months ago
(→‎REXX version 1: Refurbished)
Line 4,557:
 
The image (raster) created was also written to a file   ('''image.PPM''')   to show verification of the image.
<syntaxhighlight lang="rexx">/*REXX program demonstrates how to process/display a simple RGB raster graphics image. */
red/* = 'ff 00 00'x /*a methodsimple to defineRGB a raster graphics red valueimage. */
bluered = 'ff 00 00 ff'x /*" " " " "a method to bluedefine a "red value. */
@. blue = '00 00 ff'x /*' ' ' ' ' blue ' /*define entire @. array to nulls. */
outFN pixel= 'image' /*the filenamedefine ofentire the outputpixel. imagearray PPMto nulls.*/
sWidthoutFN = 500; sHeight= 500 'image' /*the screenfilename widthof the andoutput heightimage inPPM pixels*/
sWidth = 500; sHeight= 500 /*the screen width and height in pixels*/
call RGBfill red /*set the entire image to red. */
Call RGBfill x= 10; y= 40 red /*set pixel's coördinates.the entire image to red. */
call RGBset x,=10; y,=40 blue /*set pixel's coördinates. /*set a pixel (at 10,40) to blue. */
colorCall =RGBset RGBget(x, y) ,blue /*get the color ofset a pixel. (at 10,40) to blue. */
hexV color = c2xRGBget(colorx,y) /*get the color of a pixel. /*get hex value of pixel's color. */
binVhexV = x2bc2x(hexVcolor) /*get " binary " " " hex "value of pixel's color. */
callbinV RGBfill = x2b(hexV) red /* " binary " " " /*set the entire image to" red. */
bin3V = left(binV, 8) substr(binV, 9, 8) right(binV, 8)
hex3Vbin3V = left(hexVbinV, 28) substr(hexVbinV, 39, 28) right(hexVbinV, 28)
bin3Vhex3V = left(binVhexV, 82) substr(binVhexV, 93, 82) right(binVhexV, 82)
xy= '(' || x","y')' /*create a handy─dandy literal for SAY.*/
say xy= '('||x','y')' pixel in binary: ' binV /*show the binary value of 20,50 create a handy-dandy literal for SAY.*/
say Say xy ' pixel in binary: ' bin3V binV /*show again, but with spaces. the binary value of 20,50 */
Say xy ' pixel in binary: ' bin3V /*show again,but with spaces. */
say /*show a blank between binary and hex. */
saySay xy ' pixel in hex: ' hexV /*show again,a butblank in hexadecimal.between bin & hex. */
say Say xy ' pixel in hex: ' hex3V hexV /*show again, but within spaceshexadecimal. */
Say xy ' pixel in hex: ' hex3V /*show again,but with spaces. */
callCall PPMwrite outFN, sWidth, sHeight /*create a PPM (output) file of image. */ */* ◄■■■■■■■■ not part of this task.*/
say /*show a blank. */
/* ?¦¦¦¦¦¦¦¦ not part of this task.*/
say 'The file ' outFN".PPM was created." /*inform user that a file was created. */
exitSay /*show a blank. /*stick a fork in it, we're all done. */
saySay 'The file ' outFN"'.PPM was created."' /*inform user /*inform user that a file was created. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
RGBfill:Exit @.=arg(1); return /*stick a fork in it, we're all done. /*fill image with a color.*/
/*---------------------------------------------------------------------*/
RGBget: parse arg px,py; return @.px.py /*get a pixel's color. */
RGBsetRGBfill: parse pixel.=arg px,py,p$(1); @.px.py=p$; Return return /*set " " " fill image with a color.*/
RGBget: parseParse arg px,py; Return return @pixel.px.py /*get a pixel's color. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
RGBset: Parse arg px,py,psep; pixel.px.py=psep; Return /*set a pixel */
PPMwrite: parse arg oFN, width, height /*obtain output filename, width, height*/
/*---------------------------------------------------------------------*/
oFID= oFN'.PPM'; $='9'x; #=255 /*fileID; separator; max color value.*/
PPMwrite: Parse arg oFN,width,height
call charout oFID, , 1 /*set the position of the file's output*/
oFID= oFN'.PPM' /* fileID call charout oFID,'P6'width || $ || height || $ || # || $ /*write hdr info.*/
sep='9'x; /* separator do j=1 for width*/
maxcol=255 do k=1 for height; /* callmax charoutcolor oFID, @value.j.k */
Call charout oFID,,1 end /*k*/set the position /* ↑ writeof the PPM file, ···'s output*/
Call charout oFID,'P6'width||sep||height||sep||maxcol||sep /* header */
end /*j*/ /* └───────── ··· one pixel at a time.*/
Do i=1 To width
call charout oFID; return /*close the output file just to be safe*/</syntaxhighlight>
Do j=1 To height;
Call charout oFID,pixel.i.j
End
End
callCall charout oFID; return /* close the output file just to be safe */</syntaxhighlight>
Return</syntaxhighlight>
{{out|output}}
<pre>
2,295

edits