Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
schwittlick committed Jul 6, 2013
1 parent 921cea2 commit 565c0b3
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 44 deletions.
76 changes: 38 additions & 38 deletions src/ofxScreenCapture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,62 +2,61 @@

ofxScreenCapture::ofxScreenCapture(void)
{

hScreen = GetDC(NULL);
ScreenX = GetDeviceCaps(hScreen, HORZRES);
ScreenY = GetDeviceCaps(hScreen, VERTRES);
hdcMem = CreateCompatibleDC (hScreen);
hBitmap = CreateCompatibleBitmap(hScreen, ScreenX, ScreenY);
HGDIOBJ hOld = SelectObject(hdcMem, hBitmap);
BitBlt(hdcMem, 0, 0, ScreenX, ScreenY, hScreen, 0, 0, SRCCOPY);
SelectObject(hdcMem, hOld);
screen_context = GetDC(NULL);
screen_x = GetDeviceCaps(screen_context, HORZRES);
screen_y = GetDeviceCaps(screen_context, VERTRES);
compatible_screen_context = CreateCompatibleDC (screen_context);
screen_bitmap = CreateCompatibleBitmap(screen_context, screen_x, screen_y);
HGDIOBJ hOld = SelectObject(compatible_screen_context, screen_bitmap);
BitBlt(compatible_screen_context, 0, 0, screen_x, screen_y, screen_context, 0, 0, SRCCOPY);
SelectObject(compatible_screen_context, hOld);

bmi;
bmi.biSize = sizeof(BITMAPINFOHEADER);
bmi.biPlanes = 1;
bmi.biBitCount = 32;
bmi.biWidth = ScreenX;
bmi.biHeight = -ScreenY;
bmi.biCompression = BI_RGB;
bmi.biSizeImage = 0;// 3 * ScreenX * ScreenY;
info;
info.biSize = sizeof(BITMAPINFOHEADER);
info.biPlanes = 1;
info.biBitCount = 32;
info.biWidth = screen_x;
info.biHeight = -screen_y;
info.biCompression = BI_RGB;
info.biSizeImage = 0;

pPixels = new RGBQUAD[ScreenX * ScreenY];
screenPixels = new RGBQUAD[screen_x * screen_y];
}


ofxScreenCapture::~ofxScreenCapture(void)
{
delete pPixels;
delete screenPixels;
}

void ofxScreenCapture::update( void )
{
hScreen = GetDC(NULL);
ScreenX = GetDeviceCaps(hScreen, HORZRES);
ScreenY = GetDeviceCaps(hScreen, VERTRES);
hdcMem = CreateCompatibleDC (hScreen);
hBitmap = CreateCompatibleBitmap(hScreen, ScreenX, ScreenY);
HGDIOBJ hOld = SelectObject(hdcMem, hBitmap);
BitBlt(hdcMem, 0, 0, ScreenX, ScreenY, hScreen, 0, 0, SRCCOPY);
SelectObject(hdcMem, hOld);
screen_context = GetDC(NULL);
screen_x = GetDeviceCaps(screen_context, HORZRES);
screen_y = GetDeviceCaps(screen_context, VERTRES);
compatible_screen_context = CreateCompatibleDC (screen_context);
screen_bitmap = CreateCompatibleBitmap(screen_context, screen_x, screen_y);
HGDIOBJ hOld = SelectObject(compatible_screen_context, screen_bitmap);
BitBlt(compatible_screen_context, 0, 0, screen_x, screen_y, screen_context, 0, 0, SRCCOPY);
SelectObject(compatible_screen_context, hOld);

GetDIBits(hdcMem, hBitmap, 0, ScreenY, pPixels, (BITMAPINFO*)&bmi, DIB_RGB_COLORS);
ReleaseDC(NULL,hScreen);
DeleteDC(hdcMem);
GetDIBits(compatible_screen_context, screen_bitmap, 0, screen_y, screenPixels, (BITMAPINFO*)&info, DIB_RGB_COLORS);
ReleaseDC(NULL,screen_context);
DeleteDC(compatible_screen_context);

}

void ofxScreenCapture::getImage( ofImage& im )
{
im.allocate(ScreenX, ScreenY, OF_IMAGE_COLOR_ALPHA);
im.allocate(screen_x, screen_y, OF_IMAGE_COLOR_ALPHA);

for(int y = 0; y < ScreenY; ++y )
for(int y = 0; y < screen_y; ++y )
{
for( int x = 0; x < ScreenX; ++x )
for( int x = 0; x < screen_x; ++x )
{
int index = y * ScreenX + x;
int index = y * screen_x + x;

RGBQUAD p = pPixels[index];
RGBQUAD p = screenPixels[index];
int r = p.rgbRed;
int g = p.rgbGreen;
int b = p.rgbBlue;
Expand Down Expand Up @@ -88,9 +87,10 @@ bool ofxScreenCapture::equals( ofImage* first, ofImage* second )
for (int x = 0; x < first->getWidth(); ++x )
{
int index = y * first->getWidth() + x;
int *firstColor = (int*)(&first_image_pixelsref_array[index]);
int *secondColor = (int*)(&second_image_pixelsref_array[index]);
if(&firstColor != &secondColor )
int firstColor = first_image_pixelsref_array[index];
int secondColor = second_image_pixelsref_array[index];

if(firstColor != secondColor )
{
ret = false;
}
Expand Down
15 changes: 9 additions & 6 deletions src/ofxScreenCapture.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <olectl.h>
#include "ofMain.h"
#include <time.h>
#include <omp.h>

/*
* author: marcel schwittlick (mrzl)
Expand All @@ -22,12 +23,14 @@ class ofxScreenCapture
void update( void );
void getImage( ofImage& im ); // benchmarked: ~70-80ms for 1920x1080

bool equals( ofImage* first, ofImage* second ); // utility to compare two ofimages

private:
RGBQUAD *pPixels;
int ScreenX, ScreenY;
HDC hdcMem;
HBITMAP hBitmap;
HDC hScreen;
BITMAPINFOHEADER bmi;
RGBQUAD *screenPixels;
int screen_x, screen_y;
HBITMAP screen_bitmap;
HDC compatible_screen_context;
HDC screen_context;
BITMAPINFOHEADER info;
};

0 comments on commit 565c0b3

Please sign in to comment.