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

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

void btnep(WSCbase* object){
  WSDdev* dev = newwin000->getdev();
  if (mdev == NULL){
    mdev = WSDmwindowDev::getNewInstance();
    mdev2 = WSDmwindowDev::getNewInstance();
  } 
  mdev->createPixmap(200,200);
  mdev->beginDraw(0,0,200,200);
  WSDimage* image = WSGIappImageSet()->getImage("001.jpg");
  if (image->getValue1() == -1 ){
    WSCstring str;
    str << "File: 001.jpg not found.";
    WSGIappMessageDialog()->setProperty(WSNwidth,600);
    WSGIappMessageDialog()->setProperty(WSNlabelString,(char*)str);
    WSGIappMessageDialog()->popup();
    return;
  }
  mdev->drawStretchedImage(0,0,200,200,image);
  mdev->endDraw();

  mdev2->createPixmap(200,200);

  mdev->initBuffer();
  mdev2->initBuffer();

  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);
        r = (WSCushort)((double)(r*i)/100);
        g = (WSCushort)((double)(g*i)/100);
        b = (WSCushort)((double)(b*i)/100);
        mdev2->setBufferRGB(x,y,r,g,b);
      }
    }
    mdev2->putBufferToPixmap();
    mdev2->copyToWindow(dev,0,0,200,200,0,0);
  }
}
static WSCfunctionRegister  op("btnep",(void*)btnep);
