forked from old/legacy-imlib2
parent
0bfac5e70b
commit
2e6940e4c1
2
image.c
2
image.c
|
@ -138,7 +138,7 @@ __imlib_ProduceImage(void)
|
|||
memset(im, 0, sizeof(ImlibImage));
|
||||
im->data = NULL;
|
||||
im->file = NULL;
|
||||
im->flags = F_NONE;
|
||||
im->flags = F_FORMAT_IRRELEVANT | F_BORDER_IRRELEVANT | F_ALPHA_IRRELEVANT;
|
||||
im->loader = NULL;
|
||||
im->next = NULL;
|
||||
im->tags = NULL;
|
||||
|
|
89
loader_png.c
89
loader_png.c
|
@ -195,10 +195,91 @@ save (ImlibImage *im,
|
|||
int update_w, int update_h),
|
||||
char progress_granularity)
|
||||
{
|
||||
/* if we cant do this - just return 0 */
|
||||
im = NULL;
|
||||
progress = NULL;
|
||||
return 0;
|
||||
FILE *f;
|
||||
png_structp png_ptr;
|
||||
png_infop info_ptr;
|
||||
DATA32 *ptr;
|
||||
int x, y, j;
|
||||
png_bytep row_ptr, data = NULL;
|
||||
png_color_8 sig_bit;
|
||||
|
||||
f = fopen(im->file, "wb");
|
||||
if (!f)
|
||||
return 0;
|
||||
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING,
|
||||
NULL, NULL, NULL);
|
||||
if (!png_ptr)
|
||||
{
|
||||
fclose(f);
|
||||
return 0;
|
||||
}
|
||||
info_ptr = png_create_info_struct(png_ptr);
|
||||
if (info_ptr == NULL)
|
||||
{
|
||||
fclose(f);
|
||||
png_destroy_write_struct(&png_ptr, (png_infopp) NULL);
|
||||
return 0;
|
||||
}
|
||||
if (setjmp(png_ptr->jmpbuf))
|
||||
{
|
||||
fclose(f);
|
||||
png_destroy_write_struct(&png_ptr, (png_infopp) NULL);
|
||||
return 0;
|
||||
}
|
||||
png_init_io(png_ptr, f);
|
||||
if (im->flags & F_HAS_ALPHA)
|
||||
{
|
||||
png_set_IHDR(png_ptr, info_ptr, im->w, im->h, 8,
|
||||
PNG_COLOR_TYPE_RGB_ALPHA, PNG_INTERLACE_NONE,
|
||||
PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
|
||||
#ifdef WORDS_BIGENDIAN
|
||||
png_set_swap_alpha(png_ptr);
|
||||
#else
|
||||
png_set_bgr(png_ptr);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
png_set_IHDR(png_ptr, info_ptr, im->w, im->h, 8,
|
||||
PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE,
|
||||
PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
|
||||
data = malloc(im->w * 3 * sizeof(char));
|
||||
}
|
||||
sig_bit.red = 8;
|
||||
sig_bit.green = 8;
|
||||
sig_bit.blue = 8;
|
||||
sig_bit.alpha = 8;
|
||||
png_set_sBIT(png_ptr, info_ptr, &sig_bit);
|
||||
png_write_info(png_ptr, info_ptr);
|
||||
png_set_shift(png_ptr, &sig_bit);
|
||||
png_set_packing(png_ptr);
|
||||
|
||||
ptr = im->data;
|
||||
for (y = 0; y < im->h; y++)
|
||||
{
|
||||
if (im->flags & F_HAS_ALPHA)
|
||||
row_ptr = (png_bytep)ptr;
|
||||
else
|
||||
{
|
||||
for (j = 0, x = 0; x < im->w; x++)
|
||||
{
|
||||
data[j++] = (ptr[x] >> 16) & 0xff;
|
||||
data[j++] = (ptr[x] >> 8 ) & 0xff;
|
||||
data[j++] = (ptr[x] ) & 0xff;
|
||||
}
|
||||
row_ptr = (png_bytep)data;
|
||||
}
|
||||
png_write_rows(png_ptr, &row_ptr, 1);
|
||||
ptr += im->w;
|
||||
}
|
||||
if (data)
|
||||
free(data);
|
||||
png_write_end(png_ptr, info_ptr);
|
||||
png_destroy_write_struct(&png_ptr, (png_infopp) NULL);
|
||||
|
||||
fclose(f);
|
||||
return 1;
|
||||
progress = NULL;
|
||||
}
|
||||
|
||||
/* fills the ImlibLoader struct with a strign array of format file */
|
||||
|
|
2
main.c
2
main.c
|
@ -225,6 +225,7 @@ int main (int argc, char **argv)
|
|||
XResizeWindow(disp, win, w, h);
|
||||
XSync(disp, False);
|
||||
im = imlib_create_image(w, h);
|
||||
imlib_image_set_has_alpha(im, 1);
|
||||
imlib_set_cache_size(4 * 1024 * 1024);
|
||||
i = 0;
|
||||
up = imlib_update_append_rect(up, 0, 0, w, h);
|
||||
|
@ -412,6 +413,7 @@ int main (int argc, char **argv)
|
|||
up = imlib_updates_merge_for_rendering(up, w, h);
|
||||
imlib_render_image_updates_on_drawable(im, up, disp, win, vis, cm,
|
||||
depth, dith, 0, 0, NULL);
|
||||
imlib_save_image(im, "out.png");
|
||||
if ((px != x) || (py != y))
|
||||
{
|
||||
Imlib_Updates u;
|
||||
|
|
Loading…
Reference in New Issue