ReactOS 0.4.16-dev-1067-ge98bba2
libjpeg.c File Reference
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include <setjmp.h>
#include <basetsd.h>
#include <jpeglib.h>
#include "ntstatus.h"
#include "windef.h"
#include "winternl.h"
#include "winbase.h"
#include "objbase.h"
#include "wincodecs_private.h"
#include "wine/debug.h"
Include dependency graph for libjpeg.c:

Go to the source code of this file.

Classes

struct  jpeg_decoder
 
struct  jpeg_compress_format
 
struct  jpeg_encoder
 

Macros

#define WIN32_NO_STATUS
 

Typedefs

typedef struct jpeg_compress_format jpeg_compress_format
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (wincodecs)
 
 WINE_DECLARE_DEBUG_CHANNEL (jpeg)
 
static void error_exit_fn (j_common_ptr cinfo)
 
static void emit_message_fn (j_common_ptr cinfo, int msg_level)
 
static struct jpeg_decoderimpl_from_decoder (struct decoder *iface)
 
static struct jpeg_decoderdecoder_from_decompress (j_decompress_ptr decompress)
 
static void CDECL jpeg_decoder_destroy (struct decoder *iface)
 
static void source_mgr_init_source (j_decompress_ptr cinfo)
 
static boolean source_mgr_fill_input_buffer (j_decompress_ptr cinfo)
 
static void source_mgr_skip_input_data (j_decompress_ptr cinfo, long num_bytes)
 
static void source_mgr_term_source (j_decompress_ptr cinfo)
 
static HRESULT CDECL jpeg_decoder_initialize (struct decoder *iface, IStream *stream, struct decoder_stat *st)
 
static HRESULT CDECL jpeg_decoder_get_frame_info (struct decoder *iface, UINT frame, struct decoder_frame *info)
 
static HRESULT CDECL jpeg_decoder_copy_pixels (struct decoder *iface, UINT frame, const WICRect *prc, UINT stride, UINT buffersize, BYTE *buffer)
 
static HRESULT CDECL jpeg_decoder_get_metadata_blocks (struct decoder *iface, UINT frame, UINT *count, struct decoder_block **blocks)
 
static HRESULT CDECL jpeg_decoder_get_color_context (struct decoder *This, UINT frame, UINT num, BYTE **data, DWORD *datasize)
 
HRESULT CDECL jpeg_decoder_create (struct decoder_info *info, struct decoder **result)
 
static struct jpeg_encoderimpl_from_encoder (struct encoder *iface)
 
static struct jpeg_encoderencoder_from_compress (j_compress_ptr compress)
 
static void dest_mgr_init_destination (j_compress_ptr cinfo)
 
static boolean dest_mgr_empty_output_buffer (j_compress_ptr cinfo)
 
static void dest_mgr_term_destination (j_compress_ptr cinfo)
 
static HRESULT CDECL jpeg_encoder_initialize (struct encoder *iface, IStream *stream)
 
static HRESULT CDECL jpeg_encoder_get_supported_format (struct encoder *iface, GUID *pixel_format, DWORD *bpp, BOOL *indexed)
 
static HRESULT CDECL jpeg_encoder_create_frame (struct encoder *iface, const struct encoder_frame *frame)
 
static HRESULT CDECL jpeg_encoder_write_lines (struct encoder *iface, BYTE *data, DWORD line_count, DWORD stride)
 
static HRESULT CDECL jpeg_encoder_commit_frame (struct encoder *iface)
 
static HRESULT CDECL jpeg_encoder_commit_file (struct encoder *iface)
 
static void CDECL jpeg_encoder_destroy (struct encoder *iface)
 
HRESULT CDECL jpeg_encoder_create (struct encoder_info *info, struct encoder **result)
 

Variables

static const struct decoder_funcs jpeg_decoder_vtable
 
static const jpeg_compress_format compress_formats []
 
static const struct encoder_funcs jpeg_encoder_vtable
 

Macro Definition Documentation

◆ WIN32_NO_STATUS

#define WIN32_NO_STATUS

Definition at line 27 of file libjpeg.c.

Typedef Documentation

◆ jpeg_compress_format

Function Documentation

◆ decoder_from_decompress()

static struct jpeg_decoder * decoder_from_decompress ( j_decompress_ptr  decompress)
inlinestatic

Definition at line 90 of file libjpeg.c.

91{
92 return CONTAINING_RECORD(decompress, struct jpeg_decoder, cinfo);
93}
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260

Referenced by source_mgr_fill_input_buffer(), and source_mgr_skip_input_data().

◆ dest_mgr_empty_output_buffer()

static boolean dest_mgr_empty_output_buffer ( j_compress_ptr  cinfo)
static

Definition at line 409 of file libjpeg.c.

410{
412 HRESULT hr;
413 ULONG byteswritten;
414
415 hr = stream_write(This->stream, This->dest_buffer,
416 sizeof(This->dest_buffer), &byteswritten);
417
418 if (hr != S_OK || byteswritten == 0)
419 {
420 ERR("Failed writing data, hr=%lx\n", hr);
421 return FALSE;
422 }
423
424 This->dest_mgr.next_output_byte = This->dest_buffer;
425 This->dest_mgr.free_in_buffer = sizeof(This->dest_buffer);
426 return TRUE;
427}
#define ERR(fmt,...)
Definition: precomp.h:57
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define S_OK
Definition: intsafe.h:52
static struct jpeg_encoder * encoder_from_compress(j_compress_ptr compress)
Definition: libjpeg.c:396
HRESULT hr
Definition: shlfolder.c:183
struct jpeg_compress_struct cinfo
Definition: libjpeg.c:383
uint32_t ULONG
Definition: typedefs.h:59
HRESULT CDECL stream_write(IStream *stream, const void *buffer, ULONG write, ULONG *bytes_written)

Referenced by jpeg_encoder_initialize().

◆ dest_mgr_init_destination()

static void dest_mgr_init_destination ( j_compress_ptr  cinfo)
static

Definition at line 401 of file libjpeg.c.

402{
404
405 This->dest_mgr.next_output_byte = This->dest_buffer;
406 This->dest_mgr.free_in_buffer = sizeof(This->dest_buffer);
407}

Referenced by jpeg_encoder_initialize().

◆ dest_mgr_term_destination()

static void dest_mgr_term_destination ( j_compress_ptr  cinfo)
static

Definition at line 429 of file libjpeg.c.

430{
432 ULONG byteswritten;
433 HRESULT hr;
434
435 if (This->dest_mgr.free_in_buffer != sizeof(This->dest_buffer))
436 {
437 hr = stream_write(This->stream, This->dest_buffer,
438 sizeof(This->dest_buffer) - This->dest_mgr.free_in_buffer, &byteswritten);
439
440 if (hr != S_OK || byteswritten == 0)
441 ERR("Failed writing data, hr=%lx\n", hr);
442 }
443}

Referenced by jpeg_encoder_initialize().

◆ emit_message_fn()

static void emit_message_fn ( j_common_ptr  cinfo,
int  msg_level 
)
static

Definition at line 51 of file libjpeg.c.

52{
54
55 if (msg_level < 0 && ERR_ON(jpeg))
56 {
57 cinfo->err->format_message(cinfo, message);
58 ERR_(jpeg)("%s\n", message);
59 }
60 else if (msg_level == 0 && WARN_ON(jpeg))
61 {
62 cinfo->err->format_message(cinfo, message);
63 WARN_(jpeg)("%s\n", message);
64 }
65 else if (msg_level > 0 && TRACE_ON(jpeg))
66 {
67 cinfo->err->format_message(cinfo, message);
68 TRACE_(jpeg)("%s\n", message);
69 }
70}
#define TRACE_(x)
Definition: compat.h:76
#define TRACE_ON(x)
Definition: compat.h:75
#define JMSG_LENGTH_MAX
Definition: jpeglib.h:711
#define WARN_ON(c)
Definition: module.h:257
#define ERR_(ch,...)
Definition: debug.h:156
#define WARN_(ch,...)
Definition: debug.h:157
#define ERR_ON(ch)
Definition: debug.h:412
Definition: tftpd.h:60

Referenced by jpeg_decoder_initialize(), and jpeg_encoder_initialize().

◆ encoder_from_compress()

static struct jpeg_encoder * encoder_from_compress ( j_compress_ptr  compress)
inlinestatic

Definition at line 396 of file libjpeg.c.

397{
398 return CONTAINING_RECORD(compress, struct jpeg_encoder, cinfo);
399}
int ZEXPORT compress(Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen)
Definition: compress.c:68

Referenced by dest_mgr_empty_output_buffer(), dest_mgr_init_destination(), and dest_mgr_term_destination().

◆ error_exit_fn()

static void error_exit_fn ( j_common_ptr  cinfo)
static

Definition at line 40 of file libjpeg.c.

41{
43 if (ERR_ON(jpeg))
44 {
45 cinfo->err->format_message(cinfo, message);
46 ERR_(jpeg)("%s\n", message);
47 }
48 longjmp(*(jmp_buf*)cinfo->client_data, 1);
49}
_JBTYPE jmp_buf[_JBLEN]
Definition: setjmp.h:186

Referenced by jpeg_decoder_initialize(), and jpeg_encoder_initialize().

◆ impl_from_decoder()

static struct jpeg_decoder * impl_from_decoder ( struct decoder iface)
inlinestatic

◆ impl_from_encoder()

static struct jpeg_encoder * impl_from_encoder ( struct encoder iface)
inlinestatic

◆ jpeg_decoder_copy_pixels()

static HRESULT CDECL jpeg_decoder_copy_pixels ( struct decoder iface,
UINT  frame,
const WICRect prc,
UINT  stride,
UINT  buffersize,
BYTE buffer 
)
static

Definition at line 308 of file libjpeg.c.

310{
311 struct jpeg_decoder *This = impl_from_decoder(iface);
312 return copy_pixels(This->frame.bpp, This->image_data,
313 This->frame.width, This->frame.height, This->stride,
314 prc, stride, buffersize, buffer);
315}
void copy_pixels(const BYTE *src, UINT src_row_pitch, UINT src_slice_pitch, BYTE *dst, UINT dst_row_pitch, UINT dst_slice_pitch, const struct volume *size, const struct pixel_format_desc *format) DECLSPEC_HIDDEN
Definition: surface.c:1700
GLsizei stride
Definition: glext.h:5848
GLuint buffer
Definition: glext.h:5915
static struct jpeg_decoder * impl_from_decoder(struct decoder *iface)
Definition: libjpeg.c:85
_Out_ LPRECT prc
Definition: ntgdi.h:1658

◆ jpeg_decoder_create()

HRESULT CDECL jpeg_decoder_create ( struct decoder_info info,
struct decoder **  result 
)

Definition at line 343 of file libjpeg.c.

344{
345 struct jpeg_decoder *This;
346
347 This = malloc(sizeof(struct jpeg_decoder));
348 if (!This) return E_OUTOFMEMORY;
349
350 This->decoder.vtable = &jpeg_decoder_vtable;
351 This->cinfo_initialized = FALSE;
352 This->stream = NULL;
353 This->image_data = NULL;
354 *result = &This->decoder;
355
356 info->container_format = GUID_ContainerFormatJpeg;
357 info->block_format = GUID_ContainerFormatJpeg;
358 info->clsid = CLSID_WICJpegDecoder;
359
360 return S_OK;
361}
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define malloc
Definition: debug_ros.c:4
#define NULL
Definition: types.h:112
GLuint64EXT * result
Definition: glext.h:11304
static const struct decoder_funcs jpeg_decoder_vtable
Definition: libjpeg.c:334

Referenced by JpegDecoder_CreateInstance().

◆ jpeg_decoder_destroy()

static void CDECL jpeg_decoder_destroy ( struct decoder iface)
static

Definition at line 95 of file libjpeg.c.

96{
97 struct jpeg_decoder *This = impl_from_decoder(iface);
98
99 if (This->cinfo_initialized) jpeg_destroy_decompress(&This->cinfo);
100 free(This->image_data);
101 free(This);
102}
#define free
Definition: debug_ros.c:5
jpeg_destroy_decompress(j_decompress_ptr cinfo)
Definition: jdapimin.c:92

◆ jpeg_decoder_get_color_context()

static HRESULT CDECL jpeg_decoder_get_color_context ( struct decoder This,
UINT  frame,
UINT  num,
BYTE **  data,
DWORD datasize 
)
static

Definition at line 326 of file libjpeg.c.

328{
329 /* This should never be called because we report 0 color contexts and the unsupported flag. */
330 FIXME("stub\n");
331 return E_NOTIMPL;
332}
#define FIXME(fmt,...)
Definition: precomp.h:53
#define E_NOTIMPL
Definition: ddrawi.h:99

◆ jpeg_decoder_get_frame_info()

static HRESULT CDECL jpeg_decoder_get_frame_info ( struct decoder iface,
UINT  frame,
struct decoder_frame info 
)
static

Definition at line 301 of file libjpeg.c.

302{
303 struct jpeg_decoder *This = impl_from_decoder(iface);
304 *info = This->frame;
305 return S_OK;
306}

◆ jpeg_decoder_get_metadata_blocks()

static HRESULT CDECL jpeg_decoder_get_metadata_blocks ( struct decoder iface,
UINT  frame,
UINT count,
struct decoder_block **  blocks 
)
static

Definition at line 317 of file libjpeg.c.

319{
320 FIXME("stub\n");
321 *count = 0;
322 *blocks = NULL;
323 return S_OK;
324}
GLuint GLuint GLsizei count
Definition: gl.h:1545
static int blocks
Definition: mkdosfs.c:527

◆ jpeg_decoder_initialize()

static HRESULT CDECL jpeg_decoder_initialize ( struct decoder iface,
IStream stream,
struct decoder_stat st 
)
static

Definition at line 148 of file libjpeg.c.

149{
150 struct jpeg_decoder *This = impl_from_decoder(iface);
151 int ret;
153 UINT data_size, i;
154
155 if (This->cinfo_initialized)
157
158 jpeg_std_error(&This->jerr);
159
160 This->jerr.error_exit = error_exit_fn;
161 This->jerr.emit_message = emit_message_fn;
162
163 This->cinfo.err = &This->jerr;
164
165 This->cinfo.client_data = jmpbuf;
166
167 if (setjmp(jmpbuf))
168 return E_FAIL;
169
171
172 This->cinfo_initialized = TRUE;
173
174 This->stream = stream;
175
176 stream_seek(This->stream, 0, STREAM_SEEK_SET, NULL);
177
178 This->source_mgr.bytes_in_buffer = 0;
179 This->source_mgr.init_source = source_mgr_init_source;
180 This->source_mgr.fill_input_buffer = source_mgr_fill_input_buffer;
181 This->source_mgr.skip_input_data = source_mgr_skip_input_data;
182 This->source_mgr.resync_to_restart = jpeg_resync_to_restart;
183 This->source_mgr.term_source = source_mgr_term_source;
184
185 This->cinfo.src = &This->source_mgr;
186
187 ret = jpeg_read_header(&This->cinfo, TRUE);
188
189 if (ret != JPEG_HEADER_OK) {
190 WARN("Jpeg image in stream has bad format, read header returned %d.\n",ret);
191 return E_FAIL;
192 }
193
194 switch (This->cinfo.jpeg_color_space)
195 {
196 case JCS_GRAYSCALE:
197 This->cinfo.out_color_space = JCS_GRAYSCALE;
198 This->frame.bpp = 8;
199 This->frame.pixel_format = GUID_WICPixelFormat8bppGray;
200 break;
201 case JCS_RGB:
202 case JCS_YCbCr:
203 This->cinfo.out_color_space = JCS_RGB;
204 This->frame.bpp = 24;
205 This->frame.pixel_format = GUID_WICPixelFormat24bppBGR;
206 break;
207 case JCS_CMYK:
208 case JCS_YCCK:
209 This->cinfo.out_color_space = JCS_CMYK;
210 This->frame.bpp = 32;
211 This->frame.pixel_format = GUID_WICPixelFormat32bppCMYK;
212 break;
213 default:
214 ERR("Unknown JPEG color space %i\n", This->cinfo.jpeg_color_space);
215 return E_FAIL;
216 }
217
218 if (!jpeg_start_decompress(&This->cinfo))
219 {
220 ERR("jpeg_start_decompress failed\n");
221 return E_FAIL;
222 }
223
224 This->frame.width = This->cinfo.output_width;
225 This->frame.height = This->cinfo.output_height;
226
227 switch (This->cinfo.density_unit)
228 {
229 case 2: /* pixels per centimeter */
230 This->frame.dpix = This->cinfo.X_density * 2.54;
231 This->frame.dpiy = This->cinfo.Y_density * 2.54;
232 break;
233
234 case 1: /* pixels per inch */
235 This->frame.dpix = This->cinfo.X_density;
236 This->frame.dpiy = This->cinfo.Y_density;
237 break;
238
239 case 0: /* unknown */
240 default:
241 This->frame.dpix = This->frame.dpiy = 96.0;
242 break;
243 }
244
245 This->frame.num_color_contexts = 0;
246 This->frame.num_colors = 0;
247
248 This->stride = (This->frame.bpp * This->cinfo.output_width + 7) / 8;
249 data_size = This->stride * This->cinfo.output_height;
250
251 if (data_size / This->stride < This->cinfo.output_height)
252 /* overflow in multiplication */
253 return E_OUTOFMEMORY;
254
255 This->image_data = malloc(data_size);
256 if (!This->image_data)
257 return E_OUTOFMEMORY;
258
259 while (This->cinfo.output_scanline < This->cinfo.output_height)
260 {
261 UINT first_scanline = This->cinfo.output_scanline;
262 UINT max_rows;
263 JSAMPROW out_rows[4];
265
266 max_rows = min(This->cinfo.output_height-first_scanline, 4);
267 for (i=0; i<max_rows; i++)
268 out_rows[i] = This->image_data + This->stride * (first_scanline+i);
269
270 ret = jpeg_read_scanlines(&This->cinfo, out_rows, max_rows);
271 if (ret == 0)
272 {
273 ERR("read_scanlines failed\n");
274 return E_FAIL;
275 }
276 }
277
278 if (This->frame.bpp == 24)
279 {
280 /* libjpeg gives us RGB data and we want BGR, so byteswap the data */
281 reverse_bgr8(3, This->image_data,
282 This->cinfo.output_width, This->cinfo.output_height,
283 This->stride);
284 }
285
286 if (This->cinfo.out_color_space == JCS_CMYK && This->cinfo.saw_Adobe_marker)
287 {
288 /* Adobe JPEG's have inverted CMYK data. */
289 for (i=0; i<data_size; i++)
290 This->image_data[i] ^= 0xff;
291 }
292
293 st->frame_count = 1;
298 return S_OK;
299}
static jmp_buf jmpbuf
Definition: NtContinue.c:24
#define WARN(fmt,...)
Definition: precomp.h:61
#define E_FAIL
Definition: ddrawi.h:102
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
jpeg_CreateDecompress(j_decompress_ptr cinfo, int version, size_t structsize)
Definition: jdapimin.c:31
jpeg_read_header(j_decompress_ptr cinfo, boolean require_image)
Definition: jdapimin.c:245
jpeg_read_scanlines(j_decompress_ptr cinfo, JSAMPARRAY scanlines, JDIMENSION max_lines)
Definition: jdapistd.c:153
jpeg_resync_to_restart(j_decompress_ptr cinfo, int desired)
Definition: jdmarker.c:1338
jpeg_std_error(struct jpeg_error_mgr *err)
Definition: jerror.c:232
unsigned int JDIMENSION
Definition: jmorecfg.h:229
@ JCS_YCCK
Definition: jpeglib.h:226
@ JCS_YCbCr
Definition: jpeglib.h:224
@ JCS_CMYK
Definition: jpeglib.h:225
@ JCS_GRAYSCALE
Definition: jpeglib.h:222
@ JCS_RGB
Definition: jpeglib.h:223
#define JPEG_LIB_VERSION
Definition: jpeglib.h:40
JSAMPLE FAR * JSAMPROW
Definition: jpeglib.h:75
#define JPEG_HEADER_OK
Definition: jpeglib.h:1046
static void source_mgr_term_source(j_decompress_ptr cinfo)
Definition: libjpeg.c:144
static boolean source_mgr_fill_input_buffer(j_decompress_ptr cinfo)
Definition: libjpeg.c:108
static void emit_message_fn(j_common_ptr cinfo, int msg_level)
Definition: libjpeg.c:51
static void error_exit_fn(j_common_ptr cinfo)
Definition: libjpeg.c:40
static void source_mgr_skip_input_data(j_decompress_ptr cinfo, long num_bytes)
Definition: libjpeg.c:128
static void source_mgr_init_source(j_decompress_ptr cinfo)
Definition: libjpeg.c:104
#define min(a, b)
Definition: monoChain.cc:55
unsigned int UINT
Definition: ndis.h:50
IStream * stream
Definition: libjpeg.c:76
#define setjmp
Definition: setjmp.h:209
int ret
@ WICBitmapDecoderCapabilityCanDecodeSomeImages
Definition: wincodec.idl:51
@ WICBitmapDecoderCapabilityCanEnumerateMetadata
Definition: wincodec.idl:52
@ WICBitmapDecoderCapabilityCanDecodeAllImages
Definition: wincodec.idl:50
HRESULT CDECL stream_seek(IStream *stream, LONGLONG ofs, DWORD origin, ULONGLONG *new_position)
void reverse_bgr8(UINT bytesperpixel, LPBYTE bits, UINT width, UINT height, INT stride)
#define DECODER_FLAGS_UNSUPPORTED_COLOR_CONTEXT
#define WINCODEC_ERR_WRONGSTATE
Definition: winerror.h:3281

◆ jpeg_encoder_commit_file()

static HRESULT CDECL jpeg_encoder_commit_file ( struct encoder iface)
static

Definition at line 615 of file libjpeg.c.

616{
617 return S_OK;
618}

◆ jpeg_encoder_commit_frame()

static HRESULT CDECL jpeg_encoder_commit_frame ( struct encoder iface)
static

Definition at line 600 of file libjpeg.c.

601{
602 struct jpeg_encoder *This = impl_from_encoder(iface);
604
605 if (setjmp(jmpbuf))
606 return E_FAIL;
607
608 This->cinfo.client_data = jmpbuf;
609
610 jpeg_finish_compress(&This->cinfo);
611
612 return S_OK;
613}
jpeg_finish_compress(j_compress_ptr cinfo)
Definition: jcapimin.c:155
static struct jpeg_encoder * impl_from_encoder(struct encoder *iface)
Definition: libjpeg.c:391

◆ jpeg_encoder_create()

HRESULT CDECL jpeg_encoder_create ( struct encoder_info info,
struct encoder **  result 
)

Definition at line 638 of file libjpeg.c.

639{
640 struct jpeg_encoder *This;
641
642 This = malloc(sizeof(struct jpeg_encoder));
643 if (!This) return E_OUTOFMEMORY;
644
645 This->encoder.vtable = &jpeg_encoder_vtable;
646 This->stream = NULL;
647 This->cinfo_initialized = FALSE;
648 *result = &This->encoder;
649
651 info->container_format = GUID_ContainerFormatJpeg;
652 info->clsid = CLSID_WICJpegEncoder;
653 info->encoder_options[0] = ENCODER_OPTION_IMAGE_QUALITY;
654 info->encoder_options[1] = ENCODER_OPTION_BITMAP_TRANSFORM;
655 info->encoder_options[2] = ENCODER_OPTION_LUMINANCE;
656 info->encoder_options[3] = ENCODER_OPTION_CHROMINANCE;
657 info->encoder_options[4] = ENCODER_OPTION_YCRCB_SUBSAMPLING;
658 info->encoder_options[5] = ENCODER_OPTION_SUPPRESS_APP0;
659 info->encoder_options[6] = ENCODER_OPTION_END;
660
661 return S_OK;
662}
static const struct encoder_funcs jpeg_encoder_vtable
Definition: libjpeg.c:628
#define ENCODER_FLAGS_SUPPORTS_METADATA
@ ENCODER_OPTION_CHROMINANCE
@ ENCODER_OPTION_YCRCB_SUBSAMPLING
@ ENCODER_OPTION_IMAGE_QUALITY
@ ENCODER_OPTION_END
@ ENCODER_OPTION_LUMINANCE
@ ENCODER_OPTION_SUPPRESS_APP0
@ ENCODER_OPTION_BITMAP_TRANSFORM

Referenced by JpegEncoder_CreateInstance().

◆ jpeg_encoder_create_frame()

static HRESULT CDECL jpeg_encoder_create_frame ( struct encoder iface,
const struct encoder_frame frame 
)
static

Definition at line 500 of file libjpeg.c.

501{
502 struct jpeg_encoder *This = impl_from_encoder(iface);
504 int i;
505
506 This->encoder_frame = *frame;
507
508 if (setjmp(jmpbuf))
509 return E_FAIL;
510
511 This->cinfo.client_data = jmpbuf;
512
513 for (i=0; compress_formats[i].guid; i++)
514 {
515 if (memcmp(compress_formats[i].guid, &frame->pixel_format, sizeof(GUID)) == 0)
516 break;
517 }
518 This->format = &compress_formats[i];
519
520 This->cinfo.image_width = frame->width;
521 This->cinfo.image_height = frame->height;
522 This->cinfo.input_components = This->format->num_components;
523 This->cinfo.in_color_space = This->format->color_space;
524
525 jpeg_set_defaults(&This->cinfo);
526
527 if (frame->dpix != 0.0 && frame->dpiy != 0.0)
528 {
529 This->cinfo.density_unit = 1; /* dots per inch */
530 This->cinfo.X_density = frame->dpix;
531 This->cinfo.Y_density = frame->dpiy;
532 }
533
534 jpeg_start_compress(&This->cinfo, TRUE);
535
536 return S_OK;
537}
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
jpeg_start_compress(j_compress_ptr cinfo, boolean write_all_tables)
Definition: jcapistd.c:39
jpeg_set_defaults(j_compress_ptr cinfo)
Definition: jcparam.c:196
static const jpeg_compress_format compress_formats[]
Definition: libjpeg.c:371
const GUID * guid
const WICPixelFormatGUID * guid
Definition: libjpeg.c:364

◆ jpeg_encoder_destroy()

static void CDECL jpeg_encoder_destroy ( struct encoder iface)
static

Definition at line 620 of file libjpeg.c.

621{
622 struct jpeg_encoder *This = impl_from_encoder(iface);
623 if (This->cinfo_initialized)
625 free(This);
626};
jpeg_destroy_compress(j_compress_ptr cinfo)
Definition: jcapimin.c:96

◆ jpeg_encoder_get_supported_format()

static HRESULT CDECL jpeg_encoder_get_supported_format ( struct encoder iface,
GUID pixel_format,
DWORD bpp,
BOOL indexed 
)
static

Definition at line 480 of file libjpeg.c.

482{
483 int i;
484
485 for (i=0; compress_formats[i].guid; i++)
486 {
487 if (memcmp(compress_formats[i].guid, pixel_format, sizeof(GUID)) == 0)
488 break;
489 }
490
491 if (!compress_formats[i].guid) i = 0;
492
495 *indexed = FALSE;
496
497 return S_OK;
498}
DWORD bpp
Definition: surface.c:185

◆ jpeg_encoder_initialize()

static HRESULT CDECL jpeg_encoder_initialize ( struct encoder iface,
IStream stream 
)
static

Definition at line 445 of file libjpeg.c.

446{
447 struct jpeg_encoder *This = impl_from_encoder(iface);
449
450 jpeg_std_error(&This->jerr);
451
452 This->jerr.error_exit = error_exit_fn;
453 This->jerr.emit_message = emit_message_fn;
454
455 This->cinfo.err = &This->jerr;
456
457 This->cinfo.client_data = jmpbuf;
458
459 if (setjmp(jmpbuf))
460 return E_FAIL;
461
463
464 This->stream = stream;
465
466 This->dest_mgr.next_output_byte = This->dest_buffer;
467 This->dest_mgr.free_in_buffer = sizeof(This->dest_buffer);
468
469 This->dest_mgr.init_destination = dest_mgr_init_destination;
470 This->dest_mgr.empty_output_buffer = dest_mgr_empty_output_buffer;
471 This->dest_mgr.term_destination = dest_mgr_term_destination;
472
473 This->cinfo.dest = &This->dest_mgr;
474
475 This->cinfo_initialized = TRUE;
476
477 return S_OK;
478}
jpeg_CreateCompress(j_compress_ptr cinfo, int version, size_t structsize)
Definition: jcapimin.c:31
static boolean dest_mgr_empty_output_buffer(j_compress_ptr cinfo)
Definition: libjpeg.c:409
static void dest_mgr_term_destination(j_compress_ptr cinfo)
Definition: libjpeg.c:429
static void dest_mgr_init_destination(j_compress_ptr cinfo)
Definition: libjpeg.c:401
IStream * stream
Definition: libjpeg.c:381

◆ jpeg_encoder_write_lines()

static HRESULT CDECL jpeg_encoder_write_lines ( struct encoder iface,
BYTE data,
DWORD  line_count,
DWORD  stride 
)
static

Definition at line 539 of file libjpeg.c.

541{
542 struct jpeg_encoder *This = impl_from_encoder(iface);
544 BYTE *swapped_data = NULL, *current_row;
545 UINT line;
546 int row_size;
547
548 if (setjmp(jmpbuf))
549 {
550 free(swapped_data);
551 return E_FAIL;
552 }
553
554 This->cinfo.client_data = jmpbuf;
555
556 row_size = This->format->bpp / 8 * This->encoder_frame.width;
557
558 if (This->format->swap_rgb)
559 {
560 swapped_data = malloc(row_size);
561 if (!swapped_data)
562 return E_OUTOFMEMORY;
563 }
564
565 for (line=0; line < line_count; line++)
566 {
567 if (This->format->swap_rgb)
568 {
569 UINT x;
570
571 memcpy(swapped_data, data + (stride * line), row_size);
572
573 for (x=0; x < This->encoder_frame.width; x++)
574 {
575 BYTE b;
576
577 b = swapped_data[x*3];
578 swapped_data[x*3] = swapped_data[x*3+2];
579 swapped_data[x*3+2] = b;
580 }
581
582 current_row = swapped_data;
583 }
584 else
585 current_row = data + (stride * line);
586
587 if (!jpeg_write_scanlines(&This->cinfo, &current_row, 1))
588 {
589 ERR("failed writing scanlines\n");
590 free(swapped_data);
591 return E_FAIL;
592 }
593 }
594
595 free(swapped_data);
596
597 return S_OK;
598}
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
jpeg_write_scanlines(j_compress_ptr cinfo, JSAMPARRAY scanlines, JDIMENSION num_lines)
Definition: jcapistd.c:78
#define b
Definition: ke_i.h:79
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
Definition: parser.c:49
unsigned char BYTE
Definition: xxhash.c:193

◆ source_mgr_fill_input_buffer()

static boolean source_mgr_fill_input_buffer ( j_decompress_ptr  cinfo)
static

Definition at line 108 of file libjpeg.c.

109{
111 HRESULT hr;
112 ULONG bytesread;
113
114 hr = stream_read(This->stream, This->source_buffer, 1024, &bytesread);
115
116 if (FAILED(hr) || bytesread == 0)
117 {
118 return FALSE;
119 }
120 else
121 {
122 This->source_mgr.next_input_byte = This->source_buffer;
123 This->source_mgr.bytes_in_buffer = bytesread;
124 return TRUE;
125 }
126}
#define FAILED(hr)
Definition: intsafe.h:51
static struct jpeg_decoder * decoder_from_decompress(j_decompress_ptr decompress)
Definition: libjpeg.c:90
static int stream_read
Definition: htmldoc.c:205
struct jpeg_decompress_struct cinfo
Definition: libjpeg.c:77

Referenced by jpeg_decoder_initialize().

◆ source_mgr_init_source()

static void source_mgr_init_source ( j_decompress_ptr  cinfo)
static

Definition at line 104 of file libjpeg.c.

105{
106}

Referenced by jpeg_decoder_initialize().

◆ source_mgr_skip_input_data()

static void source_mgr_skip_input_data ( j_decompress_ptr  cinfo,
long  num_bytes 
)
static

Definition at line 128 of file libjpeg.c.

129{
131
132 if (num_bytes > This->source_mgr.bytes_in_buffer)
133 {
134 stream_seek(This->stream, num_bytes - This->source_mgr.bytes_in_buffer, STREAM_SEEK_CUR, NULL);
135 This->source_mgr.bytes_in_buffer = 0;
136 }
137 else if (num_bytes > 0)
138 {
139 This->source_mgr.next_input_byte += num_bytes;
140 This->source_mgr.bytes_in_buffer -= num_bytes;
141 }
142}

Referenced by jpeg_decoder_initialize().

◆ source_mgr_term_source()

static void source_mgr_term_source ( j_decompress_ptr  cinfo)
static

Definition at line 144 of file libjpeg.c.

145{
146}

Referenced by jpeg_decoder_initialize().

◆ WINE_DECLARE_DEBUG_CHANNEL()

WINE_DECLARE_DEBUG_CHANNEL ( jpeg  )

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( wincodecs  )

Variable Documentation

◆ compress_formats

const jpeg_compress_format compress_formats[]
static
Initial value:
= {
{ &GUID_WICPixelFormat24bppBGR, 24, 3, JCS_RGB, 1 },
{ &GUID_WICPixelFormat32bppCMYK, 32, 4, JCS_CMYK },
{ &GUID_WICPixelFormat8bppGray, 8, 1, JCS_GRAYSCALE },
{ 0 }
}

Definition at line 371 of file libjpeg.c.

Referenced by jpeg_encoder_create_frame(), and jpeg_encoder_get_supported_format().

◆ jpeg_decoder_vtable

const struct decoder_funcs jpeg_decoder_vtable
static
Initial value:
= {
}
static HRESULT CDECL jpeg_decoder_copy_pixels(struct decoder *iface, UINT frame, const WICRect *prc, UINT stride, UINT buffersize, BYTE *buffer)
Definition: libjpeg.c:308
static HRESULT CDECL jpeg_decoder_get_frame_info(struct decoder *iface, UINT frame, struct decoder_frame *info)
Definition: libjpeg.c:301
static HRESULT CDECL jpeg_decoder_initialize(struct decoder *iface, IStream *stream, struct decoder_stat *st)
Definition: libjpeg.c:148
static HRESULT CDECL jpeg_decoder_get_metadata_blocks(struct decoder *iface, UINT frame, UINT *count, struct decoder_block **blocks)
Definition: libjpeg.c:317
static void CDECL jpeg_decoder_destroy(struct decoder *iface)
Definition: libjpeg.c:95
static HRESULT CDECL jpeg_decoder_get_color_context(struct decoder *This, UINT frame, UINT num, BYTE **data, DWORD *datasize)
Definition: libjpeg.c:326

Definition at line 334 of file libjpeg.c.

Referenced by jpeg_decoder_create().

◆ jpeg_encoder_vtable

const struct encoder_funcs jpeg_encoder_vtable
static
Initial value:
= {
}
static HRESULT CDECL jpeg_encoder_write_lines(struct encoder *iface, BYTE *data, DWORD line_count, DWORD stride)
Definition: libjpeg.c:539
static HRESULT CDECL jpeg_encoder_initialize(struct encoder *iface, IStream *stream)
Definition: libjpeg.c:445
static HRESULT CDECL jpeg_encoder_commit_frame(struct encoder *iface)
Definition: libjpeg.c:600
static HRESULT CDECL jpeg_encoder_create_frame(struct encoder *iface, const struct encoder_frame *frame)
Definition: libjpeg.c:500
static void CDECL jpeg_encoder_destroy(struct encoder *iface)
Definition: libjpeg.c:620
static HRESULT CDECL jpeg_encoder_commit_file(struct encoder *iface)
Definition: libjpeg.c:615
static HRESULT CDECL jpeg_encoder_get_supported_format(struct encoder *iface, GUID *pixel_format, DWORD *bpp, BOOL *indexed)
Definition: libjpeg.c:480

Definition at line 628 of file libjpeg.c.

Referenced by jpeg_encoder_create().