| WideStudio Programming Guide | WideStudio Index Table of contents

> ## The memory device class

> ### How to create the memory device class

> It is possible to operate the data of the image directly by the memory device class. The memory device has the following facilities.
> - Drawing some pictures on the device.
> - Drawing some images(jpg,bmp) on the device.
> - Direct referencing and direct manipulation of the image data.
> - Transferring of the image data to the window.
> By the sample: ws/sampes/share/memdev/newproject.prj, See the usage of the memory device class. This sample read the image "001.jpg" and indicates it gradually.

> [The sample which indicates the image gradually.]
> This sample does the following.
> - Creates two the memory devices(mdev,mdev2).
> - Draws the image "001.jpg" on mdev.
> - (1)Transfers the data changed brightness up from mdev from mdev2
> - (2)Transfers the data from mdev2 to the window.
> - Loops (1),(2).

>     #include <WScom.h>
>     #include <WSCfunctionList.h>
>     #include <WSCbase.h>
>     //----------------------------------------------------------
>     //Function for the event procedure
>     //----------------------------------------------------------
>     #include <WSDappDev.h>
>     #include <WSCcolorSet.h>
>     #include <WSCimageSet.h>
>     #include <WSCmainWindow.h>
>     extern WSCmainWindow* newwin000;

>     #include <WSDmwindowDev.h>
>     WSDmwindowDev* mdev = NULL;
>     WSDmwindowDev* mdev2 = NULL;

>     void btnep(WSCbase* object){
>       WSDdev* dev = newwin000->getdev(); //A

>       if (mdev == NULL){ //B
>         mdev = WSDmwindowDev::getNewInstance();
>         mdev2 = WSDmwindowDev::getNewInstance();
>       }

>       mdev->createPixmap(200,200); //C
>       mdev->beginDraw(0,0,200,200);  //D
>       WSDimage* image = WSGIappImageSet()->getImage("001.jpg"); //E
>       mdev->drawStretchedImage(0,0,200,200,image); //F
>       mdev->endDraw(); //G

>       mdev2->createPixmap(200,200);  //H

>       mdev->initBuffer();           //I
>       mdev2->initBuffer();          //J

>       long i,x,y;
>       for(i=0;i<100; i++){
>         for(x=0; x<200; x++){
>           for(y=0; y<200; y++){
>             WSCuchar r,g,b;
>             mdev->getBufferRGB(x,y,&r,&g,&b); //K
>             r = (WSCushort)((double)(r*i)/100); //L
>             g = (WSCushort)((double)(g*i)/100); //L
>             b = (WSCushort)((double)(b*i)/100); //L
>             mdev2->setBufferRGB(x,y,r,g,b);     //M
>           }
>         }
>         mdev2->putBufferToPixmap();  //N
>         mdev2->copyToWindow(dev,0,0,200,200,0,0); //P
>       }
>     }
>     static WSCfunctionRegister  op("btnep",(void*)btnep);

> It acquires the window device from the instance at (A) and creates the memory devices at the first click by the method: getNewInstance which creates an appropriate instance(B). It is impossible with new operator to create an instance of the memory device class, because this class depends the window system.
> About indicating the image 001.jpg to mdev1, at first,initialize mdev1 by the method: createPixmap with the geometry (C). To begin draw pictures,call the method: beginDraw() of the device class(D). Acquire the image instance from the global image management class(E) and put the image instance to the memory device(F). If drawing pictures is over,call the method: endDraw().
> Initialize mdev2 too at (H). and initialize the memory buffer for direct operation (I)(J),this time it transfers the internal image data on the frame buffer to the memory buffer. At(K), get the RGB value from mdev1. At(L), increase the brightness of the RGB value and set it to mdev2 (M). It transfers the memory data to the frame buffer(N). and indicates it by transferring to window(P).

Document Release 3.70 for WideStudio ver 3.70, May 2004

WideStudio documents index | Table of contents

Copyright(C) WideStudio Development Team, 1999-2004 | Last modified: May 25, 2004