HRESULT JpegDecoder_CreateInstance(IUnknown *pUnkOuter, REFIID iid, void** ppv) { JpegDecoder *This; HRESULT ret; TRACE("(%p,%s,%p)\n", pUnkOuter, debugstr_guid(iid), ppv); if (!libjpeg_handle && !load_libjpeg()) { ERR("Failed reading JPEG because unable to find %s\n", SONAME_LIBJPEG); return E_FAIL; } *ppv = NULL; if (pUnkOuter) return CLASS_E_NOAGGREGATION; This = HeapAlloc(GetProcessHeap(), 0, sizeof(JpegDecoder)); if (!This) return E_OUTOFMEMORY; This->lpVtbl = &JpegDecoder_Vtbl; This->lpFrameVtbl = &JpegDecoder_Frame_Vtbl; This->ref = 1; This->initialized = FALSE; This->cinfo_initialized = FALSE; This->stream = NULL; This->image_data = NULL; InitializeCriticalSection(&This->lock); This->lock.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": JpegDecoder.lock"); ret = IUnknown_QueryInterface((IUnknown*)This, iid, ppv); IUnknown_Release((IUnknown*)This); return ret; }
HRESULT JpegDecoder_CreateInstance(REFIID iid, void** ppv) { JpegDecoder *This; HRESULT ret; TRACE("(%s,%p)\n", debugstr_guid(iid), ppv); if (!libjpeg_handle && !load_libjpeg()) { ERR("Failed reading JPEG because unable to find %s\n", SONAME_LIBJPEG); return E_FAIL; } *ppv = NULL; This = HeapAlloc(GetProcessHeap(), 0, sizeof(JpegDecoder)); if (!This) return E_OUTOFMEMORY; This->IWICBitmapDecoder_iface.lpVtbl = &JpegDecoder_Vtbl; This->IWICBitmapFrameDecode_iface.lpVtbl = &JpegDecoder_Frame_Vtbl; This->IWICMetadataBlockReader_iface.lpVtbl = &JpegDecoder_Block_Vtbl; This->ref = 1; This->initialized = FALSE; This->cinfo_initialized = FALSE; This->stream = NULL; This->image_data = NULL; InitializeCriticalSection(&This->lock); This->lock.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": JpegDecoder.lock"); ret = IWICBitmapDecoder_QueryInterface(&This->IWICBitmapDecoder_iface, iid, ppv); IWICBitmapDecoder_Release(&This->IWICBitmapDecoder_iface); return ret; }
HRESULT JpegEncoder_CreateInstance(IUnknown *pUnkOuter, REFIID iid, void** ppv) { JpegEncoder *This; HRESULT ret; TRACE("(%p,%s,%p)\n", pUnkOuter, debugstr_guid(iid), ppv); *ppv = NULL; if (pUnkOuter) return CLASS_E_NOAGGREGATION; if (!libjpeg_handle && !load_libjpeg()) { ERR("Failed writing JPEG because unable to find %s\n",SONAME_LIBJPEG); return E_FAIL; } This = HeapAlloc(GetProcessHeap(), 0, sizeof(JpegEncoder)); if (!This) return E_OUTOFMEMORY; This->IWICBitmapEncoder_iface.lpVtbl = &JpegEncoder_Vtbl; This->IWICBitmapFrameEncode_iface.lpVtbl = &JpegEncoder_FrameVtbl; This->ref = 1; This->initialized = 0; This->frame_count = 0; This->frame_initialized = 0; This->started_compress = 0; This->lines_written = 0; This->frame_committed = 0; This->committed = 0; This->width = This->height = 0; This->xres = This->yres = 0.0; This->format = NULL; This->stream = NULL; InitializeCriticalSection(&This->lock); This->lock.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": JpegEncoder.lock"); ret = IWICBitmapEncoder_QueryInterface(&This->IWICBitmapEncoder_iface, iid, ppv); IWICBitmapEncoder_Release(&This->IWICBitmapEncoder_iface); return ret; }
TW_UINT16 _get_gphoto2_file_as_DIB( const char *folder, const char *filename, CameraFileType type, HWND hwnd, HBITMAP *hDIB ) { const unsigned char *filedata; unsigned long filesize; int ret; CameraFile *file; struct jpeg_source_mgr xjsm; struct jpeg_decompress_struct jd; struct jpeg_error_mgr jerr; HDC dc; BITMAPINFO bmpInfo; LPBYTE bits; JSAMPROW samprow, oldsamprow; if(!libjpeg_handle) { if(!load_libjpeg()) { FIXME("Failed reading JPEG because unable to find %s\n", SONAME_LIBJPEG); filedata = NULL; return TWRC_FAILURE; } } gp_file_new (&file); ret = gp_camera_file_get(activeDS.camera, folder, filename, type, file, activeDS.context); if (ret < GP_OK) { FIXME("Failed to get file?\n"); gp_file_unref (file); return TWRC_FAILURE; } ret = gp_file_get_data_and_size (file, (const char**)&filedata, &filesize); if (ret < GP_OK) { FIXME("Failed to get file data?\n"); return TWRC_FAILURE; } /* FIXME: Actually we might get other types than JPEG ... But only handle JPEG for now */ if (filedata[0] != 0xff) { ERR("File %s/%s might not be JPEG, cannot decode!\n", folder, filename); } /* This is basically so we can use in-memory data for jpeg decompression. * We need to have all the functions. */ xjsm.next_input_byte = filedata; xjsm.bytes_in_buffer = filesize; xjsm.init_source = _jpeg_init_source; xjsm.fill_input_buffer = _jpeg_fill_input_buffer; xjsm.skip_input_data = _jpeg_skip_input_data; xjsm.resync_to_restart = _jpeg_resync_to_restart; xjsm.term_source = _jpeg_term_source; jd.err = pjpeg_std_error(&jerr); /* jpeg_create_decompress is a macro that expands to jpeg_CreateDecompress - see jpeglib.h * jpeg_create_decompress(&jd); */ pjpeg_CreateDecompress(&jd, JPEG_LIB_VERSION, (size_t) sizeof(struct jpeg_decompress_struct)); jd.src = &xjsm; ret=pjpeg_read_header(&jd,TRUE); jd.out_color_space = JCS_RGB; pjpeg_start_decompress(&jd); if (ret != JPEG_HEADER_OK) { ERR("Jpeg image in stream has bad format, read header returned %d.\n",ret); gp_file_unref (file); return TWRC_FAILURE; } ZeroMemory (&bmpInfo, sizeof (BITMAPINFO)); bmpInfo.bmiHeader.biSize = sizeof (BITMAPINFOHEADER); bmpInfo.bmiHeader.biWidth = jd.output_width; bmpInfo.bmiHeader.biHeight = -jd.output_height; bmpInfo.bmiHeader.biPlanes = 1; bmpInfo.bmiHeader.biBitCount = jd.output_components*8; bmpInfo.bmiHeader.biCompression = BI_RGB; bmpInfo.bmiHeader.biSizeImage = 0; bmpInfo.bmiHeader.biXPelsPerMeter = 0; bmpInfo.bmiHeader.biYPelsPerMeter = 0; bmpInfo.bmiHeader.biClrUsed = 0; bmpInfo.bmiHeader.biClrImportant = 0; *hDIB = CreateDIBSection ((dc = GetDC(hwnd)), &bmpInfo, DIB_RGB_COLORS, (LPVOID)&bits, 0, 0); if (!*hDIB) { FIXME("Failed creating DIB.\n"); gp_file_unref (file); return TWRC_FAILURE; } samprow = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,jd.output_width*jd.output_components); oldsamprow = samprow; while ( jd.output_scanline<jd.output_height ) { int i, x = pjpeg_read_scanlines(&jd,&samprow,1); if (x != 1) { FIXME("failed to read current scanline?\n"); break; } /* We have to convert from RGB to BGR, see MSDN/ BITMAPINFOHEADER */ for(i=0;i<jd.output_width;i++,samprow+=jd.output_components) { *(bits++) = *(samprow+2); *(bits++) = *(samprow+1); *(bits++) = *(samprow); } bits = (LPBYTE)(((UINT_PTR)bits + 3) & ~3); samprow = oldsamprow; } if (hwnd) ReleaseDC (hwnd, dc); HeapFree (GetProcessHeap(), 0, samprow); gp_file_unref (file); return TWRC_SUCCESS; }
static TW_UINT16 _get_image_and_startup_jpeg(void) { const char *folder = NULL, *filename = NULL; struct gphoto2_file *file; const unsigned char *filedata; unsigned long filesize; int ret; if (activeDS.file) /* Already loaded. */ return TWRC_SUCCESS; if(!libjpeg_handle) { if(!load_libjpeg()) { FIXME("Failed reading JPEG because unable to find %s\n", SONAME_LIBJPEG); filedata = NULL; return TWRC_FAILURE; } } LIST_FOR_EACH_ENTRY( file, &activeDS.files, struct gphoto2_file, entry ) { if (strstr(file->filename,".JPG") || strstr(file->filename,".jpg")) { filename = file->filename; folder = file->folder; TRACE("downloading %s/%s\n", folder, filename); if (file->download) { file->download = FALSE; /* mark as done */ break; } } } gp_file_new (&activeDS.file); ret = gp_camera_file_get(activeDS.camera, folder, filename, GP_FILE_TYPE_NORMAL, activeDS.file, activeDS.context); if (ret < GP_OK) { FIXME("Failed to get file?\n"); activeDS.twCC = TWCC_SEQERROR; return TWRC_FAILURE; } ret = gp_file_get_data_and_size (activeDS.file, (const char**)&filedata, &filesize); if (ret < GP_OK) { FIXME("Failed to get file data?\n"); activeDS.twCC = TWCC_SEQERROR; return TWRC_FAILURE; } /* This is basically so we can use in-memory data for jpeg decompression. * We need to have all the functions. */ activeDS.xjsm.next_input_byte = filedata; activeDS.xjsm.bytes_in_buffer = filesize; activeDS.xjsm.init_source = _jpeg_init_source; activeDS.xjsm.fill_input_buffer = _jpeg_fill_input_buffer; activeDS.xjsm.skip_input_data = _jpeg_skip_input_data; activeDS.xjsm.resync_to_restart = _jpeg_resync_to_restart; activeDS.xjsm.term_source = _jpeg_term_source; activeDS.jd.err = pjpeg_std_error(&activeDS.jerr); /* jpeg_create_decompress is a macro that expands to jpeg_CreateDecompress - see jpeglib.h * jpeg_create_decompress(&jd); */ pjpeg_CreateDecompress(&activeDS.jd, JPEG_LIB_VERSION, (size_t) sizeof(struct jpeg_decompress_struct)); activeDS.jd.src = &activeDS.xjsm; ret=pjpeg_read_header(&activeDS.jd,TRUE); activeDS.jd.out_color_space = JCS_RGB; pjpeg_start_decompress(&activeDS.jd); if (ret != JPEG_HEADER_OK) { ERR("Jpeg image in stream has bad format, read header returned %d.\n",ret); gp_file_unref (activeDS.file); activeDS.file = NULL; return TWRC_FAILURE; } return TWRC_SUCCESS; }