.
.
.
.
.
.
.
.
.
.
.
.
.
.typeof win = ObjWin;;
.typeof bmp = ObjBitmap;;
.typeof bmpSrc = ObjBitmap;;
.typeof combo = ObjBox;;
.typeof shader = ObjText;;
.
.proto makeGray = fun [I I I I I I] I;;
.proto copyBmp = fun [] I;;
.
.
.fun destroy (o, u)=
. _DSbitmap bmp;
. _DSbitmap bmpSrc;
. _closemachine;;
.
.
.fun paint (o, u)=
. _BLTbitmap win bmp 5 5;
. 0;;
.
.
.fun choice (o, u, iChoice, szChoice)=
. if iChoice == 10 then
. _ENtext shader 1
. else
. _ENtext shader 0;
. 0;;
.
.
.fun apply (o, u)=
. copyBmp;
. let _GETcombo combo -> [iAlgo _] in
. let _GETbitmapSize bmp -> [w h] in
. makeGray iAlgo w h atoi _GETtext shader 0 0;
. _PAINTwindow win;
. 0;;
.
.fun savebmp (o, u, w)=
. _SAVEjpeg bmp w 90;
. 0;;
.
.
.fun save (o, u)=
. _DLGrflsave
. _DLGSaveFile _channel win "" "" "jpeg\0*.jpg\0\0"
. @savebmp
. 0;
. 0;;
.
.
.fun reset (o, u)=
. copyBmp;
. _PAINTwindow win;
. 0;;
.
.
.fun main ()=
. _showconsole;
.
. set win = _CRwindow _channel nil 100 50 800 810 WN_NORMAL "Grayscale";
. set bmpSrc = _LDjpeg _channel _checkpack "lib/examples/2d/rscs/fleurs.jpg";
. set bmp = _CRbitmap _channel 600 800;
. copyBmp;
.
. _CRtext _channel win 610 5 180 20 0 "Choose an algorithm :";
.
. set combo = _CRcombo _channel win 610 30 180 220 CB_NOEDIT|CB_DOWN "Average";
. _ADDcombo combo 0 "Average";
. _ADDcombo combo 1 "Human eye A";
. _ADDcombo combo 2 "Human eye B";
. _ADDcombo combo 3 "Human eye C";
. _ADDcombo combo 4 "Desaturation";
. _ADDcombo combo 5 "Decomposition Maximum";
. _ADDcombo combo 6 "Decomposition Minimum";
. _ADDcombo combo 7 "Single gray channel RED";
. _ADDcombo combo 8 "Single gray channel GREEN";
. _ADDcombo combo 9 "Single gray channel BLUE";
. _ADDcombo combo 10 "Custom shaders";
. _SELcombo combo 0;
.
. _CRtext _channel win 610 675 180 20 0 "Set the shaders number :";
. set shader = _CReditLine _channel win 610 700 180 20 ET_DOWN|ET_NUMBER "16";
. _ENtext shader 0;
.
. _CBbutton
. _CRbutton _channel win 610 725 180 20 0 "Apply"
. @apply
. 0;
. _CBbutton
. _CRbutton _channel win 610 750 180 20 0 "Save"
. @save
. 0;
. _CBbutton
. _CRbutton _channel win 610 775 180 20 0 "Reset"
. @reset
. 0;
.
. _CBwinPaint win @paint 0;
. _CBwinDestroy win @destroy 0;
. _CBcombo combo @choice 0;
. _PAINTwindow win;
.
. 0;;
.
.
.fun makeGray (iAlgo, w, h, iShader, line, col)=
. if (line >= h) || ((col >= w) && (h <= line+1)) then
. 0
. else
. (
. if col >= w then
. (
. set col = 0;
. ++line
. );
. let _GETpixel24 bmp col line -> c in
. else [0 0 0]
. -> [a a a] in
. makeGray iAlgo w h iShader line col+1
. );;
.
.
.fun copyBmp ()=
. _CPbitmap24 bmp 0 0 bmpSrc 0 0 600 800 nil;
. 0;;