Category:Action! Bitmap tools: Difference between revisions
Content added Content deleted
No edit summary |
No edit summary |
||
Line 249: | Line 249: | ||
SetRgbPixel(img,x0+y,y0-x,c) |
SetRgbPixel(img,x0+y,y0-x,c) |
||
SetRgbPixel(img,x0-y,y0-x,c) |
SetRgbPixel(img,x0-y,y0-x,c) |
||
OD |
|||
RETURN |
|||
MODULE</lang> |
|||
---- |
|||
=== RGB2GRAY.ACT === |
|||
The following module is responsible for conversion from RGB color image into grayscale image. |
|||
<lang Action!>MODULE |
|||
INCLUDE "H6:RGBIMAGE.ACT" ;from task Bitmap |
|||
INCLUDE "H6:GRIMAGE.ACT" ;from task Grayscale image |
|||
INCLUDE "D2:REAL.ACT" ;from the Action! Tool Kit |
|||
REAL rFact,gFact,bFact |
|||
PROC InitRgbToGray() |
|||
ValR("0.2126",rFact) |
|||
ValR("0.7152",gFact) |
|||
ValR("0.0722",bFact) |
|||
RETURN |
|||
BYTE FUNC Luminance(RGB POINTER c) |
|||
REAL r1,r2,r3 |
|||
IntToReal(c.r,r1) ;r1=R |
|||
RealMult(rFact,r1,r2) ;r2=0.2126*R |
|||
IntToReal(c.g,r1) ;r1=G |
|||
RealMult(gFact,r1,r3) ;r3=0.7152*G |
|||
RealAdd(r2,r3,r1) ;r1=0.2126*R+0.7152*G |
|||
IntToReal(c.b,r2) ;r2=B |
|||
RealMult(bFact,r2,r3) ;r3=0.0722*B |
|||
RealAdd(r1,r3,r2) ;r2=0.2126*R+0.7152*G+0.0722*B |
|||
RETURN (RealToInt(r2)) |
|||
PROC RgbToGray(RgbImage POINTER src GrayImage POINTER dst) |
|||
BYTE x,y,lum |
|||
RGB c |
|||
FOR y=0 TO dst.h-1 |
|||
DO |
|||
FOR x=0 TO dst.w-1 |
|||
DO |
|||
GetRgbPixel(src,x,y,c) |
|||
lum=Luminance(c) |
|||
SetGrayPixel(dst,x,y,lum) |
|||
OD |
|||
OD |
|||
RETURN |
|||
PROC GrayToRgb(GrayImage POINTER src RgbImage POINTER dst) |
|||
BYTE x,y,lum |
|||
RGB c |
|||
FOR y=0 TO dst.h-1 |
|||
DO |
|||
FOR x=0 TO dst.w-1 |
|||
DO |
|||
lum=GetGrayPixel(src,x,y) |
|||
c.r=lum c.g=lum c.b=lum |
|||
SetRgbPixel(dst,x,y,c) |
|||
OD |
|||
OD |
OD |
||
RETURN |
RETURN |