Register Guidelines E-Books Search Today's Posts Mark Forums Read

Go Back   MobileRead Forums > E-Book Readers > More E-Book Readers > iRex > iRex Developer's Corner

Notices

Reply
 
Thread Tools Search this Thread
Old 11-06-2009, 12:17 AM   #1
ericshliao
Guru
ericshliao will become famous soon enoughericshliao will become famous soon enoughericshliao will become famous soon enoughericshliao will become famous soon enoughericshliao will become famous soon enoughericshliao will become famous soon enough
 
Posts: 974
Karma: 687
Join Date: Nov 2007
Device: Dell X51v; iLiad v2
What's wrong with my C code?

I have a small program (not really executable, just for experiement):
Code:
#include <glib.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
//#include <glib/gi18n-lib.h>
#include <string.h>
#include <libdjvu/ddjvuapi.h>

typedef struct _DjvuDocument DjvuDocument;

typedef struct _EvRenderContext EvRenderContext;

struct _DjvuDocument {
	GObject           parent_instance;

	ddjvu_context_t  *d_context;
	ddjvu_document_t *d_document;
	ddjvu_format_t   *d_format;
	ddjvu_format_t   *thumbs_format;

	gchar            *uri;

        /* PS exporter */
        gchar		 *ps_filename;
        GString 	 *opts;
};

struct _EvRenderContext
{
	GObject parent;
	
	//EvPage *page;
	gint    rotation;
	gdouble scale;
};

cairo_surface_t *djvu_document_render (DjvuDocument *djvu_document, int page_index)
{
	
	EvRenderContext *rc;
	
	cairo_surface_t *surface;
	gchar *pixels;
	gint   rowstride;
    ddjvu_rect_t rrect;
	ddjvu_rect_t prect;
	ddjvu_page_t *d_page;
	ddjvu_page_rotation_t rotation;
	double page_width, page_height, tmp;
	static const cairo_user_data_key_t key;

	d_page = ddjvu_page_create_by_pageno (djvu_document->d_document, page_index);
	
	while (!ddjvu_page_decoding_done (d_page))
		djvu_handle_events(djvu_document, TRUE, NULL);

	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;
	
	switch (rc->rotation) {
	        case 90:
			rotation = DDJVU_ROTATE_90;
			tmp = page_height;
			page_height = page_width;
			page_width = tmp;
			
			break;
	        case 180:
			rotation = DDJVU_ROTATE_180;
			
			break;
	        case 270:
			rotation = DDJVU_ROTATE_270;
			tmp = page_height;
			page_height = page_width;
			page_width = tmp;
			
			break;
	        default:
			rotation = DDJVU_ROTATE_0;
	}
///#ifdef HAVE_CAIRO_FORMAT_STRIDE_FOR_WIDTH
	rowstride = cairo_format_stride_for_width (CAIRO_FORMAT_RGB24, page_width);
//#else
//	rowstride = page_width * 4;
//#endif
	pixels = (gchar *) g_malloc (page_height * rowstride);
	surface = cairo_image_surface_create_for_data ((guchar *)pixels,
						       CAIRO_FORMAT_RGB24,
						       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_set_rotation (d_page, rotation);
	
	ddjvu_page_render (d_page, DDJVU_RENDER_COLOR,
			   &prect,
			   &rrect,
			   djvu_document->d_format,
			   rowstride,
			   pixels);

	return surface;
}

/*
static void
djvu_document_finalize (GObject *object)
{
	DjvuDocument *djvu_document = DJVU_DOCUMENT (object);

	if (djvu_document->d_document)
	    ddjvu_document_release (djvu_document->d_document);
	    
	if (djvu_document->opts)
	    g_string_free (djvu_document->opts, TRUE);

	if (djvu_document->ps_filename)
	    g_free (djvu_document->ps_filename);
	    
	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);
}*/


int main()
{

    return 0;
}
I compiled it with:
gcc -o test lua-djview.c `pkg-config gtk+-2.0 ddjvuapi --libs --cflags`
using GCC4.1.2 in Debian 5.

And I alwasy got error message:
lua-djview.c:35: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token

Line 35 is marked in red.

The code is copied from source code of Evince with some modification. I know it must be a silly problem, but I just can't figure it out. Please help. Thanx.

Last edited by ericshliao; 11-06-2009 at 12:21 AM.
ericshliao is offline   Reply With Quote
Old 11-06-2009, 12:07 PM   #2
ericshliao
Guru
ericshliao will become famous soon enoughericshliao will become famous soon enoughericshliao will become famous soon enoughericshliao will become famous soon enoughericshliao will become famous soon enoughericshliao will become famous soon enough
 
Posts: 974
Karma: 687
Join Date: Nov 2007
Device: Dell X51v; iLiad v2
Sorry. Please ignore this problem. I found that the above code is not correct. Some variables undefinded, required headers not include...It's all my fault.

Added:
I am trying to create a djvu module for lua, so that I can create a djvu reader for iLiad using GTK+, instead of QTGui. It should save ram and loading time.

Evince uses Cairo to convert page image gererated from Djvulibre API to cairo_surface_t, then draw it on GdkWindow. That's really a clever way.

Last edited by ericshliao; 11-06-2009 at 12:31 PM.
ericshliao is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Let's create a source code repository for DR 800 related code? jraf iRex 3 03-11-2010 12:26 PM
Its all gone wrong! Please help blackrat779 Bookeen 11 06-08-2009 03:43 AM
What have I done wrong justlizz Calibre 2 05-13-2009 05:45 PM
Help! Something is wrong... ficbot Fictionwise eBookwise 4 03-01-2009 07:57 PM
Am I doing something wrong? NavyDad6 Amazon Kindle 3 02-26-2009 02:04 AM


All times are GMT -4. The time now is 12:12 AM.


MobileRead.com is a privately owned, operated and funded community.