Thread: iLiad DJVU for iLiad
View Single Post
Old 10-25-2006, 08:04 AM   #7
Mike Kostousov
Connoisseur
Mike Kostousov has learned how to read e-booksMike Kostousov has learned how to read e-booksMike Kostousov has learned how to read e-booksMike Kostousov has learned how to read e-booksMike Kostousov has learned how to read e-booksMike Kostousov has learned how to read e-booksMike Kostousov has learned how to read e-books
 
Posts: 50
Karma: 861
Join Date: Aug 2006
Device: Zaurus C1000/iLiad/SE K750i
Code:
#include "config.h"
#include "DjVuGlobal.h"
#include "ZPCodec.h"
#include "GException.h"
#include "GSmartPointer.h"
#include "GURL.h"
#include "GRect.h"
#include "GPixmap.h"
#include "GBitmap.h"
#include "DjVuImage.h"
#include "DjVuDocument.h"
#include "GOS.h"
#include "ByteStream.h"
#include "DjVuMessage.h"
#include "DjVuText.h"
#include "ddjvuapi.h"


GP<DjVuDocument> doc;



int openFile(const char *fileName)
{
	djvu_programname("ddjvu");
	ddjvu_context_t * context = ddjvu_context_create("djview");	
	ddjvu_cache_set_size(context,10000000);
	printf("cache_size %ld\n",ddjvu_cache_get_size(context));
	if (doc) doc->stop_init();
	GURL gurl=GURL::Filename::UTF8(GNativeString(fileName));
	doc = DjVuDocument::create_wait(gurl);
	/*	doc = DjVuDocument::create_noinit();
		if (!doc) return 1;
		GURL gurl=GURL::Filename::UTF8(GNativeString(fileName.latin1()));
		doc->start_init(gurl);
	 */	ddjvu_context_release(context);
	return 1;
}

uint * getPageNum(int pageNum,int width,int height)
{
	printf("step 1");

	GP<DjVuImage> dimg;
	dimg = doc->get_page(pageNum);
	if (!dimg || ! dimg->wait_for_complete_decode()) { printf("error no dimg\n"); }
	DjVuInfo *info = dimg->get_info();
	int colorp = dimg->is_legal_photo();
	int blackp = dimg->is_legal_bilevel();
	int compoundp = dimg->is_legal_compound();
	if (!compoundp && !colorp && !blackp) 
	{ 
		DjVuPrintErrorUTF8("%s","Warning: This is not a well formed DjVu image\n");
		if (!info)  printf("error\n");
	}

	GP<GPixmap> pm;
	GP<GBitmap> bm;
	GRect renderrect(0,0,width/2,height/2);
	GRect fullrect(0,0,width/2,height/2);
	uint * buffer = new uint[width*height];


	pm = dimg->get_pixmap(renderrect, fullrect);

	if (!pm) bm = dimg->get_bitmap(renderrect, fullrect);
	unsigned int buff_row = width;
	unsigned int* buff_ptr = new uint[width*height*10];  
	unsigned int px,py;
	unsigned int w,h;
	printf("here");
	if (bm) {
		printf("BM!!!\n");

		int grays = bm->get_grays();
		unsigned char* row_ptr = (*bm)[bm->rows()-1];
		w=bm->columns();
		h=bm->rows();
		for (unsigned int i=0;i<w*h;i++) 
		{
			py=i/w;
			px=i%w;
			if (px==0)
			{
				row_ptr = (*bm)[bm->rows()-py-1];
				buff_ptr = buffer + buff_row*py;
			}
			int v = 255 - ((row_ptr[px] * 255) / (grays-1));
			buff_ptr[px] = (255<<24) | (v<<16) | (v<<8) | v;
		}

	} else
		if (pm) {
			printf("PM!!!\n");
			w=pm->columns();
			h=pm->rows();

			GPixel* row_ptr;
			for (unsigned int i=0;i<w*h;i++) {
				py=i/w;
				px=i%w;
				if (px==0) 
				{
					row_ptr=(*pm)[pm->rows()-1-py];
					buff_ptr = buffer + buff_row*py;
				}
				int r = row_ptr[px].r;
				int g = row_ptr[px].g;
				int b = row_ptr[px].b;
				buff_ptr[px] = (255<<24) | (r<<16) | (g<<8) | b;
			}
		}
	return buffer;

}
With compilation of djvulibre can be some problems. So, gcc parameters must be tuned and config.h also must be tuned

Last edited by Mike Kostousov; 10-25-2006 at 08:09 AM.
Mike Kostousov is offline   Reply With Quote