From 217797d63b2d3b1c9a7a0511af1bbf3d99f0d482 Mon Sep 17 00:00:00 2001 From: Carlos Garcia Campos Date: Wed, 13 Jun 2007 08:54:53 +0000 Subject: Use cairo image surfaces instead of GDK pixbufs for drawing pages and 2007-06-13 Carlos Garcia Campos * backend/dvi/dvi-document.c: (dvi_document_render), (dvi_document_render_pixbuf), (dvi_document_document_iface_init): * backend/impress/impress-document.c: (imp_render_get_from_drawable), (impress_document_render_pixbuf), (impress_document_render), (impress_document_document_iface_init), (impress_document_thumbnails_get_thumbnail): * backend/djvu/djvu-document-private.h: * backend/djvu/djvu-document.c: (djvu_document_render), (djvu_document_finalize), (djvu_document_document_iface_init), (djvu_document_thumbnails_get_thumbnail), (djvu_document_init): * backend/tiff/tiff-document.c: (tiff_document_render), (tiff_document_render_pixbuf), (tiff_document_document_iface_init): * backend/pdf/ev-poppler.cc: (pdf_document_render), (pdf_document_render_pixbuf), (pdf_document_document_iface_init), (pdf_selection_render_selection): * backend/comics/comics-document.c: (comics_document_render_pixbuf), (comics_document_render), (comics_document_document_iface_init): * backend/pixbuf/pixbuf-document.c: (pixbuf_document_render), (pixbuf_document_document_iface_init): * libdocument/ev-document-misc.[ch]: (ev_document_misc_surface_from_pixbuf), (ev_document_misc_surface_rotate_and_scale): * libdocument/ev-document.[ch]: (ev_document_render): * libdocument/ev-selection.[ch]: (ev_selection_render_selection): * shell/ev-pixbuf-cache.[ch]: (dispose_cache_job_info), (move_one_job), (copy_job_to_job_info), (add_job_if_needed), (ev_pixbuf_cache_get_surface), (new_selection_surface_needed), (clear_selection_if_needed), (ev_pixbuf_cache_style_changed), (ev_pixbuf_cache_get_selection_surface), (clear_job_selection): * shell/ev-jobs.[ch]: (ev_job_render_dispose), (render_finished_cb), (ev_job_render_run): * shell/ev-view.c: (draw_loading_text), (draw_one_page), (merge_selection_region): Use cairo image surfaces instead of GDK pixbufs for drawing pages and selections. svn path=/trunk/; revision=2499 --- (limited to 'backend/djvu') diff --git a/backend/djvu/djvu-document-private.h b/backend/djvu/djvu-document-private.h index 37651ef..3e7deed 100644 --- a/backend/djvu/djvu-document-private.h +++ b/backend/djvu/djvu-document-private.h @@ -32,6 +32,7 @@ struct _DjvuDocument { ddjvu_context_t *d_context; ddjvu_document_t *d_document; ddjvu_format_t *d_format; + ddjvu_format_t *thumbs_format; gchar *uri; diff --git a/backend/djvu/djvu-document.c b/backend/djvu/djvu-document.c index fc1ccaa..a8f0425 100644 --- a/backend/djvu/djvu-document.c +++ b/backend/djvu/djvu-document.c @@ -203,7 +203,7 @@ djvu_document_get_page_size (EvDocument *document, while ((r = ddjvu_document_get_pageinfo(djvu_document->d_document, page, &info)) < DDJVU_JOB_OK) djvu_handle_events(djvu_document, TRUE); - + if (r >= DDJVU_JOB_FAILED) djvu_handle_events(djvu_document, TRUE); @@ -211,45 +211,57 @@ djvu_document_get_page_size (EvDocument *document, *height = info.height * SCALE_FACTOR; } -static GdkPixbuf * -djvu_document_render_pixbuf (EvDocument *document, - EvRenderContext *rc) +static cairo_surface_t * +djvu_document_render (EvDocument *document, + EvRenderContext *rc) { DjvuDocument *djvu_document = DJVU_DOCUMENT (document); - GdkPixbuf *pixbuf; - GdkPixbuf *rotated_pixbuf; - + cairo_surface_t *surface, *rotated_surface; + gchar *pixels; + gint rowstride; ddjvu_rect_t rrect; ddjvu_rect_t prect; ddjvu_page_t *d_page; - double page_width, page_height; + static const cairo_user_data_key_t key; d_page = ddjvu_page_create_by_pageno (djvu_document->d_document, rc->page); while (!ddjvu_page_decoding_done (d_page)) djvu_handle_events(djvu_document, TRUE); - - page_width = ddjvu_page_get_width (d_page) * rc->scale * SCALE_FACTOR; - page_height = ddjvu_page_get_height (d_page) * rc->scale * SCALE_FACTOR; - pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, page_width, page_height); - - prect.x = 0; prect.y = 0; - prect.w = page_width; prect.h = page_height; + page_width = ddjvu_page_get_width (d_page) * rc->scale * SCALE_FACTOR + 0.5; + page_height = ddjvu_page_get_height (d_page) * rc->scale * SCALE_FACTOR + 0.5; + + rowstride = page_width * 4; + pixels = (gchar *) g_malloc (page_height * rowstride); + surface = cairo_image_surface_create_for_data (pixels, + CAIRO_FORMAT_ARGB32, + page_width, + page_height, + rowstride); + cairo_surface_set_user_data (surface, &key, + pixels, (cairo_destroy_func_t)g_free); + prect.x = 0; + prect.y = 0; + prect.w = page_width; + prect.h = page_height; rrect = prect; - ddjvu_page_render(d_page, DDJVU_RENDER_COLOR, - &prect, - &rrect, - djvu_document->d_format, - gdk_pixbuf_get_rowstride (pixbuf), - (gchar *)gdk_pixbuf_get_pixels (pixbuf)); - - rotated_pixbuf = gdk_pixbuf_rotate_simple (pixbuf, 360 - rc->rotation); - g_object_unref (pixbuf); - - return rotated_pixbuf; + ddjvu_page_render (d_page, DDJVU_RENDER_COLOR, + &prect, + &rrect, + djvu_document->d_format, + rowstride, + pixels); + + rotated_surface = ev_document_misc_surface_rotate_and_scale (surface, + page_width, + page_height, + rc->rotation); + cairo_surface_destroy (surface); + + return rotated_surface; } static void @@ -268,6 +280,7 @@ djvu_document_finalize (GObject *object) ddjvu_context_release (djvu_document->d_context); ddjvu_format_release (djvu_document->d_format); + ddjvu_format_release (djvu_document->thumbs_format); g_free (djvu_document->uri); G_OBJECT_CLASS (djvu_document_parent_class)->finalize (object); @@ -329,7 +342,7 @@ djvu_document_document_iface_init (EvDocumentIface *iface) iface->get_text = djvu_document_get_text; iface->get_n_pages = djvu_document_get_n_pages; iface->get_page_size = djvu_document_get_page_size; - iface->render_pixbuf = djvu_document_render_pixbuf; + iface->render = djvu_document_render; iface->get_info = djvu_document_get_info; } @@ -383,7 +396,7 @@ djvu_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document, ddjvu_thumbnail_render (djvu_document->d_document, rc->page, &thumb_width, &thumb_height, - djvu_document->d_format, + djvu_document->thumbs_format, gdk_pixbuf_get_rowstride (pixbuf), (gchar *)pixels); @@ -417,13 +430,13 @@ djvu_document_file_exporter_format_supported (EvFileExporter *exporter, static void djvu_document_file_exporter_begin (EvFileExporter *exporter, - EvFileExporterFormat format, - const char *filename, /* for storing the temp ps file */ - int first_page, - int last_page, - double width, - double height, - gboolean duplex) + EvFileExporterFormat format, + const char *filename, /* for storing the temp ps file */ + int first_page, + int last_page, + double width, + double height, + gboolean duplex) { DjvuDocument *djvu_document = DJVU_DOCUMENT (exporter); @@ -435,7 +448,8 @@ djvu_document_file_exporter_begin (EvFileExporter *exporter, } static void -djvu_document_file_exporter_do_page (EvFileExporter *exporter, EvRenderContext *rc) +djvu_document_file_exporter_do_page (EvFileExporter *exporter, + EvRenderContext *rc) { DjvuDocument *djvu_document = DJVU_DOCUMENT (exporter); @@ -478,9 +492,14 @@ djvu_document_file_exporter_iface_init (EvFileExporterIface *iface) static void djvu_document_init (DjvuDocument *djvu_document) { + guint masks[4] = { 0xff0000, 0xff00, 0xff, 0xff000000 }; + djvu_document->d_context = ddjvu_context_create ("Evince"); - djvu_document->d_format = ddjvu_format_create (DDJVU_FORMAT_RGB24, 0, 0); - ddjvu_format_set_row_order (djvu_document->d_format,1); + djvu_document->d_format = ddjvu_format_create (DDJVU_FORMAT_RGBMASK32, 4, masks); + ddjvu_format_set_row_order (djvu_document->d_format, 1); + + djvu_document->thumbs_format = ddjvu_format_create (DDJVU_FORMAT_RGB24, 0, 0); + ddjvu_format_set_row_order (djvu_document->thumbs_format, 1); djvu_document->ps_filename = NULL; djvu_document->opts = g_string_new (""); -- cgit v0.9.1