Last active
October 23, 2024 13:14
-
-
Save prashanthrajagopal/05f8ad157ece964d8c4d to your computer and use it in GitHub Desktop.
Revisions
-
prashanthrajagopal revised this gist
Jun 18, 2014 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -71,13 +71,13 @@ void gdiscreen() { int main() { clock_t t1 = clock(); int i; int iterations = 10; for(i=0;i<iterations;i++){ gdiscreen(); } clock_t t2 = clock(); printf("%d iterations: %0.0f fps\n", iterations, iterations/((double)(t2 - t1) / CLOCKS_PER_SEC)); return 0; } -
prashanthrajagopal revised this gist
Jun 18, 2014 . 1 changed file with 13 additions and 9 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -34,9 +34,8 @@ int GetEncoderClsid(const WCHAR* format, CLSID* pClsid) { void gdiscreen() { using namespace Gdiplus; IStream* istream; HRESULT res = CreateStreamOnHGlobal(NULL, true, &istream); GdiplusStartupInput gdiplusStartupInput; ULONG_PTR gdiplusToken; GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL); @@ -54,9 +53,15 @@ void gdiscreen() { Gdiplus::Bitmap bitmap(membit, NULL); CLSID clsid; GetEncoderClsid(L"image/jpeg", &clsid); // bitmap.Save(L"screen.jpeg", &clsid, NULL); // To save the jpeg to a file bitmap.Save(istream, &clsid, NULL); // Create a bitmap from the stream and save it to make sure the stream has the image // Gdiplus::Bitmap bmp(istream, NULL); // bmp.Save(L"t1est.jpeg", &clsid, NULL); // END delete &clsid; DeleteObject(memdc); DeleteObject(membit); ::ReleaseDC(0,scrdc); @@ -66,10 +71,9 @@ void gdiscreen() { int main() { clock_t t1 = clock(); int i; int iterations = 10; for(i=0;i<iterations;i++){ gdiscreen(); } -
prashanthrajagopal revised this gist
Jun 18, 2014 . 1 changed file with 20 additions and 9 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,9 +1,9 @@ #include <stdio.h> #include <windows.h> #include <gdiplus.h> #include <time.h> int GetEncoderClsid(const WCHAR* format, CLSID* pClsid) { using namespace Gdiplus; UINT num = 0; UINT size = 0; @@ -32,9 +32,11 @@ int GetEncoderClsid(const WCHAR* format, CLSID* pClsid) return 0; } void gdiscreen() { using namespace Gdiplus; LPSTREAM lpstream; // HRESULT res; // res = CreateStreamOnHGlobal(NULL, true, &lpstream); GdiplusStartupInput gdiplusStartupInput; ULONG_PTR gdiplusToken; GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL); @@ -48,12 +50,12 @@ void gdiscreen() membit = CreateCompatibleBitmap(scrdc, Width, Height); HBITMAP hOldBitmap =(HBITMAP) SelectObject(memdc, membit); BitBlt(memdc, 0, 0, Width, Height, scrdc, 0, 0, SRCCOPY); Gdiplus::Bitmap bitmap(membit, NULL); CLSID clsid; GetEncoderClsid(L"image/jpeg", &clsid); // bitmap.Save(L"screen.jpeg", &clsid, NULL); bitmap.Save(lpstream, &clsid, NULL); DeleteObject(memdc); DeleteObject(membit); @@ -64,5 +66,14 @@ void gdiscreen() int main() { LPSTREAM jStream; clock_t t1 = clock(); int i; int iterations = 100; for(i=0;i<iterations;i++){ gdiscreen(); } clock_t t2 = clock(); printf("%d iterations: %0.0f fps\n", iterations, iterations/((double)(t2 - t1) / CLOCKS_PER_SEC)); return 0; } -
prashanthrajagopal revised this gist
Jun 18, 2014 . 1 changed file with 1 addition and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -64,8 +64,5 @@ void gdiscreen() int main() { gdiscreen(); } -
prashanthrajagopal revised this gist
Jun 18, 2014 . 1 changed file with 6 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -52,7 +52,8 @@ void gdiscreen() Gdiplus::Bitmap bitmap(membit, NULL); CLSID clsid; GetEncoderClsid(L"image/jpeg", &clsid); // bitmap.Save(L"screen.jpeg", &clsid, NULL); DeleteObject(memdc); DeleteObject(membit); @@ -63,5 +64,8 @@ void gdiscreen() int main() { int i; for(i=0;i<1000;i++){ gdiscreen(); } } -
prashanthrajagopal revised this gist
Jun 17, 2014 . 1 changed file with 55 additions and 56 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,68 +1,67 @@ #include <stdio.h> #include <windows.h> #include <gdiplus/gdiplus.h> int GetEncoderClsid(const WCHAR* format, CLSID* pClsid) { using namespace Gdiplus; UINT num = 0; UINT size = 0; ImageCodecInfo* pImageCodecInfo = NULL; GetImageEncodersSize(&num, &size); if(size == 0) return -1; pImageCodecInfo = (ImageCodecInfo*)(malloc(size)); if(pImageCodecInfo == NULL) return -1; GetImageEncoders(num, size, pImageCodecInfo); for(UINT j = 0; j < num; ++j) { if( wcscmp(pImageCodecInfo[j].MimeType, format) == 0 ) { *pClsid = pImageCodecInfo[j].Clsid; free(pImageCodecInfo); return j; } } free(pImageCodecInfo); return 0; } void gdiscreen() { using namespace Gdiplus; GdiplusStartupInput gdiplusStartupInput; ULONG_PTR gdiplusToken; GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL); { HDC scrdc, memdc; HBITMAP membit; scrdc = ::GetDC(0); int Height = GetSystemMetrics(SM_CYSCREEN); int Width = GetSystemMetrics(SM_CXSCREEN); memdc = CreateCompatibleDC(scrdc); membit = CreateCompatibleBitmap(scrdc, Width, Height); HBITMAP hOldBitmap =(HBITMAP) SelectObject(memdc, membit); BitBlt(memdc, 0, 0, Width, Height, scrdc, 0, 0, SRCCOPY); Gdiplus::Bitmap bitmap(membit, NULL); CLSID clsid; GetEncoderClsid(L"image/jpeg", &clsid); bitmap.Save(L"screen.jpeg", &clsid, NULL); DeleteObject(memdc); DeleteObject(membit); ::ReleaseDC(0,scrdc); } GdiplusShutdown(gdiplusToken); } int main() { gdiscreen(); } -
prashanthrajagopal created this gist
Jun 16, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,68 @@ #include <stdio.h> #include <windows.h> #include <jpeglib.h> int jpegCapture(char* filename, int quality){ HBITMAP hBMP; HWND desktopWnd; int width; int height; RECT rc; HDC hDC; HDC hDCmem; struct jpeg_compress_struct cinfo; struct jpeg_error_mgr jerr; FILE * outfile; JSAMPLE* scanline; COLORREF pixel; desktopWnd = GetDesktopWindow(); GetWindowRect(desktopWnd, &rc); width = rc.right - rc.left; height = rc.bottom - rc.top; hDC = GetDC(desktopWnd); hDCmem = CreateCompatibleDC(hDC); hBMP = CreateCompatibleBitmap(hDC, width, height); if(hBMP == NULL) return -2; SelectObject(hDCmem, hBMP); BitBlt(hDCmem, 0, 0, width, height, hDC, rc.left, rc.top, SRCCOPY); cinfo.err = jpeg_std_error(&jerr); jpeg_create_compress(&cinfo); outfile = fopen(filename, "wb"); jpeg_stdio_dest(&cinfo, outfile); cinfo.image_width = width; cinfo.image_height = height; cinfo.input_components = 3; cinfo.in_color_space = JCS_RGB; jpeg_set_defaults(&cinfo); if(quality < 0) quality = 0; if(quality > 100) quality = 100; jpeg_set_quality(&cinfo, quality, FALSE); jpeg_start_compress(&cinfo, TRUE); scanline = new JSAMPLE[width*3]; for(int posy = 0; posy < height; posy++) { for(int posx = 0; posx < width; posx++) { pixel = GetPixel(hDCmem, posx, posy); scanline[posx*3+0] = GetRValue(pixel); scanline[posx*3+1] = GetGValue(pixel); scanline[posx*3+2] = GetBValue(pixel); } jpeg_write_scanlines(&cinfo, &scanline, 1); } jpeg_finish_compress(&cinfo); jpeg_destroy_compress(&cinfo); delete scanline; fclose(outfile); DeleteDC(hDCmem); ReleaseDC(desktopWnd, hDC); } int main() { jpegCapture("q.jpeg", 30); }