Showing posts with label stereogram. Show all posts
Showing posts with label stereogram. Show all posts

2008-05-30

Stereogram in AX

Following job demonstrates random dot stereogram technique in AX.

static void RDStechniqueJob(Args _args)
{
        #define.image("C:\\Images\\pattern.bmp")

        #define.imageSizeX(300) // width*2
        #define.imageSizeY(300) // height

        #define.depth(5)

        Form            form;
        FormRun         formRun;
        FormDesign      formDesign;

        Args            args;
        FormBuildDesign formBuildDesign;

        FormBuildWindowControl formBuildWindowControl;
        FormWindowControl pane;

        Image image     = new Image();
        Image pattern   = new Image();
        int     _x, _y;


        void Draw()
        {
            Random  rnd = new Random();
            int     color;
            ;

            for(_x=0; _x<#imageSizeX/2; _x++)
            {
                for(_y=0; _y<#imageSizeY; _y++)
                {
                    color = rnd.nextInt()*0xFF;
                    image.setPixel(_x, _y, color);
                    image.setPixel(_x+#imageSizeX/2, _y, color);
                }
            }
        }

        void CreateStereogram()
        {
            int     color;
            int     d;
            ;

            pattern.loadImage(#image);

            for(_x=0; _x<#imageSizeX/2; _x++)
            {
                for(_y=0; _y<#imageSizeY; _y++)
                {
                    if(!(pattern.getPixel(_x, _y) mod 2))
                    {
                        color = image.getPixel(_x, _y);
                        image.setPixel(_x+#imageSizeX/2-#depth, _y, color);
                    }
                }
            }
        }
        ;

        form = new Form();
        formBuildDesign = form.addDesign('design');
        formBuildDesign.hideToolbar(true);

        formBuildDesign.columns(1);
        formBuildDesign.topMode(1); // Auto
        formBuildDesign.leftMode(1); // Auto
        formBuildDesign.widthMode(1); // Auto
        formBuildDesign.heightMode(1); // Auto
        formBuildDesign.width(1.1*#imageSizeX);

        formBuildWindowControl = formBuildDesign.addControl(FormControlType::IMAGE, 'pane');
        formBuildWindowControl.height(#imageSizeY);
        formBuildWindowControl.width(#imageSizeX);
        formBuildWindowControl.backgroundColor(0);

        args = new Args();
        args.object(form);
        formRun = classFactory.formRunClass(args);
        formRun.init();
        formRun.resetSize();
        formDesign = formRun.design();
        formRun.resetSize();
        formrun.formOnTop();
        formRun.run();


        formRun.design().caption('Random-dot stereogram');
        pane = formRun.control(formBuildWindowControl.id());

        image.saveType(ImageSaveType::BMP_UNCOMP);
        image.createImage(#imageSizeX, #imageSizeY, 24);

        Draw();

        CreateStereogram();
        pane.image(image);

        formRun.wait();
}

Notes:
in this job
- pattern.bmp should be monochrome.
- imageSizeX should be twice more than width of bitmap file.
- depth -- z-axis (depth).

Copyright © 2008 Ruslan Goncharov