Exemplo n.º 1
0
static pngquant_error prepare_output_image(liq_result *result, liq_image *input_image, png8_image *output_image)
{
    output_image->width = liq_image_get_width(input_image);
    output_image->height = liq_image_get_height(input_image);
    output_image->gamma = liq_get_output_gamma(result);

    /*
    ** Step 3.7 [GRR]: allocate memory for the entire indexed image
    */

    output_image->indexed_data = malloc(output_image->height * output_image->width);
    output_image->row_pointers = malloc(output_image->height * sizeof(output_image->row_pointers[0]));

    if (!output_image->indexed_data || !output_image->row_pointers) {
        return OUT_OF_MEMORY_ERROR;
    }

    for(size_t row = 0; row < output_image->height; row++) {
        output_image->row_pointers[row] = output_image->indexed_data + row * output_image->width;
    }

    const liq_palette *palette = liq_get_palette(result);
    // tRNS, etc.
    output_image->num_palette = palette->count;
    output_image->num_trans = 0;
    for(unsigned int i=0; i < palette->count; i++) {
        if (palette->entries[i].a < 255) {
            output_image->num_trans = i+1;
        }
    }

    return SUCCESS;
}
Exemplo n.º 2
0
void
prepare_output_image(liq_result *rv, liq_image *image, png8_image *png)
{
    unsigned int i;
    const liq_palette *palette;
    
    png->width = liq_image_get_width(image);
    png->height = liq_image_get_height(image);

    png->indexed_data = malloc(png->width * png->height);
    png->row_pointers = malloc(png->height * sizeof(png->row_pointers[0]));

    for (i = 0;i < png->height;i++) {
        png->row_pointers[i] = png->indexed_data + i * png->width;
    }
    
    palette = liq_get_palette(rv);
    png->num_palette = palette->count;
    png->num_trans = 0;
    for (i = 0;i < palette->count;i++) {
        if (palette->entries[i].a < 255) {
            png->num_trans = i + 1;
        }
    }
}