forked from old/legacy-imlib2
we have a jpeg saver and the saver code works
SVN revision: 1100
This commit is contained in:
parent
c944ff5199
commit
eb25c971c8
8
api.c
8
api.c
|
@ -1863,6 +1863,8 @@ imlib_save_image(Imlib_Image image, char *filename)
|
|||
ImlibImage *im;
|
||||
|
||||
CAST_IMAGE(im, image);
|
||||
if ((!(im->data)) && (im->loader) && (im->loader->load))
|
||||
im->loader->load(im, NULL, 0, 1);
|
||||
__imlib_SaveImage(im, filename, NULL, 0, NULL);
|
||||
}
|
||||
|
||||
|
@ -1874,6 +1876,8 @@ imlib_save_image_with_progress_callback(Imlib_Image image, char *filename,
|
|||
ImlibImage *im;
|
||||
|
||||
CAST_IMAGE(im, image);
|
||||
if ((!(im->data)) && (im->loader) && (im->loader->load))
|
||||
im->loader->load(im, NULL, 0, 1);
|
||||
__imlib_SaveImage(im, filename, progress_function,
|
||||
progress_granulatiy, NULL);
|
||||
}
|
||||
|
@ -1885,6 +1889,8 @@ imlib_save_image_with_error_return(Imlib_Image image, char *filename,
|
|||
ImlibImage *im;
|
||||
|
||||
CAST_IMAGE(im, image);
|
||||
if ((!(im->data)) && (im->loader) && (im->loader->load))
|
||||
im->loader->load(im, NULL, 0, 1);
|
||||
__imlib_SaveImage(im, filename, NULL, 0, error_return);
|
||||
}
|
||||
|
||||
|
@ -1898,6 +1904,8 @@ imlib_save_image_with_progress_callback_and_error_return(Imlib_Image image,
|
|||
ImlibImage *im;
|
||||
|
||||
CAST_IMAGE(im, image);
|
||||
if ((!(im->data)) && (im->loader) && (im->loader->load))
|
||||
im->loader->load(im, NULL, 0, 1);
|
||||
__imlib_SaveImage(im, filename,progress_function,
|
||||
progress_granulatiy, error_return);
|
||||
}
|
||||
|
|
20
image.c
20
image.c
|
@ -1125,11 +1125,11 @@ __imlib_SaveImage(ImlibImage *im, char *file,
|
|||
ImlibLoadError *er)
|
||||
{
|
||||
ImlibLoader *l;
|
||||
ImlibLoadError e;
|
||||
char e, *pfile;
|
||||
|
||||
if (!im->file)
|
||||
if (!file)
|
||||
{
|
||||
if (*er)
|
||||
if (er)
|
||||
*er = LOAD_ERROR_FILE_DOES_NOT_EXIST;
|
||||
return;
|
||||
}
|
||||
|
@ -1150,13 +1150,19 @@ __imlib_SaveImage(ImlibImage *im, char *file,
|
|||
return;
|
||||
}
|
||||
/* if they want an error returned - assume none by default */
|
||||
if (*er)
|
||||
if (er)
|
||||
*er = LOAD_ERROR_NONE;
|
||||
if (im->file)
|
||||
free(im->file);
|
||||
|
||||
/* set the filename to the saved one */
|
||||
pfile = im->file;
|
||||
im->file = strdup(file);
|
||||
|
||||
/* call the saver */
|
||||
e = l->save(im, progress, progress_granularity);
|
||||
|
||||
/* set the filename back to the laoder image filename */
|
||||
im->file = pfile;
|
||||
|
||||
/* if there's an error return and the save faile (e = 0) figure it out */
|
||||
if ((er) && (e == 0))
|
||||
{
|
||||
*er = LOAD_ERROR_UNKNOWN;
|
||||
|
|
|
@ -202,9 +202,94 @@ save (ImlibImage *im,
|
|||
int update_w, int update_h),
|
||||
char progress_granularity)
|
||||
{
|
||||
im = NULL;
|
||||
progress = NULL;
|
||||
return 0;
|
||||
struct jpeg_compress_struct cinfo;
|
||||
struct ImLib_JPEG_error_mgr jerr;
|
||||
FILE *f;
|
||||
DATA8 *buf;
|
||||
DATA32 *ptr;
|
||||
JSAMPROW *jbuf;
|
||||
int y = 0, quality = 75;
|
||||
ImlibImageTag *tag;
|
||||
|
||||
/* no image data? abort */
|
||||
if (!im->data)
|
||||
return 0;
|
||||
/* allocate a small buffer to convert image data */
|
||||
buf = malloc(im->w * 3 * sizeof(DATA8));
|
||||
if (!buf)
|
||||
return 0;
|
||||
f = fopen(im->file, "wb");
|
||||
if (!f)
|
||||
{
|
||||
free(buf);
|
||||
return 0;
|
||||
}
|
||||
/* set up error handling */
|
||||
cinfo.err = jpeg_std_error(&(jerr.pub));
|
||||
jerr.pub.error_exit = _JPEGFatalErrorHandler;
|
||||
if (sigsetjmp(jerr.setjmp_buffer, 1))
|
||||
{
|
||||
jpeg_destroy_compress(&cinfo);
|
||||
free(buf);
|
||||
fclose(f);
|
||||
return 0;
|
||||
}
|
||||
/* setup compress params */
|
||||
jpeg_create_compress(&cinfo);
|
||||
jpeg_stdio_dest(&cinfo, f);
|
||||
cinfo.image_width = im->w;
|
||||
cinfo.image_height = im->h;
|
||||
cinfo.input_components = 3;
|
||||
cinfo.in_color_space = JCS_RGB;
|
||||
|
||||
/* look for tags attached to image to get extra parameters liek quality */
|
||||
/* settigns etc. - thsi si the "api" to hint for extra information for */
|
||||
/* saver modules */
|
||||
tag = __imlib_GetTag(im, "quality");
|
||||
if (tag)
|
||||
quality = tag->val;
|
||||
if (quality < 1)
|
||||
quality = 1;
|
||||
if (quality > 100)
|
||||
quality = 100;
|
||||
|
||||
/* set up jepg compression parameters */
|
||||
jpeg_set_defaults(&cinfo);
|
||||
jpeg_set_quality(&cinfo, quality, TRUE);
|
||||
jpeg_start_compress(&cinfo, TRUE);
|
||||
/* get the start pointer */
|
||||
ptr = im->data;
|
||||
/* go one scanline at a time... and save */
|
||||
while (cinfo.next_scanline < cinfo.image_height)
|
||||
{
|
||||
int i, j;
|
||||
|
||||
/* convcert scaline from ARGB to RGB packed */
|
||||
for (j = 0, i = 0; i < im->w; i++)
|
||||
{
|
||||
buf[j++] = ((*ptr) >> 16) & 0xff;
|
||||
buf[j++] = ((*ptr) >> 8 ) & 0xff;
|
||||
buf[j++] = ((*ptr) ) & 0xff;
|
||||
ptr++;
|
||||
}
|
||||
/* write scanline */
|
||||
jbuf = (JSAMPROW *)(&buf);
|
||||
jpeg_write_scanlines(&cinfo, jbuf, 1);
|
||||
y++;
|
||||
if (progress)
|
||||
{
|
||||
char per;
|
||||
|
||||
per = (char)((100 * y) / im->h);
|
||||
progress(im, per, 0, y, im->w, 1);
|
||||
}
|
||||
}
|
||||
/* finish off */
|
||||
jpeg_finish_compress(&cinfo);
|
||||
free(buf);
|
||||
fclose(f);
|
||||
return 1;
|
||||
progress = NULL;
|
||||
}
|
||||
|
||||
void
|
||||
|
|
8
main.c
8
main.c
|
@ -305,13 +305,13 @@ int main (int argc, char **argv)
|
|||
rg = imlib_create_color_range();
|
||||
cl.red = 255; cl.green = 255; cl.blue = 255; cl.alpha = 255;
|
||||
imlib_add_color_to_color_range(rg, &cl, 0);
|
||||
cl.red = 255; cl.green = 255; cl.blue = 160; cl.alpha = 200;
|
||||
cl.red = 255; cl.green = 255; cl.blue = 160; cl.alpha = 255;
|
||||
imlib_add_color_to_color_range(rg, &cl, 1);
|
||||
cl.red = 255; cl.green = 160; cl.blue = 120; cl.alpha = 140;
|
||||
cl.red = 255; cl.green = 160; cl.blue = 120; cl.alpha = 255;
|
||||
imlib_add_color_to_color_range(rg, &cl, 1);
|
||||
cl.red = 100; cl.green = 80; cl.blue = 100; cl.alpha = 80;
|
||||
cl.red = 100; cl.green = 80; cl.blue = 100; cl.alpha = 255;
|
||||
imlib_add_color_to_color_range(rg, &cl, 1);
|
||||
cl.red = 32; cl.green = 48; cl.blue = 80; cl.alpha = 0;
|
||||
cl.red = 32; cl.green = 48; cl.blue = 80; cl.alpha = 255;
|
||||
imlib_add_color_to_color_range(rg, &cl, 1);
|
||||
}
|
||||
imlib_image_fill_color_range_rectangle(im, 60, 60, 256, 256,
|
||||
|
|
Loading…
Reference in New Issue