X11-PngViewer
view release on metacpan or search on metacpan
PngViewer.xs view on Meta::CPAN
png_set_filler(png, 0xff, PNG_FILLER_AFTER);
png_set_bgr(png);
png_read_update_info(png, info);
break;
}
row_bytes = png_get_rowbytes (png, info);
size = image_height * row_bytes;
clip_row_bytes = row_bytes / 32;
if (row_bytes % 32) {
++clip_row_bytes;
}
data = (unsigned char*) malloc (sizeof (png_byte) * size);
row_pointers = (unsigned char**) malloc (image_height * sizeof (unsigned char*));
png_bytep cursor = data;
for (i=0; i < image_height; ++i, cursor += row_bytes) {
row_pointers[i] = cursor;
}
png_read_image(png, row_pointers);
png_read_end(png, NULL);
png_destroy_read_struct(&png, &info, (png_infopp)0);
free(row_pointers);
free(fake_png_file.data);
start_x = (self->display_width / 2) - (image_width / 2);
start_y = (self->display_height / 2) - (image_height / 2);
pixmap = (Pixmap *)malloc(sizeof(Pixmap));
*pixmap = XCreatePixmap (self->display, self->window, self->display_width, self->display_height, DefaultDepth(self->display, self->screen_number));
XFillRectangle(self->display, *pixmap, *self->gc, 0, 0, self->display_width, self->display_height);
ximage = XCreateImage(self->display, DefaultVisual (self->display, DefaultScreen (self->display)), DefaultDepth(self->display, self->screen_number), ZPixmap, 0, (char*)data, image_width, image_height, 32, row_bytes);
if (ximage) {
if (XPutImage(self->display, *pixmap, *self->gc, ximage, 0, 0, start_x, start_y, self->display_width, self->display_height)) {
XFreePixmap(self->display, *pixmap);
free(pixmap);
XDestroyImage(ximage);
croak("Failed to XPutImage");
}
XDestroyImage(ximage);
XCopyArea(self->display, *pixmap, self->window, *self->gc, 0, 0, self->display_width, self->display_height, 0, 0);
} else {
XFreePixmap(self->display, *pixmap);
free(pixmap);
croak("Failed to XCreateImage");
}
XFreePixmap(self->display, *pixmap);
free(pixmap);
XFlush(self->display);
return self;
}
void DESTROY(viewer *self) {
XFlush(self->display);
XFreeCursor(self->display, *self->cursor);
free(self->cursor);
XFreeGC(self->display, *self->gc);
XCloseDisplay(self->display);
free(self->gc);
free(self);
}
typedef viewer *X11__PngViewer;
MODULE = X11::PngViewer PACKAGE = X11::PngViewer
PROTOTYPES: ENABLE
X11::PngViewer
new(SV *class_name)
CODE:
RETVAL = new();
OUTPUT:
RETVAL
X11::PngViewer
show(self, png_contents)
X11::PngViewer self
SV *png_contents
CODE:
RETVAL = show(self, SvPV_nolen(png_contents), (int)SvLEN(png_contents));
OUTPUT:
RETVAL
( run in 0.562 second using v1.01-cache-2.11-cpan-ceb78f64989 )