#include #include #include #include #include static BOOL loadpic(LPCTSTR name, LPPICTURE* pic); int main(int argc, char *argv[]) { HBITMAP bitmap; BITMAPINFO info; LPPICTURE pic = NULL; HDC dc; long scrwidth = 0, scrheight = 0; int x, y, width, height; void *data = NULL; if(argc <= 1) return 1; if(!loadpic((LPCTSTR)argv[1], &pic)) return 1; pic->lpVtbl->get_Width(pic, &scrwidth); pic->lpVtbl->get_Height(pic, &scrheight); dc = CreateCompatibleDC(NULL); #if 0 WORD ramp[3*256]; for(x =0; x<3*256;x++) ramp[x]=0; GetDeviceGammaRamp(dc, ramp); for(x =0; x<3*256;x++) printf("%i ", ramp[x]); printf("\n"); #endif width = (scrwidth * GetDeviceCaps(dc, LOGPIXELSX) + 2540 / 2) / 2540; height = (scrheight * GetDeviceCaps(dc, LOGPIXELSY) + 2540 / 2) / 2540; printf("image size %i x %i\n", width, height); memset(&info, 0, sizeof(BITMAPINFO)); info.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); info.bmiHeader.biBitCount = 24; info.bmiHeader.biWidth = width; info.bmiHeader.biHeight = -height; info.bmiHeader.biCompression = BI_RGB; info.bmiHeader.biPlanes = 1; bitmap = CreateDIBSection(dc, &info, DIB_RGB_COLORS, &data, 0, 0); SelectObject(dc, bitmap); pic->lpVtbl->Render(pic, dc, 0, 0, width, height, 0, scrheight, scrwidth, -scrheight, NULL); pic->lpVtbl->Release(pic); for(y = 0; y < height; y++) { for(x = 0; x < width; x++) { unsigned char *pixels = data; printf("%.2x%.2x%.2x ", pixels[(y * width + x) * 3], pixels[(y * width + x) * 3 + 1], pixels[(y * width + x) * 3 + 2]); } printf("\n"); } return 0; } static BOOL loadpic(LPCTSTR name, LPPICTURE* pic) { HRESULT ret; HANDLE h; DWORD size, read = 0; LPVOID data; HGLOBAL buffer; LPSTREAM stream = NULL; h = CreateFile(name, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL); if (h == INVALID_HANDLE_VALUE) return FALSE; size = GetFileSize(h, NULL); if(size == (DWORD)-1) { CloseHandle(h); return FALSE; } buffer = GlobalAlloc(GMEM_MOVEABLE, size); if(!buffer) { CloseHandle(h); return FALSE; } data = GlobalLock(buffer); if(!data) { GlobalUnlock(buffer); CloseHandle(h); return FALSE; } ret = ReadFile(h, data, size, &read, NULL); GlobalUnlock(buffer); CloseHandle(h); if(!ret) return FALSE; ret = CreateStreamOnHGlobal(buffer, TRUE, &stream); if(!SUCCEEDED(ret)) { if(stream) stream->lpVtbl->Release(stream); return FALSE; } if(!stream) return FALSE; if(*pic) (*pic)->lpVtbl->Release(*pic); ret = OleLoadPicture(stream, size, FALSE, &IID_IPicture, (PVOID *)pic); stream->lpVtbl->Release(stream); if(!SUCCEEDED(ret)) return FALSE; if(!*pic) return FALSE; return TRUE; }