mirror of
https://git.pwmt.org/pwmt/zathura.git
synced 2025-01-01 06:56:01 +01:00
Updated plugin render functions
This commit is contained in:
parent
7d18faa452
commit
6689a3422a
3 changed files with 35 additions and 95 deletions
|
@ -243,76 +243,25 @@ djvu_page_render(zathura_page_t* page)
|
||||||
ddjvu_rect_t rrect = { 0, 0, page_width, page_height };
|
ddjvu_rect_t rrect = { 0, 0, page_width, page_height };
|
||||||
ddjvu_rect_t prect = { 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));
|
zathura_image_buffer_t* image_buffer = zathura_image_buffer_create(page_width, page_height);
|
||||||
if (!buffer) {
|
|
||||||
|
if (image_buffer == NULL) {
|
||||||
goto error_free;
|
goto error_free;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* set rotation */
|
/* set rotation */
|
||||||
GdkPixbufRotation gdk_angle = GDK_PIXBUF_ROTATE_NONE;
|
ddjvu_page_set_rotation(djvu_page, DDJVU_ROTATE_0);
|
||||||
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);
|
|
||||||
|
|
||||||
/* render page */
|
/* render page */
|
||||||
ddjvu_page_render(djvu_page, DDJVU_RENDER_COLOR, &prect, &rrect, djvu_document->format,
|
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 */
|
return image_buffer;
|
||||||
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;
|
|
||||||
|
|
||||||
error_free:
|
error_free:
|
||||||
|
|
||||||
ddjvu_page_release(djvu_page);
|
ddjvu_page_release(djvu_page);
|
||||||
free(buffer);
|
zathura_image_buffer_free(image_buffer);
|
||||||
g_object_unref(pixbuf);
|
|
||||||
|
|
||||||
error_out:
|
error_out:
|
||||||
|
|
||||||
|
|
|
@ -191,11 +191,10 @@ pdf_page_render(zathura_page_t* page)
|
||||||
page_height = dim_temp;
|
page_height = dim_temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* create pixbuf */
|
/* create image buffer */
|
||||||
GdkPixbuf* pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8,
|
zathura_image_buffer_t* image_buffer = zathura_image_buffer_create(page_width, page_height);
|
||||||
page_width, page_height);
|
|
||||||
|
|
||||||
if (!pixbuf) {
|
if (image_buffer == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -221,10 +220,6 @@ pdf_page_render(zathura_page_t* page)
|
||||||
ctm = fz_concat(ctm, fz_rotate(Zathura.document->rotate));
|
ctm = fz_concat(ctm, fz_rotate(Zathura.document->rotate));
|
||||||
fz_bbox bbox = fz_roundrect(fz_transformrect(ctm, mupdf_page->page->mediabox));
|
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_pixmap* pixmap = fz_newpixmapwithrect(fz_devicergb, bbox);
|
||||||
fz_clearpixmapwithcolor(pixmap, 0xFF);
|
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 y = 0; y < pixmap->h; y++) {
|
||||||
for (unsigned int x = 0; x < pixmap->w; x++) {
|
for (unsigned int x = 0; x < pixmap->w; x++) {
|
||||||
unsigned char *s = pixmap->samples + y * pixmap->w * 4 + x * 4;
|
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[0] = s[0];
|
||||||
p[1] = s[1];
|
p[1] = s[1];
|
||||||
p[2] = s[2];
|
p[2] = s[2];
|
||||||
|
@ -245,16 +240,5 @@ pdf_page_render(zathura_page_t* page)
|
||||||
fz_droppixmap(pixmap);
|
fz_droppixmap(pixmap);
|
||||||
fz_freedisplaylist(display_list);
|
fz_freedisplaylist(display_list);
|
||||||
|
|
||||||
/* write pixbuf */
|
return image_buffer;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -261,34 +261,41 @@ pdf_page_render(zathura_page_t* page)
|
||||||
unsigned int page_width = Zathura.document->scale * page->width;
|
unsigned int page_width = Zathura.document->scale * page->width;
|
||||||
unsigned int page_height = Zathura.document->scale * page->height;
|
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 */
|
/* create pixbuf */
|
||||||
GdkPixbuf* pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8,
|
GdkPixbuf* pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8,
|
||||||
page_width, page_height);
|
page_width, page_height);
|
||||||
|
|
||||||
if (!pixbuf) {
|
if (pixbuf == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
poppler_page_render_to_pixbuf(page->data, 0, 0, page_width, page_height, Zathura.document->scale,
|
poppler_page_render_to_pixbuf(page->data, 0, 0, page_width, page_height,
|
||||||
Zathura.document->rotate, pixbuf);
|
Zathura.document->scale, 90, pixbuf);
|
||||||
|
|
||||||
/* write pixbuf */
|
/* create image buffer */
|
||||||
GtkWidget* image = gtk_image_new();
|
zathura_image_buffer_t* image_buffer = zathura_image_buffer_create(page_width, page_height);
|
||||||
|
|
||||||
if (!image) {
|
if (image_buffer == NULL) {
|
||||||
g_object_unref(pixbuf);
|
g_object_unref(pixbuf);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
gtk_image_set_from_pixbuf(GTK_IMAGE(image), pixbuf);
|
/* copy buffer */
|
||||||
gtk_widget_show(image);
|
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;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue