Updated plugin render functions

This commit is contained in:
Moritz Lipp 2011-03-18 14:10:42 +01:00
parent 7d18faa452
commit 6689a3422a
3 changed files with 35 additions and 95 deletions

View file

@ -243,76 +243,25 @@ djvu_page_render(zathura_page_t* page)
ddjvu_rect_t rrect = { 0, 0, page_width, page_height };
ddjvu_rect_t prect = { 0, 0, page_width, page_height };
guchar* buffer = malloc(sizeof(char) * (page_width * page_height * 3));
if (!buffer) {
zathura_image_buffer_t* image_buffer = zathura_image_buffer_create(page_width, page_height);
if (image_buffer == NULL) {
goto error_free;
}
/* set rotation */
GdkPixbufRotation gdk_angle = GDK_PIXBUF_ROTATE_NONE;
ddjvu_page_rotation_t ddjvu_angle = DDJVU_ROTATE_0;
switch(Zathura.document->rotate) {
case 90:
gdk_angle = GDK_PIXBUF_ROTATE_CLOCKWISE;
ddjvu_angle = DDJVU_ROTATE_90;
break;
case 180:
gdk_angle = GDK_PIXBUF_ROTATE_UPSIDEDOWN;
ddjvu_angle = DDJVU_ROTATE_180;
break;
case 270:
gdk_angle = GDK_PIXBUF_ROTATE_COUNTERCLOCKWISE;
ddjvu_angle = DDJVU_ROTATE_270;
break;
default:
gdk_angle = GDK_PIXBUF_ROTATE_NONE;
ddjvu_angle = DDJVU_ROTATE_0;
break;
}
ddjvu_page_set_rotation(djvu_page, ddjvu_angle);
ddjvu_page_set_rotation(djvu_page, DDJVU_ROTATE_0);
/* render page */
ddjvu_page_render(djvu_page, DDJVU_RENDER_COLOR, &prect, &rrect, djvu_document->format,
3 * page_width, (char*) buffer);
3 * page_width, (char*) image_buffer);
/* create pixbuf */
GdkPixbuf* pixbuf = gdk_pixbuf_new_from_data(buffer, GDK_COLORSPACE_RGB, FALSE, 8,
page_width, page_height, 3 * page_width, NULL, NULL);
if (!pixbuf) {
goto error_free;
}
/* rotate page */
if (Zathura.document->rotate != 0) {
GdkPixbuf* pixbuf_temp = gdk_pixbuf_rotate_simple(pixbuf, gdk_angle);
if (!pixbuf_temp) {
goto error_free;
}
pixbuf = pixbuf_temp;
}
GtkWidget* image = gtk_image_new();
if (!image) {
goto error_free;
}
gtk_image_set_from_pixbuf(GTK_IMAGE(image), pixbuf);
gtk_widget_show(image);
ddjvu_page_release(djvu_page);
return image;
return image_buffer;
error_free:
ddjvu_page_release(djvu_page);
free(buffer);
g_object_unref(pixbuf);
zathura_image_buffer_free(image_buffer);
error_out:

View file

@ -191,11 +191,10 @@ pdf_page_render(zathura_page_t* page)
page_height = dim_temp;
}
/* create pixbuf */
GdkPixbuf* pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8,
page_width, page_height);
/* create image buffer */
zathura_image_buffer_t* image_buffer = zathura_image_buffer_create(page_width, page_height);
if (!pixbuf) {
if (image_buffer == NULL) {
return NULL;
}
@ -221,10 +220,6 @@ pdf_page_render(zathura_page_t* page)
ctm = fz_concat(ctm, fz_rotate(Zathura.document->rotate));
fz_bbox bbox = fz_roundrect(fz_transformrect(ctm, mupdf_page->page->mediabox));
guchar* pixels = gdk_pixbuf_get_pixels(pixbuf);
int rowstride = gdk_pixbuf_get_rowstride(pixbuf);
int n_channels = gdk_pixbuf_get_n_channels(pixbuf);
fz_pixmap* pixmap = fz_newpixmapwithrect(fz_devicergb, bbox);
fz_clearpixmapwithcolor(pixmap, 0xFF);
@ -235,7 +230,7 @@ pdf_page_render(zathura_page_t* page)
for (unsigned int y = 0; y < pixmap->h; y++) {
for (unsigned int x = 0; x < pixmap->w; x++) {
unsigned char *s = pixmap->samples + y * pixmap->w * 4 + x * 4;
guchar* p = pixels + y * rowstride + x * n_channels;
guchar* p = image_buffer->data + y * image_buffer->width + x;
p[0] = s[0];
p[1] = s[1];
p[2] = s[2];
@ -245,16 +240,5 @@ pdf_page_render(zathura_page_t* page)
fz_droppixmap(pixmap);
fz_freedisplaylist(display_list);
/* write pixbuf */
GtkWidget* image = gtk_image_new();
if (!image) {
g_object_unref(pixbuf);
return NULL;
}
gtk_image_set_from_pixbuf(GTK_IMAGE(image), pixbuf);
gtk_widget_show(image);
return image;
return image_buffer;
}

View file

@ -261,34 +261,41 @@ pdf_page_render(zathura_page_t* page)
unsigned int page_width = Zathura.document->scale * page->width;
unsigned int page_height = Zathura.document->scale * page->height;
if (Zathura.document->rotate == 90 || Zathura.document->rotate == 270) {
unsigned int dim_temp = 0;
dim_temp = page_width;
page_width = page_height;
page_height = dim_temp;
}
/* create pixbuf */
GdkPixbuf* pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8,
page_width, page_height);
if (!pixbuf) {
if (pixbuf == NULL) {
return NULL;
}
poppler_page_render_to_pixbuf(page->data, 0, 0, page_width, page_height, Zathura.document->scale,
Zathura.document->rotate, pixbuf);
poppler_page_render_to_pixbuf(page->data, 0, 0, page_width, page_height,
Zathura.document->scale, 90, pixbuf);
/* write pixbuf */
GtkWidget* image = gtk_image_new();
/* create image buffer */
zathura_image_buffer_t* image_buffer = zathura_image_buffer_create(page_width, page_height);
if (!image) {
if (image_buffer == NULL) {
g_object_unref(pixbuf);
return NULL;
}
gtk_image_set_from_pixbuf(GTK_IMAGE(image), pixbuf);
gtk_widget_show(image);
/* copy buffer */
guchar* pixels = gdk_pixbuf_get_pixels(pixbuf);
int rowstride = gdk_pixbuf_get_rowstride(pixbuf);
int n_channels = gdk_pixbuf_get_n_channels(pixbuf);
return image;
for (unsigned int y = 0; y < page_height; y++) {
for (unsigned int x = 0; x < page_width; x++) {
unsigned char *s = pixels + y * rowstride + x * n_channels;
guchar* p = image_buffer->data + y * image_buffer->width + x;
p[0] = s[0];
p[1] = s[1];
p[2] = s[2];
}
}
g_object_unref(pixbuf);
return image_buffer;
}