static int test3(void) { int nret = EXIT_FAILURE; sixel_chunk_t *chunk; sixel_allocator_t *allocator = NULL; SIXELSTATUS status = SIXEL_FALSE; sixel_debug_malloc_counter = 1; status = sixel_allocator_new(&allocator, sixel_bad_malloc, NULL, NULL, NULL); if (SIXEL_FAILED(status)) { goto error; } status = sixel_chunk_new(&chunk, "../images/map8.six", 0, NULL, allocator); if (status != SIXEL_BAD_ALLOCATION) { goto error; } nret = EXIT_SUCCESS; error: return nret; }
/* create new output context object */ SIXELAPI SIXELSTATUS sixel_output_new( sixel_output_t /* out */ **output, sixel_write_function /* in */ fn_write, void /* in */ *priv, sixel_allocator_t /* in */ *allocator) { SIXELSTATUS status = SIXEL_FALSE; size_t size; if (allocator == NULL) { status = sixel_allocator_new(&allocator, NULL, NULL, NULL, NULL); if (SIXEL_FAILED(status)) { goto end; } } else { sixel_allocator_ref(allocator); } size = sizeof(sixel_output_t) + SIXEL_OUTPUT_PACKET_SIZE * 2; *output = (sixel_output_t *)sixel_allocator_malloc(allocator, size); if (*output == NULL) { sixel_helper_set_additional_message( "sixel_output_new: sixel_allocator_malloc() failed."); status = SIXEL_BAD_ALLOCATION; goto end; } (*output)->ref = 1; (*output)->has_8bit_control = 0; (*output)->has_sdm_glitch = 0; (*output)->has_gri_arg_limit = 1; (*output)->skip_dcs_envelope = 0; (*output)->palette_type = SIXEL_PALETTETYPE_AUTO; (*output)->fn_write = fn_write; (*output)->save_pixel = 0; (*output)->save_count = 0; (*output)->active_palette = (-1); (*output)->node_top = NULL; (*output)->node_free = NULL; (*output)->priv = priv; (*output)->pos = 0; (*output)->penetrate_multiplexer = 0; (*output)->encode_policy = SIXEL_ENCODEPOLICY_AUTO; (*output)->allocator = allocator; status = SIXEL_OK; end: return status; }
/* create dither context object */ SIXELAPI SIXELSTATUS sixel_dither_new( sixel_dither_t /* out */ **ppdither, /* dither object to be created */ int /* in */ ncolors, /* required colors */ sixel_allocator_t /* in */ *allocator) /* allocator, null if you use default allocator */ { SIXELSTATUS status = SIXEL_FALSE; int headsize; int datasize; int wholesize; int quality_mode; if (ppdither == NULL) { sixel_helper_set_additional_message( "sixel_dither_new: ppdither is null."); status = SIXEL_BAD_ARGUMENT; goto end; } if (allocator == NULL) { status = sixel_allocator_new(&allocator, NULL, NULL, NULL, NULL); if (SIXEL_FAILED(status)) { *ppdither = NULL; goto end; } } else { sixel_allocator_ref(allocator); } if (ncolors == (-1)) { ncolors = 256; quality_mode = SIXEL_QUALITY_HIGHCOLOR; } else { if (ncolors > SIXEL_PALETTE_MAX) { ncolors = 256; } else if (ncolors < 2) { ncolors = 2; } quality_mode = SIXEL_QUALITY_LOW; } headsize = sizeof(sixel_dither_t); datasize = ncolors * 3; wholesize = headsize + datasize; *ppdither = (sixel_dither_t *)sixel_allocator_malloc(allocator, wholesize); if (*ppdither == NULL) { sixel_allocator_unref(allocator); sixel_helper_set_additional_message( "sixel_dither_new: sixel_allocator_malloc() failed."); status = SIXEL_BAD_ALLOCATION; goto end; } (*ppdither)->ref = 1; (*ppdither)->palette = (unsigned char*)(*ppdither + 1); (*ppdither)->cachetable = NULL; (*ppdither)->reqcolors = ncolors; (*ppdither)->ncolors = ncolors; (*ppdither)->origcolors = (-1); (*ppdither)->keycolor = (-1); (*ppdither)->optimized = 0; (*ppdither)->optimize_palette = 0; (*ppdither)->complexion = 1; (*ppdither)->bodyonly = 0; (*ppdither)->method_for_largest = SIXEL_LARGE_NORM; (*ppdither)->method_for_rep = SIXEL_REP_CENTER_BOX; (*ppdither)->method_for_diffuse = SIXEL_DIFFUSE_FS; (*ppdither)->quality_mode = quality_mode; (*ppdither)->pixelformat = SIXEL_PIXELFORMAT_RGB888; (*ppdither)->allocator = allocator; status = SIXEL_OK; end: return status; }