Example #1
0
static int openDocument(lua_State *L) {
	const char *filename = luaL_checkstring(L, 1);
	int cache_size = luaL_optint(L, 2, 10 << 20);

	DjvuDocument *doc = (DjvuDocument*) lua_newuserdata(L, sizeof(DjvuDocument));
	luaL_getmetatable(L, "djvudocument");
	lua_setmetatable(L, -2);

	doc->context = ddjvu_context_create("kindlepdfviewer");
	if (! doc->context) {
		return luaL_error(L, "cannot create context");
	}

	//printf("## cache_size = %d\n", cache_size);
	ddjvu_cache_set_size(doc->context, (unsigned long)cache_size);

	doc->doc_ref = ddjvu_document_create_by_filename_utf8(doc->context, filename, TRUE);
	if (! doc->doc_ref)
		return luaL_error(L, "cannot open DjVu file <%s>", filename);
	while (! ddjvu_document_decoding_done(doc->doc_ref))
		handle(L, doc->context, True);

	doc->pixelformat = ddjvu_format_create(DDJVU_FORMAT_GREY8, 0, NULL);
	if (! doc->pixelformat) {
		return luaL_error(L, "cannot create DjVu pixelformat for <%s>", filename);
	}
	ddjvu_format_set_row_order(doc->pixelformat, 1);
	ddjvu_format_set_y_direction(doc->pixelformat, 1);
	/* dithering bits <8 are ignored by djvulibre */
	/* ddjvu_format_set_ditherbits(doc->pixelformat, 4); */

	return 1;
}
Example #2
0
	void Plugin::Init (ICoreProxy_ptr)
	{
		Context_ = ddjvu_context_create ("leechcraft");
		ddjvu_message_set_callback (Context_, MsgCallback, this);

		DocMgr_ = new DocManager (Context_, this);
	}
Example #3
0
extern "C" jlong
Java_org_vudroid_djvudroid_codec_DjvuContext_create(JNIEnv *env,
                                    jclass cls)
{
	ddjvu_context_t* context = ddjvu_context_create(DJVU_DROID);
	DEBUG_PRINT("Creating context: %x", context);
	return (jlong) context;
}
Example #4
0
int main(int argc, char *argv[])
{
	ddjvu_context_t *djvu_test;
	(void)argc;

	djvu_test = ddjvu_context_create(argv[0]);
	ddjvu_context_release(djvu_test);

	return 0;
}
void guFolderInspector::extractIsbnsFromDjvu(QString fileName, QList<QString> &ISBNList)
{
    ctx = ddjvu_context_create("lgUploader"); //ddjvu_document_create_by_filename
    doc = ddjvu_document_create_by_filename_utf8(ctx, fileName.toUtf8(), 1);
    while (! ddjvu_document_decoding_done(doc));
    int  numOfPages = ddjvu_document_get_pagenum(doc); //количество страниц - строго!
    //QByteArray b = QFile::encodeName(fileName);
    //doc = ddjvu_document_create_by_filename(ctx, b, 1);
    if(!doc)
        qDebug() << "error create doc";
    if(!ctx)
        qDebug() << "error create context";


    const char *lvl = "page";
    //начало перебора по страницам
    isbnMethods find;
    int numOfSearchPages = 15;
    //qDebug() << "num of pages " << numOfPages;
    if(numOfPages < numOfSearchPages)
    {
        numOfSearchPages = numOfPages;
    }
    for (int pageCount = 0 ; pageCount < numOfSearchPages ; pageCount++)
    {

        miniexp_t r = miniexp_nil;
        while ((r = ddjvu_document_get_pagetext(doc, pageCount ,lvl))==miniexp_dummy);
        r = miniexp_nth(5, r);
        //if ( r == miniexp_nil )
        //    qDebug() << "r = null";
        const char *pageDumpArr = miniexp_to_str( r );
        QString pageDump( QString::fromUtf8( pageDumpArr ));

        find.findIsbns(pageDump, ISBNList);

        //qDebug() << fileName << " content: \n" <<  pageDump ;
    }
    //конец перебора по страницам
    if (doc)
        ddjvu_document_release(doc); //освобождаем контекст документа
    if (ctx)
        ddjvu_context_release(ctx); //освобождаем контескт приложени¤ (возможно стоит оставить)

}
Example #6
0
JNIEXPORT int JNICALL
Java_universe_constellation_orion_viewer_djvu_DjvuDocument_openFile(JNIEnv * env, jobject thiz, jstring jfileName)
{  
	page = NULL;
	context = ddjvu_context_create("orion");
	const char * fileName = (*env)->GetStringUTFChars(env, jfileName, 0);

	LOGI("Opening document: %s", fileName);
	doc = ddjvu_document_create_by_filename_utf8(context, fileName, 0);
	LOGI("Doc opened: %x", doc);

	int pageNum = 0;
	
	if (doc) {
		pageNum =  ddjvu_document_get_pagenum(doc);
	}

	LOGI("Page count = %i", pageNum);

	return 	pageNum;
}
Example #7
0
/*
** Returns >0  for success, negative number for error code.
*/
int bmpdjvu_numpages(char *infile)

    {
    ddjvu_context_t *ctx;
    ddjvu_document_t *doc;
    int i;

    ctx=ddjvu_context_create("bmpdjvu_numpages");
    if (ctx==NULL)
        return(-1);
    doc=ddjvu_document_create_by_filename(ctx,infile,1);
    if (doc==NULL)
        {
        ddjvu_context_release(ctx);
        return(-2);
        }
    i=ddjvu_document_get_pagenum(doc);
    ddjvu_document_release(doc);
    ddjvu_context_release(ctx);
    return(i);
    }
Model::Document* DjVuPlugin::loadDocument(const QString& filePath) const
{
    ddjvu_context_t* context = ddjvu_context_create("qpdfview");
    ddjvu_document_t* document = ddjvu_document_create_by_filename(context, QFile::encodeName(filePath), FALSE);

    if(document == 0)
    {
        ddjvu_context_release(context);

        return 0;
    }

    waitForMessageTag(context, DDJVU_DOCINFO);

    if(ddjvu_document_decoding_error(document))
    {
        ddjvu_document_release(document);
        ddjvu_context_release(context);

        return 0;
    }

    return new Model::DjVuDocument(context, document);
}
int
main(int argc, char **argv)
{
  int i;
  int optc = 0;
  char **optv;
  const char *infile = 0;
  const char *outfile = 0;
  FILE *fout;

  /* Sort options */
  if (! (optv = (char**)malloc(argc*sizeof(char*))))
    die(i18n("Out of memory"));
  for (i=1; i<argc; i++)
    {
      char *s = argv[i];
      if (s[0]=='-' && s[1]=='-')
        s = s+1;
      if (!strcmp(s,"-verbose"))
        verbose = true;
      else if (check_option(s))
        optv[optc++] = s;
      else if (s[0]=='-' && s[1])
        usage();
      else if (s[0] && !infile)
        infile = s;
      else if (s[0] && !outfile)
        outfile = s;
      else
        die(i18n("Incorrect arguments. Try option --help."));
    }
  if (! infile)
    infile = "-";
  if (! outfile)
    outfile = "-";
  /* Open document */
  if (! (ctx = ddjvu_context_create(argv[0])))
    die(i18n("Cannot create djvu context."));
  if (! (doc = ddjvu_document_create_by_filename(ctx, infile, TRUE)))
    die(i18n("Cannot open djvu document '%s'."), infile);
  while (! ddjvu_document_decoding_done(doc))
    handle(TRUE);
  /* Open output file */
  if (! strcmp(outfile,"-")) 
    {
      fout = stdout;
#if defined(__CYGWIN32__)
      setmode(fileno(fout), O_BINARY);
#elif defined(WIN32)
      _setmode(_fileno(fout), _O_BINARY);
#endif
    } 
  else if (! (fout = fopen(outfile, "wb")))
    die(i18n("Cannot open output file '%s'."), outfile);
  /* Create printing job */
  if (! (job = ddjvu_document_print(doc, fout, optc, optv)))
    die(i18n("Cannot create PostScript conversion job."));
  /* Wait until completion and cleanup */
  while (! ddjvu_job_done(job))
    handle(TRUE);
  if (verbose)
    fprintf(stderr,"\n");
  /* Make sure we get error messages */
  tryhelp = false;
  if (ddjvu_job_error(job))
    handle(FALSE);
  if (ddjvu_job_error(job))
    die(i18n("PostScript conversion job failed."));
  /* Close */
  fclose(fout);
  if (job)
    ddjvu_job_release(job);
  if (doc)
    ddjvu_document_release(doc);
  if (ctx)
    ddjvu_context_release(ctx);
  return 0;
}
Example #10
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);
    
}
Example #11
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);
    }
Example #12
0
zathura_error_t
djvu_document_open(zathura_document_t* document)
{
  zathura_error_t error = ZATHURA_ERROR_OK;

  if (document == NULL) {
    error = ZATHURA_ERROR_INVALID_ARGUMENTS;
    goto error_out;
  }

  djvu_document_t* djvu_document = calloc(1, sizeof(djvu_document_t));
  if (djvu_document == NULL) {
    error = ZATHURA_ERROR_OUT_OF_MEMORY;
    goto error_out;
  }

  /* setup format */
  static unsigned int masks[4] = {0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000};
  djvu_document->format = ddjvu_format_create(DDJVU_FORMAT_RGBMASK32, 4, masks);

  if (djvu_document->format == NULL) {
    error = ZATHURA_ERROR_UNKNOWN;
    goto error_free;
  }

  ddjvu_format_set_row_order(djvu_document->format, TRUE);

  /* setup context */
  djvu_document->context = ddjvu_context_create("zathura");

  if (djvu_document->context == NULL) {
    error = ZATHURA_ERROR_UNKNOWN;
    goto error_free;
  }

  /* setup document */
  djvu_document->document =
    ddjvu_document_create_by_filename(
        djvu_document->context,
        zathura_document_get_path(document),
        FALSE
    );

  if (djvu_document->document == NULL) {
    error = ZATHURA_ERROR_UNKNOWN;
    goto error_free;
  }

  /* load document info */
  ddjvu_message_t* msg;
  ddjvu_message_wait(djvu_document->context);

  while ((msg = ddjvu_message_peek(djvu_document->context)) &&
         (msg->m_any.tag != DDJVU_DOCINFO)) {
    if (msg->m_any.tag == DDJVU_ERROR) {
      error = ZATHURA_ERROR_UNKNOWN;
      goto error_free;
    }

    ddjvu_message_pop(djvu_document->context);
  }

  /* decoding error */
  if (ddjvu_document_decoding_error(djvu_document->document)) {
    handle_messages(djvu_document, true);
    error = ZATHURA_ERROR_UNKNOWN;
    goto error_free;
  }

  zathura_document_set_data(document, djvu_document);
  zathura_document_set_number_of_pages(document,
      ddjvu_document_get_pagenum(djvu_document->document));

  return error;

error_free:

  if (djvu_document->format != NULL) {
    ddjvu_format_release(djvu_document->format);
  }

  if (djvu_document->context != NULL) {
    ddjvu_context_release(djvu_document->context);
  }

  free(djvu_document);

error_out:

  return error;
}
Example #13
0
int
main(int argc, char **argv)
{
  /* Parse options */
  int i;
  for (i=1; i<argc; i++)
    {
      char *s = argv[i];
      if (s[0] == '-' && s[1] != 0)
        {
          char buf[32];
          const char *opt = s;
          const char *arg = strchr(opt, '=');
          if (*opt == '-')
            opt += 1;
          if (*opt == '-')
            opt += 1;
          if (arg)
            {
              int l = arg - opt;
              if (l > (int)sizeof(buf) - 1)
                l = sizeof(buf) - 1;
              strncpy(buf, opt, l);
              buf[l] = 0;
              opt = buf;
              arg += 1;
            }
          
          if (!strcmp(opt,"page") || 
              !strcmp(opt,"pages") )
            {
              if (!arg && i<argc)
                arg = argv[i++];
              if (!arg)
                die(i18n("option %s needs an argument."), s);
              if (pagespec)
                fprintf(stderr,i18n("warning: duplicate option --page=...\n"));
              pagespec = arg;
            }
          else if (!strcmp(opt, "detail"))
            {
              if (!arg)
                arg = "char";
              if (detail)
                fprintf(stderr,i18n("warning: duplicate option --detail.\n"));
              detail = arg;
            }
          else if (!strcmp(opt, "escape") && !arg)
            escape = 1;
          else
            die(i18n("unrecognized option %s."), s);
        }
      else if (!inputfilename)
        inputfilename = s;
      else if (! outputfilename)
        outputfilename = s;
      else
        usage();
    }
  
  /* Defaults */
  if (! inputfilename)
    usage();
  if (outputfilename)
    if (! freopen(outputfilename, "w", stdout))
      die(i18n("cannot open output file %s."), outputfilename);
  if (! pagespec)
    pagespec = "1-$";
  
  /* Create context and document */
  if (! (ctx = ddjvu_context_create(argv[0])))
    die(i18n("Cannot create djvu context."));
  if (! (doc = ddjvu_document_create_by_filename(ctx, inputfilename, TRUE)))
    die(i18n("Cannot open djvu document '%s'."), inputfilename);
  while (! ddjvu_document_decoding_done(doc))
    handle(TRUE);
  
  /* Process all pages */
  i = ddjvu_document_get_pagenum(doc);
  parse_pagespec(pagespec, i, dopage);
  
  /* Close */
  if (doc)
    ddjvu_document_release(doc);
  if (ctx)
    ddjvu_context_release(ctx);

  /* Return */
  minilisp_finish();  
  return 0;
}