Changeset 62

Show
Ignore:
Timestamp:
11/05/11 11:03:51 (7 months ago)
Author:
mirko
Message:

Using Cairo instead of gdk_pixbuf. This should fix compatibility issues with newer poppler versions.

Location:
trunk
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/README

    r29 r62  
    4545   libpoppler-dev libpoppler-glib-dev) 
    4646 * GtkGlExt (Debian/Ubuntu package: libgtkglext1-dev) 
    47  * OpenGL (freeglut3-dev) 
    4847 * Boost C++ Program Option Library 
    4948 
  • trunk/configure.ac

    r61 r62  
    2020AC_PROG_CC 
    2121AC_PROG_CXX 
    22 dnl AM_PROG_LIBTOOL 
    2322AM_SANITY_CHECK 
    2423 
     
    4544AC_SUBST(poppler_glib_LIBS) 
    4645 
     46PKG_CHECK_MODULES(cairo, cairo >= 0.25) 
     47AC_SUBST(cairo_CFLAGS) 
     48AC_SUBST(cairo_LIBS) 
     49 
    4750AC_CHECK_HEADERS(GL/gl.h) 
    4851AC_CHECK_HEADERS(GL/glu.h) 
    4952AC_CHECK_HEADERS(GL/glx.h) 
    50 AC_CHECK_HEADERS(GL/glut.h) 
    5153 
    5254AX_BOOST_BASE([1.33.1]) 
  • trunk/src/pdfcube.cc

    r60 r62  
    33// PDFCube source file - pdfcube.cc 
    44//  
    5 // Copyright (C) 2006-2008  
     5// Copyright (C) 2006-2011 
    66//               Mirko Maischberger <mirko.maischberger@gmail.com> 
    77//               Karol Sokolowski   <sokoow@gmail.com> 
     
    4444#include <GL/glx.h> 
    4545 
    46 // PDF to GdkPixbuf (pkg-config poppler-glib) 
     46// PDF to cairo_surface_t using Cairo (pkg-config poppler-glib cairo) 
    4747#include <poppler.h> 
     48#include <cairo.h> 
    4849 
    4950#include <boost/program_options.hpp> 
     
    124125     frame(0), 
    125126     lookposx(0.0), lookposy(0.0), lookposz(3.48), 
    126      atx(0.0), aty(0.0), atz(0.0), persp(44.0), angle(0.0), pixmap(0) { 
     127     atx(0.0), aty(0.0), atz(0.0), persp(44.0), angle(0.0),  
     128     context(0), pixmap(0) { 
    127129    texmap[0] = 0; 
    128130    texmap[1] = 1; 
    129131    texmap[2] = 2; 
    130132    cube_faces=0; 
     133    PopplerPage *page; 
     134    double w,h; 
     135    page = poppler_document_get_page(d, 1); 
     136    poppler_page_get_size(page, &w, &h); 
     137    tex_width = 1024; 
     138    tex_height = 768; 
    131139    pixmap = 
    132       gdk_pixbuf_new(GDK_COLORSPACE_RGB, true, 8, tex_width, 
    133                      tex_height); 
     140      cairo_image_surface_create(CAIRO_FORMAT_ARGB32,  
     141                                 tex_width, 
     142                                 tex_height); 
     143    context = cairo_create(pixmap); 
     144    cairo_scale(context, tex_width/w, (double)tex_height/h); 
     145 
    134146    steps = new GLfloat[N_FRAMES]; 
    135147    xsteps = new double[N_FRAMES]; 
     
    230242    glEnable(GL_TEXTURE_RECTANGLE_ARB); 
    231243 
    232     GLfloat mat_ambient[] = { 0.0, 0.0, 0.0, 1.00 }; 
    233     GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.00 }; 
     244    GLfloat mat_ambient[] = { 0.0, 0.0, 0.0, 0.00 }; 
     245    GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 0.00 }; 
    234246    GLfloat mat_shininess[] = { 3.0 }; 
    235247 
     
    325337  void 
    326338  redraw(GtkWidget * widget) { 
    327  
    328339    double yoffset = 0.1; 
    329340    if (animating) { 
     
    726737        0, 0, 0, 127 
    727738      }; 
    728       glDrawPixels(1, 1, GL_RGBA, GL_UNSIGNED_BYTE, rcube); 
     739      glDrawPixels(1, 1, GL_BGRA, GL_UNSIGNED_BYTE, rcube); 
    729740 
    730741      active_animation = ANIM_NONE; 
     
    937948      texmap[1] = texmap[0]; 
    938949      texmap[0] = tmp; 
    939       render_page(pixmap, next_page(), tex_width, tex_height); 
     950      render_page(next_page()); 
    940951    } else { 
    941952      current_page = prev_page(); 
     
    944955      texmap[1] = texmap[2]; 
    945956      texmap[2] = tmp; 
    946       render_page(pixmap, prev_page(), tex_width, tex_height); 
     957      render_page(prev_page()); 
    947958    } 
    948959 
     
    955966                 tex_height, 
    956967                 0, 
    957                  GL_RGBA, 
    958                  GL_UNSIGNED_BYTE, gdk_pixbuf_get_pixels(pixmap)); 
     968                 GL_BGRA, 
     969                 GL_UNSIGNED_BYTE, cairo_image_surface_get_data(pixmap)); 
    959970 
    960971    gdk_window_invalidate_rect(widget->window, &widget->allocation, 
     
    968979    assert(current_page >= 0); 
    969980    assert(current_page < total_pages); 
    970     render_page(pixmap, current_page, tex_width, tex_height); 
     981    render_page(current_page); 
    971982    glBindTexture(GL_TEXTURE_RECTANGLE_ARB, textures[texmap[0]]); 
    972983    glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 
     
    976987                 tex_height, 
    977988                 0, 
    978                  GL_RGBA, 
    979                  GL_UNSIGNED_BYTE, gdk_pixbuf_get_pixels(pixmap)); 
    980  
    981     render_page(pixmap, prev_page(), tex_width, tex_height); 
     989                 GL_BGRA, 
     990                 GL_UNSIGNED_BYTE, cairo_image_surface_get_data(pixmap)); 
     991 
     992    render_page(prev_page()); 
    982993    glBindTexture(GL_TEXTURE_RECTANGLE_ARB, textures[texmap[1]]); 
    983994    glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 
     
    987998                 tex_height, 
    988999                 0, 
    989                  GL_RGBA, 
    990                  GL_UNSIGNED_BYTE, gdk_pixbuf_get_pixels(pixmap)); 
    991  
    992     render_page(pixmap, next_page(), tex_width, tex_height); 
     1000                 GL_BGRA, 
     1001                 GL_UNSIGNED_BYTE, cairo_image_surface_get_data(pixmap)); 
     1002 
     1003    render_page(next_page()); 
    9931004    glBindTexture(GL_TEXTURE_RECTANGLE_ARB, textures[texmap[2]]); 
    9941005    glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 
     
    9981009                 tex_height, 
    9991010                 0, 
    1000                  GL_RGBA, 
    1001                  GL_UNSIGNED_BYTE, gdk_pixbuf_get_pixels(pixmap)); 
     1011                 GL_BGRA, 
     1012                 GL_UNSIGNED_BYTE, cairo_image_surface_get_data(pixmap)); 
    10021013 
    10031014    gdk_window_invalidate_rect(widget->window, &widget->allocation, 
     
    10151026  double atx, aty, atz; 
    10161027  double persp, angle; 
    1017   GdkPixbuf *pixmap; 
     1028  cairo_surface_t *pixmap; 
     1029  cairo_t *context; 
    10181030  int texmap[3]; 
    10191031 
     
    10251037  // ratio is fixed, should instead depend on the  
    10261038  // aspect ratio of the pdf page) 
    1027   static const gint tex_width = (gint) (3 * 1024 / 2); 
    1028   static const gint tex_height = (gint) (3 * 768 / 2); 
     1039  gint tex_width; //(gint) (3 * 1024 / 2); 
     1040  gint tex_height; //(gint) (3 * 768 / 2); 
    10291041 
    10301042  // renders the poppler page on a pixmap 
    10311043  void 
    1032   render_page(GdkPixbuf * pm, int i, gint iWidth, gint iHeight) { 
     1044  render_page(int i) { 
    10331045    PopplerPage *page; 
    10341046    page = poppler_document_get_page(doc, i); 
    1035     double w, h; 
    1036     poppler_page_get_size(page, &w, &h); 
    1037     poppler_page_render_to_pixbuf(page, 0, 0, iWidth, iHeight, 
    1038                                   ((double)iWidth)/w, 0, pm); 
     1047    //double w,h; 
     1048    //poppler_page_get_size(page, &w, &h); 
     1049    cairo_save(context); 
     1050    unsigned char* data = cairo_image_surface_get_data(pixmap); 
     1051    std::fill(data, data+4*tex_width*tex_height, 0); 
     1052    cairo_surface_mark_dirty(pixmap); 
     1053    poppler_page_render(page, context); 
     1054    cairo_restore(context); 
    10391055  } 
    10401056