int gs_jpeg_mem_init (gs_memory_t *mem, j_common_ptr cinfo) { int code = 0; #if SHARE_JPEG == 0 jpeg_cust_mem_data custm, *custmptr; memset(&custm, 0x00, sizeof(custm)); if (!jpeg_cust_mem_init(&custm, (void *) mem, gs_j_mem_init, gs_j_mem_term, NULL, gs_j_mem_alloc, gs_j_mem_free, gs_j_mem_alloc, gs_j_mem_free, NULL)) { code = gs_note_error(gs_error_VMerror); } if (code == 0) { custmptr = (jpeg_cust_mem_data *)gs_alloc_bytes(mem->non_gc_memory, sizeof(custm) + sizeof(void *), "JPEG custom memory descriptor"); if (!custmptr) { code = gs_note_error(gs_error_VMerror); } else { memcpy(custmptr, &custm, sizeof(custm)); cinfo->client_data = custmptr; } } #endif /* SHAREJPEG == 0 */ return code; }
static void fz_dct_mem_init(struct jpeg_decompress_struct *cinfo, fz_dctd *state) { jpeg_cust_mem_data *custmptr; custmptr = fz_malloc_struct(state->ctx, jpeg_cust_mem_data); if (!jpeg_cust_mem_init(custmptr, (void *) state, NULL, NULL, NULL, fz_dct_mem_alloc, fz_dct_mem_free, fz_dct_mem_alloc, fz_dct_mem_free, NULL)) { fz_free(state->ctx, custmptr); fz_throw(state->ctx, FZ_ERROR_GENERIC, "cannot initialize custom JPEG memory handler"); } cinfo->client_data = custmptr; }