struct jpeg_source_mgr source_mgr;
BYTE source_buffer[1024];
BYTE *image_data;
+ CRITICAL_SECTION lock;
} JpegDecoder;
static inline JpegDecoder *decoder_from_decompress(j_decompress_ptr decompress)
if (ref == 0)
{
+ This->lock.DebugInfo->Spare[0] = 0;
+ DeleteCriticalSection(&This->lock);
if (This->cinfo_initialized) pjpeg_destroy_decompress(&This->cinfo);
if (This->stream) IStream_Release(This->stream);
HeapFree(GetProcessHeap(), 0, This->image_data);
int ret;
TRACE("(%p,%p,%u)\n", iface, pIStream, cacheOptions);
- if (This->cinfo_initialized) return WINCODEC_ERR_WRONGSTATE;
+ EnterCriticalSection(&This->lock);
+
+ if (This->cinfo_initialized)
+ {
+ LeaveCriticalSection(&This->lock);
+ return WINCODEC_ERR_WRONGSTATE;
+ }
This->cinfo.err = pjpeg_std_error(&This->jerr);
if (ret != JPEG_HEADER_OK) {
WARN("Jpeg image in stream has bad format, read header returned %d.\n",ret);
+ LeaveCriticalSection(&This->lock);
return E_FAIL;
}
if (!pjpeg_start_decompress(&This->cinfo))
{
ERR("jpeg_start_decompress failed\n");
+ LeaveCriticalSection(&This->lock);
return E_FAIL;
}
This->initialized = TRUE;
+ LeaveCriticalSection(&This->lock);
+
return S_OK;
}
max_row_needed = prc->Y + prc->Height;
if (max_row_needed > This->cinfo.output_height) return E_INVALIDARG;
+ EnterCriticalSection(&This->lock);
+
if (!This->image_data)
{
This->image_data = HeapAlloc(GetProcessHeap(), 0, data_size);
- if (!This->image_data) return E_OUTOFMEMORY;
+ if (!This->image_data)
+ {
+ LeaveCriticalSection(&This->lock);
+ return E_OUTOFMEMORY;
+ }
}
while (max_row_needed > This->cinfo.output_scanline)
if (ret == 0)
{
ERR("read_scanlines failed\n");
+ LeaveCriticalSection(&This->lock);
return E_FAIL;
}
}
}
+ LeaveCriticalSection(&This->lock);
+
return copy_pixels(bpp, This->image_data,
This->cinfo.output_width, This->cinfo.output_height, stride,
prc, cbStride, cbBufferSize, pbBuffer);
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);