#include "dib.h"

void __fastcall TDib::Create (){
  	hdc = CreateCompatibleDC (NULL);
    BITMAPINFO vscreeninfo;
    vscreeninfo.bmiHeader.biSize = sizeof vscreeninfo.bmiHeader;
    vscreeninfo.bmiHeader.biWidth = xres;
    vscreeninfo.bmiHeader.biHeight = -yres;
    vscreeninfo.bmiHeader.biPlanes = 1;
    vscreeninfo.bmiHeader.biBitCount = 32;
    vscreeninfo.bmiHeader.biCompression = BI_RGB;
    vscreeninfo.bmiHeader.biSizeImage = xres*yres*4;
    vscreeninfo.bmiHeader.biXPelsPerMeter = 0;
   	vscreeninfo.bmiHeader.biYPelsPerMeter = 0;
   	vscreeninfo.bmiHeader.biClrUsed = 0;
   	vscreeninfo.bmiHeader.biClrImportant = 0;
    void *vscreentemp;
   	vscreen_r = CreateDIBSection (hdc,&vscreeninfo,DIB_RGB_COLORS,(void**)&vscreentemp,NULL,0);
    vscreen = (int *)vscreentemp;
   	SelectObject (hdc,vscreen_r);
}

void __fastcall TDib::Destroy (){
	DeleteObject (vscreen_r);
    DeleteDC (hdc);
    hdc = NULL;
    vscreen_r = NULL;
}

TDib::~TDib(){
	Destroy ();
}

TDib::TDib(int w, int h){
	xres = w;
    yres = h;
    Create ();
}
