Example #1
0
static gboolean image_save(format_type type, image_output imageout, format_params params)
{
    gboolean result;

    if (type == FORMAT_BMP) {
        result = image_save_bmp(imageout);
    }
    else if(type == FORMAT_GIF) {
        result = image_save_gif(imageout, ((format_params_gif)params)->interlace);
    }
    else if(type == FORMAT_ICON) {
        result = image_save_icon(imageout);
    }
    else if(type == FORMAT_JPEG) {
        result = image_save_jpeg(
                     imageout,
                     ((format_params_jpeg)params)->quality,
                     ((format_params_jpeg)params)->smoothing,
                     ((format_params_jpeg)params)->entropy,
                     ((format_params_jpeg)params)->progressive,
                     ((format_params_jpeg)params)->comment,
                     ((format_params_jpeg)params)->subsampling,
                     ((format_params_jpeg)params)->baseline,
                     ((format_params_jpeg)params)->markers,
                     ((format_params_jpeg)params)->dct
                 );
    }
    else if(type == FORMAT_PNG) {
        result = image_save_png(imageout,
                                ((format_params_png)params)->interlace,
                                ((format_params_png)params)->compression,
                                ((format_params_png)params)->savebgc,
                                ((format_params_png)params)->savegamma,
                                ((format_params_png)params)->saveoff,
                                ((format_params_png)params)->savephys,
                                ((format_params_png)params)->savetime,
                                ((format_params_png)params)->savecomm,
                                ((format_params_png)params)->savetrans
                               );
    }
    else if(type == FORMAT_TGA) {
        result = image_save_tga(imageout, ((format_params_tga)params)->rle, ((format_params_tga)params)->origin);
    }
    else if(type == FORMAT_TIFF) {
        result = image_save_tiff(imageout, ((format_params_tiff)params)->compression);
    }
    else {
        result = gimp_file_save(
                     GIMP_RUN_NONINTERACTIVE,
                     imageout->image_id,
                     imageout->drawable_id,
                     imageout->filepath,
                     imageout->filename
                 );
    }

    return result;
}
static gboolean image_save(format_type type, image_output imageout, format_params params) 
{
    gboolean result;
    
    if (type == FORMAT_BMP) {
        result = image_save_bmp(imageout);
    }
    else if(type == FORMAT_GIF) {
        result = image_save_gif(imageout, ((format_params_gif)params)->interlace);
    }
    else if(type == FORMAT_ICON) {
        result = image_save_icon(imageout);
    }
    else if(type == FORMAT_JPEG) {
        result = image_save_jpeg(
            imageout, 
            ((format_params_jpeg)params)->quality, 
            ((format_params_jpeg)params)->smoothing, 
            ((format_params_jpeg)params)->entropy, 
            ((format_params_jpeg)params)->progressive,
            ((format_params_jpeg)params)->comment,
            ((format_params_jpeg)params)->subsampling,
            ((format_params_jpeg)params)->baseline,
            ((format_params_jpeg)params)->markers,
            ((format_params_jpeg)params)->dct
        );
    }
    else if(type == FORMAT_PNG) {
        result = image_save_png(imageout, 
            ((format_params_png)params)->interlace, 
            ((format_params_png)params)->compression,
            ((format_params_png)params)->savebgc,
            ((format_params_png)params)->savegamma,
            ((format_params_png)params)->saveoff,
            ((format_params_png)params)->savephys,
            ((format_params_png)params)->savetime,
            ((format_params_png)params)->savecomm,
            ((format_params_png)params)->savetrans
        );
    }
    else if(type == FORMAT_TGA) {
        result = image_save_tga(imageout, ((format_params_tga)params)->rle, ((format_params_tga)params)->origin);
    }
    else if(type == FORMAT_TIFF) {
        result = image_save_tiff(imageout, ((format_params_tiff)params)->compression);
    }
    else {
        // save in the original format
        int final_drawable = gimp_image_merge_visible_layers(imageout->image_id, GIMP_CLIP_TO_IMAGE);
        // but first check if the images was a GIF and it's palette has changed during the process
        if (file_has_extension(imageout->filename, ".gif") && gimp_drawable_is_rgb(final_drawable)) {
            gimp_image_convert_indexed(
                imageout->image_id,
                GIMP_FS_DITHER,
                GIMP_MAKE_PALETTE,
                gimp_drawable_has_alpha (final_drawable) ? 255 : 256,
                TRUE,
                FALSE,
                ""
            );
        }
    
        result = gimp_file_save(
            GIMP_RUN_NONINTERACTIVE, 
            imageout->image_id, 
            final_drawable, 
            imageout->filepath, 
            imageout->filename
        );
    }
    
    return result;
}