Пример #1
0
extern "C" jint
Java_org_vudroid_djvudroid_codec_DjvuPage_getHeight(JNIEnv *env,
                                    jclass cls,
                                    jlong pageHangle)
{
	return ddjvu_page_get_height((ddjvu_page_t*)pageHangle);
}
Пример #2
0
static int getPageInfo(lua_State *L) {
	DjvuDocument *doc = (DjvuDocument*) luaL_checkudata(L, 1, "djvudocument");
	int pageno = luaL_checkint(L, 2);
	ddjvu_page_t *djvu_page;
	int page_width, page_height, page_dpi;
	double page_gamma;
	ddjvu_page_type_t page_type;
	char *page_type_str;

	djvu_page = ddjvu_page_create_by_pageno(doc->doc_ref, pageno - 1);
	if (! djvu_page)
		return luaL_error(L, "cannot create djvu_page #%d", pageno);

	while (! ddjvu_page_decoding_done(djvu_page))
		handle(L, doc->context, TRUE);

	page_width = ddjvu_page_get_width(djvu_page);
	lua_pushnumber(L, page_width);

	page_height = ddjvu_page_get_height(djvu_page);
	lua_pushnumber(L, page_height);

	page_dpi = ddjvu_page_get_resolution(djvu_page);
	lua_pushnumber(L, page_dpi);

	page_gamma = ddjvu_page_get_gamma(djvu_page);
	lua_pushnumber(L, page_gamma);

	page_type = ddjvu_page_get_type(djvu_page);
	switch (page_type) {
		case DDJVU_PAGETYPE_UNKNOWN:
			page_type_str = "UNKNOWN";
			break;

		case DDJVU_PAGETYPE_BITONAL:
			page_type_str = "BITONAL";
			break;

		case DDJVU_PAGETYPE_PHOTO:
			page_type_str = "PHOTO";
			break;

		case DDJVU_PAGETYPE_COMPOUND:
			page_type_str = "COMPOUND";
			break;

		default:
			page_type_str = "INVALID";
			break;
	}
	lua_pushstring(L, page_type_str);

	ddjvu_page_release(djvu_page);

	return 5;
}
Пример #3
0
static int getPagePix(lua_State *L) {
	DjvuPage *page = (DjvuPage*) luaL_checkudata(L, 1, "djvupage");
	KOPTContext *kctx = (KOPTContext*) lua_topointer(L, 2);
	ddjvu_rect_t prect;
	ddjvu_rect_t rrect;
	int px, py, pw, ph, rx, ry, rw, rh, status;

	px = 0;
    py = 0;
    pw = ddjvu_page_get_width(page->page_ref);
    ph = ddjvu_page_get_height(page->page_ref);
    prect.x = px;
    prect.y = py;

	rx = (int)kctx->bbox.x0;
    ry = (int)kctx->bbox.y0;
    rw = (int)(kctx->bbox.x1 - kctx->bbox.x0);
    rh = (int)(kctx->bbox.y1 - kctx->bbox.y0);

    float scale = kctx->zoom;

    prect.w = pw * scale;
    prect.h = ph * scale;
    rrect.x = rx * scale;
    rrect.y = ry * scale;
    rrect.w = rw * scale;
    rrect.h = rh * scale;
    printf("rendering page:%d,%d,%d,%d\n",rrect.x,rrect.y,rrect.w,rrect.h);

	WILLUSBITMAP *dst = &kctx->src;
	bmp_init(dst);
	dst->width = rrect.w;
	dst->height = rrect.h;
	dst->bpp = 8;
	bmp_alloc(dst);
	if (dst->bpp == 8) {
		int ii;
		for (ii = 0; ii < 256; ii++)
		dst->red[ii] = dst->blue[ii] = dst->green[ii] = ii;
	}

	ddjvu_format_set_row_order(page->doc->pixelformat, 1);
	ddjvu_page_render(page->page_ref, 0, &prect, &rrect, page->doc->pixelformat,
		bmp_bytewidth(dst), (char *) dst->data);

	return 0;
}
Пример #4
0
/* write out nice info on the message,
 * and store in *user* data the info on progress.
 * */
int
process_message(ddjvu_message_t *message)
{

#if 0
   ddjvu_context_t* context= message->m_any.context;
#endif

   if (! message)
      return(-1);
#if DEBUG
   printf("*** %s: %s.\n",__FUNCTION__, message_tag_name(message->m_any.tag));
#endif


   switch (message->m_any.tag){
   case DDJVU_DOCINFO:
   {
      ddjvu_document_t* document= message->m_any.document;
      /* ddjvu_document_decoding_status  is set by libdjvu! */
      /* we have some info on the document  */
      LoadContext *lc = (LoadContext *) ddjvu_document_get_user_data(document);
      lc->pages = ddjvu_document_get_pagenum(document);
#if DEBUG
      printf("the doc has %d pages\n", ddjvu_document_get_pagenum(document));
#endif
      break;
   }
   case DDJVU_CHUNK:
#if DEBUG
           printf("the name of the chunk is: %s\n", message->m_chunk.chunkid);
#endif
           break;


   case DDJVU_RELAYOUT:
   case DDJVU_PAGEINFO:
   {
#if 0
      ddjvu_page_t* page = message->m_any.page;
      page_info* info = ddjvu_page_get_user_data(page);

      printf("page decoding status: %d %s%s%s\n",
             ddjvu_page_decoding_status(page),
             status_color, status_name(ddjvu_page_decoding_status(page)), color_reset);

      printf("the page LAYOUT changed: width x height: %d x %d @ %d dpi. Version %d, type %d\n",
             // printf("page info:\n width x height: %d x %d @ %d dpi, version %d, type %d\n",
             ddjvu_page_get_width(page),
             ddjvu_page_get_height(page),
             ddjvu_page_get_resolution(page),
             ddjvu_page_get_version(page),
             /* DDJVU_PAGETYPE_BITONAL */
             ddjvu_page_get_type(page));

      info->info = 1;
#endif
      break;
   }

   case DDJVU_REDISPLAY:
   {

#if 0
    ddjvu_page_t* page = message->m_any.page;
      page_info* info = ddjvu_page_get_user_data(page);

      printf("the page can/should be REDISPLAYED\n");
      info->display = 1;
#endif
      break;
   }

   case DDJVU_PROGRESS:
#if DEBUG
           printf("PROGRESS:\n");
#endif
           break;
   case DDJVU_ERROR:
           printf("simply ERROR!\n message:\t%s\nfunction:\t%s(file %s)\nlineno:\t%d\n",
                  message->m_error.message,
                  message->m_error.function,
                  message->m_error.filename,
                  message->m_error.lineno);
           break;
   case DDJVU_INFO:
#if DEBUG
           printf("INFO: %s!\n", message->m_info.message);
#endif
           break;
   default:
      printf("unexpected\n");
   };
  return(message->m_any.tag);
}
Пример #5
0
gint32
load_djvu (const gchar * filename, 
          GimpRunMode runmode, 
          gboolean preview)

{
  
  GimpPixelRgn rgn_in;
  GimpDrawable *drawable;
  gint32 volatile image_ID;
  gint32 layer_ID;
  int x1, y1, x2, y2, width, height;
   unsigned char *src = NULL;
  int file_length;



ctx = ddjvu_context_create("gimp");
//
doc = ddjvu_document_create_by_filename(ctx,filename, TRUE);



while (! ddjvu_document_decoding_done(doc))
    handle(TRUE);
  




  i = ddjvu_document_get_pagenum(doc);
  dialog( &pageno ,i);
//processing the page
  
page = ddjvu_page_create_by_pageno(doc, pageno-1);
while (! ddjvu_page_decoding_done(page))
    handle(TRUE);

if (ddjvu_page_decoding_error(page))
{
 fprintf(stderr,"unexpected error ");
 exit(10);
}

// ddjvu variables

  ddjvu_rect_t prect;
  ddjvu_rect_t rrect;
  ddjvu_format_style_t style;
  ddjvu_render_mode_t mode;
  ddjvu_format_t *fmt;
  int iw = ddjvu_page_get_width(page);
  int ih = ddjvu_page_get_height(page);
  int dpi = ddjvu_page_get_resolution(page);
  ddjvu_page_type_t type = ddjvu_page_get_type(page);
  char *image = 0;
  int rowsize;

//end of ddjvu variables
style= DDJVU_FORMAT_RGB24;
mode=DDJVU_RENDER_COLOR;
fmt = ddjvu_format_create(style, 0, 0);
ddjvu_format_set_row_order(fmt, 1);

      prect.w = iw;
      prect.h = ih;

       prect.x = 0;
       prect.y = 0;

       flag_scale=150;

     prect.w = (unsigned int) (iw * flag_scale) / dpi;
     prect.h = (unsigned int) (ih * flag_scale) / dpi;
       
      rrect = prect;

 rowsize = (rrect.w *3);
 image = (char*)malloc(rowsize * rrect.h);
  
//generating page
ddjvu_page_render(page, mode, &prect, &rrect, fmt, rowsize, image);

ddjvu_page_release(page);
char *s =image;
  /* create output image */

  width = prect.w;
  height =  prect.h;
  x1 = 0;
  y1 = 0;
  x2 = prect.w;
  y2 = prect.h;


  image_ID = gimp_image_new (width, height, GIMP_RGB);
  layer_ID = gimp_layer_new (image_ID, _("Background"),
			     width, height, GIMP_RGB, 100, GIMP_NORMAL_MODE);
  gimp_image_add_layer (image_ID, layer_ID, 0);
  drawable = gimp_drawable_get (layer_ID);	// initializes the drawable     
  gimp_drawable_mask_bounds (drawable->drawable_id, &x1, &y1, &x2, &y2);
  gimp_pixel_rgn_init (&rgn_in, drawable, x1, y1,
		       x2 - x1, y2 - y1, TRUE, TRUE);
  gimp_pixel_rgn_set_rect (&rgn_in,  image, 0, 0, width, height);
      //g_free (buf);
  gimp_drawable_flush (drawable);
  gimp_drawable_merge_shadow (drawable->drawable_id, TRUE);
  gimp_drawable_update (drawable->drawable_id, x1, y1, x2 - x1, y2 - y1);
  gimp_image_set_filename (image_ID, filename);
  return image_ID;
  image =NULL;
 

//not handling any error
if (doc)
    ddjvu_document_release(doc);
  if (ctx)
    ddjvu_context_release(ctx);
    
}
Пример #6
0
JNIEXPORT jboolean JNICALL
Java_universe_constellation_orion_viewer_djvu_DjvuDocument_drawPage(JNIEnv *env, jobject thiz, jobject bitmap,
        float zoom,
		int pageW, int pageH, int patchX, int patchY, int patchW, int patchH)
{
	LOGI("==================Start Rendering==============");
	int ret;
	AndroidBitmapInfo info;
	void *pixels;
	int num_pixels = pageW * pageH;

	LOGI("Rendering page=%dx%d patch=[%d,%d,%d,%d]",
			pageW, pageH, patchX, patchY, patchW, patchH);
    LOGI("page: %x", page);

    LOGI("In native method\n");
    if ((ret = AndroidBitmap_getInfo(env, bitmap, &info)) < 0) {
        LOGE("AndroidBitmap_getInfo() failed ! error=%d", ret);
        return 0;
    }

    LOGI("Checking format\n");
    if (info.format != ANDROID_BITMAP_FORMAT_RGBA_8888) {
        LOGE("Bitmap format is not RGBA_8888 !");
        return 0;
    }

    LOGI("locking pixels\n");
    if ((ret = AndroidBitmap_lockPixels(env, bitmap, &pixels)) < 0) {
        LOGE("AndroidBitmap_lockPixels() failed ! error=%d", ret);
        return 0;
    }

			
    //float zoom = 0.0001f * zoom10000;
	
	int pageWidth =  ddjvu_page_get_width(page);
	int pageHeight = ddjvu_page_get_height(page);
	
    ddjvu_rect_t pageRect;
    pageRect.x = 0;
    pageRect.y = 0;
    pageRect.w = round(zoom * pageWidth);
    pageRect.h = round(zoom * pageHeight);
	LOGI("Original page=%dx%d patch=[%d,%d,%d,%d]",
			pageWidth, pageHeight, pageRect.x, pageRect.y, pageRect.w, pageRect.h);
    ddjvu_rect_t targetRect;
    targetRect.x = patchX;
    targetRect.y = patchY;
    targetRect.w = patchW;
    targetRect.h = patchH;
	
	int shift = 0;
	if (targetRect.x < 0) {
	   shift = -targetRect.x;
	   targetRect.w += targetRect.x;
	   targetRect.x = 0;
	}
	if (targetRect.y < 0) {
	    shift +=  -targetRect.y * pageW;
		targetRect.h += targetRect.y;
		targetRect.y = 0;
	}
	
	
	if (pageRect.w <  targetRect.x + targetRect.w) {
	  targetRect.w = targetRect.w - (targetRect.x + targetRect.w - pageRect.w);
	}
	if (pageRect.h <  targetRect.y + targetRect.h) {
	    targetRect.h = targetRect.h - (targetRect.y + targetRect.h - pageRect.h);
	}
	memset(pixels, 255, num_pixels * 4);
	 
	LOGI("Rendering page=%dx%d patch=[%d,%d,%d,%d]",
			patchW, patchH, targetRect.x, targetRect.y, targetRect.w, targetRect.h);
	 
    unsigned int masks[4] = { 0xff, 0xff00, 0xff0000, 0xff000000 };
    ddjvu_format_t* pixelFormat = ddjvu_format_create(DDJVU_FORMAT_RGBMASK32, 4, masks);

    LOGI("zoom=%f ", zoom);

    ddjvu_format_set_row_order(pixelFormat, TRUE);

    ddjvu_format_set_y_direction(pixelFormat, TRUE);

    char * buffer = &(((unsigned char *)pixels)[shift*4]);
    jboolean result = ddjvu_page_render(page, DDJVU_RENDER_COLOR, &pageRect, &targetRect, pixelFormat, pageW * 4, buffer);

	ddjvu_format_release(pixelFormat);

	orion_updateContrast((unsigned char *) pixels, num_pixels*4);
    AndroidBitmap_unlockPixels(env, bitmap);
	LOGI("...Rendered");
	
    return 1;
}
Пример #7
0
/*
** Returns 0 for success, negative number for error code.
** bpp can be 24 or 8.
**
*/
int bmpdjvu_djvufile_to_bmp(WILLUSBITMAP *bmp,char *infile,int pageno,
                            int dpi,int bpp,FILE *out)

    {
    ddjvu_context_t *ctx;
    ddjvu_document_t *doc;
    ddjvu_page_t *page;
    /* ddjvu_page_type_t type; */
    ddjvu_rect_t prect;
    ddjvu_rect_t rrect;
    ddjvu_format_style_t style;
    ddjvu_render_mode_t mode;
    ddjvu_format_t *fmt;
    int i,iw,ih,idpi,status;

    ctx=ddjvu_context_create("bmpdjvu_djvufile_to_bmp");
    if (ctx==NULL)
        {
        nprintf(out,"Cannot create djvu context.\n");
        return(-1);
        }
    doc=ddjvu_document_create_by_filename(ctx,infile,1);
    if (doc==NULL)
        {
        ddjvu_context_release(ctx);
        nprintf(out,"Cannot create djvu document context from djvu file %s.\n",
                infile);
        return(-2);
        }
    i=ddjvu_document_get_pagenum(doc);
    if (pageno<0 || pageno>i)
        {
        ddjvu_document_release(doc);
        ddjvu_context_release(ctx);
        nprintf(out,"Page number %d is out of range for djvu file %s.\n",pageno,infile);
        return(-3);
        }
    page=ddjvu_page_create_by_pageno(doc,pageno-1);
    if (page==NULL)
        {
        ddjvu_document_release(doc);
        ddjvu_context_release(ctx);
        nprintf(out,"Cannot parse page %d of djvu file %s.\n",pageno,infile);
        return(-4);
        }
    while (!ddjvu_page_decoding_done(page))
        handle(1,ctx);
    if (ddjvu_page_decoding_error(page))
        {
        ddjvu_page_release(page);
        ddjvu_document_release(doc);
        ddjvu_context_release(ctx);
        nprintf(out,"Error decoding page %d of djvu file %s.\n",pageno,infile);
        return(-5);
        }
    /* type= */ ddjvu_page_get_type(page);
    /*
    printf("type=%d\n",type);
    description=ddjvu_page_get_long_description(page);
    printf("Description='%s'\n",description);
    */
    iw = ddjvu_page_get_width(page);
    ih = ddjvu_page_get_height(page);
    idpi = ddjvu_page_get_resolution(page);
    prect.x=prect.y=0;
    bmp->width=prect.w=iw*dpi/idpi;
    bmp->height=prect.h=ih*dpi/idpi;
    bmp->bpp=(bpp==8) ? 8 : 24;
    rrect=prect;
    bmp_alloc(bmp);
    if (bmp->bpp==8)
        {
        int ii;
        for (ii=0;ii<256;ii++)
            bmp->red[ii]=bmp->blue[ii]=bmp->green[ii]=ii;
        }
    mode=DDJVU_RENDER_COLOR;
    style=bpp==8 ? DDJVU_FORMAT_GREY8 : DDJVU_FORMAT_RGB24;
    fmt=ddjvu_format_create(style,0,0);
    if (fmt==NULL)
        {
        ddjvu_page_release(page);
        ddjvu_document_release(doc);
        ddjvu_context_release(ctx);
        nprintf(out,"Error setting DJVU format for djvu file %s (page %d).\n",infile,pageno);
        return(-6);
        }
    ddjvu_format_set_row_order(fmt,1);
    status=ddjvu_page_render(page,mode,&prect,&rrect,fmt,bmp_bytewidth(bmp),(char *)bmp->data);
    ddjvu_format_release(fmt);
    ddjvu_page_release(page);
    ddjvu_document_release(doc);
    ddjvu_context_release(ctx);
    if (!status)
        {
        nprintf(out,"Error rendering page %d of djvu file %s.\n",pageno,infile);
        return(-7);
        }
    return(0);
    }
Пример #8
0
static int reflowPage(lua_State *L) {
	DjvuPage *page = (DjvuPage*) luaL_checkudata(L, 1, "djvupage");
	KOPTContext *kctx = (KOPTContext*) lua_topointer(L, 2);
	ddjvu_render_mode_t mode = (int) luaL_checkint(L, 3);
	ddjvu_rect_t prect;
	ddjvu_rect_t rrect;

	int px, py, pw, ph, rx, ry, rw, rh, status;

	px = 0;
	py = 0;
	pw = ddjvu_page_get_width(page->page_ref);
	ph = ddjvu_page_get_height(page->page_ref);
	prect.x = px;
	prect.y = py;

	rx = (int)kctx->bbox.x0;
	ry = (int)kctx->bbox.y0;
	rw = (int)(kctx->bbox.x1 - kctx->bbox.x0);
	rh = (int)(kctx->bbox.y1 - kctx->bbox.y0);

	double zoom = kctx->zoom*kctx->quality;
	float scale = ((2*zoom*kctx->dev_width) / (double)pw + \
			 	   (2*zoom*kctx->dev_height) / (double)ph) / 2;
	prect.w = pw * scale;
	prect.h = ph * scale;
	rrect.x = rx * scale;
	rrect.y = ry * scale;
	rrect.w = rw * scale;
	rrect.h = rh * scale;
	printf("rendering page:%d,%d,%d,%d\n",rrect.x,rrect.y,rrect.w,rrect.h);
	kctx->zoom = scale;

	WILLUSBITMAP *src = &kctx->src;
	bmp_init(src);
	src->width = rrect.w;
	src->height = rrect.h;
	src->bpp = 8;

	bmp_alloc(src);
	if (src->bpp == 8) {
		int ii;
		for (ii = 0; ii < 256; ii++)
		src->red[ii] = src->blue[ii] = src->green[ii] = ii;
	}

	ddjvu_format_set_row_order(page->doc->pixelformat, 1);

	status = ddjvu_page_render(page->page_ref, mode, &prect, &rrect, page->doc->pixelformat,
			bmp_bytewidth(src), (char *) src->data);

	if (kctx->precache) {
		pthread_t rf_thread;
		pthread_attr_t attr;
		pthread_attr_init(&attr);
		pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
		pthread_create(&rf_thread, &attr, k2pdfopt_reflow_bmp, (void*) kctx);
		pthread_attr_destroy(&attr);
	} else {
		k2pdfopt_reflow_bmp(kctx);
	}

	return 0;
}