Hi Albert

          Thank you for your suggestions. Sorry it was long gap since you
gave those suggestions. I was so busy after that.

- about "#include <png.h>". I don't know how to check for those in
configure/cmake files.
If any one can give me any ideas how to do, it will be really helpful. I
just check for #ENABLE_PNG and including it. I don't know whether it is
right or not.

- Other things I used valgrind for memory leaks. Still in some places like
"object.initDict(xref)" it is showing definitely leak some bytes.
  How to overcome those things. Not only in my code still in poppler some
places it is showing leaking memory for initDict(xref) or initArray(xref).
  But we cannot free those objects explicitly in our code, if we do like
that. If we delete like that that value for that dictionary key it is not
setting.

So is it fine?

Please kindly give suggestios.

Thank you all in advance.

--
A Srinivas









On Wed, Feb 16, 2011 at 1:30 AM, <[email protected]>wrote:

> Send poppler mailing list submissions to
>        [email protected]
>
> To subscribe or unsubscribe via the World Wide Web, visit
>        http://lists.freedesktop.org/mailman/listinfo/poppler
> or, via email, send a message with subject or body 'help' to
>        [email protected]
>
> You can reach the person managing the list at
>        [email protected]
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of poppler digest..."
>
>
> Today's Topics:
>
>   1. Re: Patch for embedding videos in to the pdf. (Albert Astals Cid)
>   2. Re: pdf import in Inkscap using poppler_glib and
>      poppler_cairo (Albert Astals Cid)
>   3. Re: Patch for embedding videos in to the pdf. (Albert Astals Cid)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Tue, 15 Feb 2011 19:13:09 +0000
> From: Albert Astals Cid <[email protected]>
> Subject: Re: [poppler] Patch for embedding videos in to the pdf.
> To: [email protected]
> Message-ID: <[email protected]>
> Content-Type: Text/Plain;  charset="us-ascii"
>
> A Dimarts, 15 de febrer de 2011, srinivas adicherla va escriure:
> > Hi all,
>
> Hi
>
> >
> >     I made a patch for embedding videos into the pdf file. I created a
> > Screen annotation, and add a Rendition action to it. For appearance I
> took
> > the image from the user (only accepting png), later I will do for others
> > also. I tested opening the embedded pdf files using Adobe and Foxit
> Reader
> > it was successfully opened for me. I tried for swf and mpg files.
> > I am asking the user to specify the image because there are lot of video
> > formats, so its time consuming for creating an image from the video frame
> > for all types. ( May be in the future i add that or anybody can help me
> in
> > that).
> >
> > I added the same in bugzilla.
>
> Bad idea, don't do this. Either do it here or in the bugzilla but not in
> both.
> In two places just makes more difficult to follow the dicussion.
>
> Albert
>
> >
> > Please give me suggestions to make this successful.
> >
> > Thanks in Advance.
> > A Srinivas
>
>
> ------------------------------
>
> Message: 2
> Date: Tue, 15 Feb 2011 19:23:42 +0000
> From: Albert Astals Cid <[email protected]>
> Subject: Re: [poppler] pdf import in Inkscap using poppler_glib and
>        poppler_cairo
> To: [email protected]
> Message-ID: <[email protected]>
> Content-Type: Text/Plain;  charset="iso-8859-1"
>
> A Dimarts, 15 de febrer de 2011, Pino Toscano va escriure:
> > Hi,
> >
> > Alle marted? 15 febbraio 2011, the Adib ha scritto:
> > > currently Inkscape uses poppler internal API to read in pdf files.
> > > Those API breaks/changes from time to time.
> > >
> > > Now I try importing pdf via poppler cairo surface and those cairo
> > > surface as svg backend. So far that works.
> > >
> > > But I do not have any control over the process:
> > > - I can not set bitmap dpi
> > > - I can not specify if text stays text or convert to path
> > > etc.
> > >
> > > Do you have any sugestions?
> >
> > What I proposed more than one year ago:
> > http://sourceforge.net/mailarchive/message.php?msg_id=24162410
>
> That'd work me too :D
>
> Also if your custom inkscape converter does not depend in inkscape i see no
> reason why we could not have it inside poppler too if you commit to
> maintaining it here (this way you'd be much safer to API changes)
>
> Albert
>
>
> ------------------------------
>
> Message: 3
> Date: Tue, 15 Feb 2011 19:50:51 +0000
> From: Albert Astals Cid <[email protected]>
> Subject: Re: [poppler] Patch for embedding videos in to the pdf.
> To: [email protected]
> Message-ID: <[email protected]>
> Content-Type: Text/Plain;  charset="us-ascii"
>
> A Dimarts, 15 de febrer de 2011, srinivas adicherla va escriure:
> > Hi all,
> >
> >     I made a patch for embedding videos into the pdf file. I created a
> > Screen annotation, and add a Rendition action to it. For appearance I
> took
> > the image from the user (only accepting png), later I will do for others
> > also. I tested opening the embedded pdf files using Adobe and Foxit
> Reader
> > it was successfully opened for me. I tried for swf and mpg files.
> > I am asking the user to specify the image because there are lot of video
> > formats, so its time consuming for creating an image from the video frame
> > for all types. ( May be in the future i add that or anybody can help me
> in
> > that).
> >
> > I added the same in bugzilla.
> >
> > Please give me suggestions to make this successful.
>
> Some quick things:
>  * You use png.h unconditionally that is not going to work, you need to use
> the proper defines to see if configure/cmake found it.
>  * FILE *f;; <- extra ;
>  * png_structp read_png;; <- again
>  * error(-1, "The file could not be recognized as a PNG file."); <-- You
> don't
> close f here
>  * You don't delete imgbuf
>  * Wihtout having any idea png_create_info_struct seems like you should
> call
> destroy afterwards in the structure it returns
>  * After
>   MemStream *imgStream = load_from_png (img_file, &imgXObj, xrefA);
>   if (!imgStream)
>     return gFalse;
>   you need to free all the Obj you've allocated
>  * I'm pretty sure
>   annotObj.dictSet("T", obj.initString(new GooString(video_name)));
>   annotObj.dictSet("Contents", obj.initString(new GooString(video_name)));
>   annotObj.dictSet("F", obj.initInt(4));
>   is leaking memory as Object is not supposed to be reused without freeing
> it
> first, please use valgrind to detect leaks in your code
>
> Albert
>
> >
> > Thanks in Advance.
> > A Srinivas
>
>
> ------------------------------
>
> _______________________________________________
> poppler mailing list
> [email protected]
> http://lists.freedesktop.org/mailman/listinfo/poppler
>
>
> End of poppler Digest, Vol 72, Issue 21
> ***************************************
>
Index: poppler-0.16.2/poppler/Annot.h
===================================================================
--- poppler-0.16.2/poppler/Annot.h	(revision 6)
+++ poppler-0.16.2/poppler/Annot.h	(working copy)
@@ -740,6 +740,7 @@
   AnnotAppearanceCharacs *getAppearCharacs() { return appearCharacs; }
   LinkAction* getAction() { return action; }
   Object* getAdditionActions() { return &additionAction; }
+  GBool SetAction(const char* video_file, const char* mimetype, const char* img_file);
 
  private:
   void initialize(XRef *xrefA, Catalog *catalog, Dict *dict);
Index: poppler-0.16.2/poppler/Annot.cc
===================================================================
--- poppler-0.16.2/poppler/Annot.cc	(revision 6)
+++ poppler-0.16.2/poppler/Annot.cc	(working copy)
@@ -62,6 +62,10 @@
 #include "Link.h"
 #include <string.h>
 
+#ifdef ENABLE_LIBPNG
+#include <png.h>
+#endif
+
 #define fieldFlagReadOnly           0x00000001
 #define fieldFlagRequired           0x00000002
 #define fieldFlagNoExport           0x00000004
@@ -4258,6 +4262,280 @@
 
 }
 
+static MemStream* load_from_png (const char* img_file, Object *imgXObj, XRef *xrefA) {
+  FILE *f;
+
+  if (!(f = fopen(img_file, "rb"))) {
+    error(-1, "Couldn't open file '%s'", img_file);
+    return NULL;
+  }
+
+  png_byte header[8];
+  fread(header, 1, 8, f);
+
+  if (png_sig_cmp(header, 0, 8)) {
+    fclose(f);
+    error(-1, "The file could not be recognized as a PNG file.");
+    return NULL;
+  }
+  
+  png_structp read_png;
+  if (!(read_png = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL))) {
+    fclose(f);
+    error(-1, "png_create_read_struct");
+    return NULL;
+  }
+ 
+  png_infop info_png;
+  if (!(info_png = png_create_info_struct(read_png))) {
+    png_destroy_read_struct (&read_png, (png_infopp)NULL, (png_infopp)NULL);
+    fclose(f);
+    error(-1, "png_create_info_struct");
+    return NULL;
+  }
+  
+  if (setjmp(png_jmpbuf(read_png))) {
+    png_destroy_read_struct (&read_png, &info_png, (png_infopp)NULL);
+    fclose(f);
+    error(-1, "png_jmpbuf");
+    return NULL;
+  }
+  
+  png_init_io(read_png, f);
+  png_set_sig_bytes(read_png, 8);
+  png_read_info(read_png, info_png);
+
+  if (info_png->color_type & PNG_COLOR_MASK_ALPHA)
+    png_set_strip_alpha(read_png);
+
+  int width = info_png->width;
+  int height = info_png->height;
+  png_read_update_info(read_png, info_png);
+  
+  // Read the file
+  if (setjmp(png_jmpbuf(read_png))) {
+    png_destroy_read_struct (&read_png, &info_png, (png_infopp)NULL);
+    fclose(f);
+    error(-1, "png_jmpbuf");
+    return NULL;
+  }
+  
+  long numbytes = static_cast<long>(info_png->rowbytes * height);
+  char *img_buffer = static_cast<char*>(malloc(sizeof(char) * numbytes));
+  png_bytepp numrows = static_cast<png_bytepp>(malloc(sizeof(png_bytep)*height));
+
+  for(int i=0; i<height; i++) {
+    numrows[i] = reinterpret_cast<png_bytep>(img_buffer + (i * info_png->rowbytes));
+  }
+  
+  png_read_image(read_png, numrows);
+  png_read_end(read_png, NULL);
+ 
+  Object obj;
+ 
+  if (info_png->channels == 3)
+    imgXObj->dictSet("ColorSpace", obj.initName("DeviceRGB"));	  
+  else
+    imgXObj->dictSet("ColorSpace", obj.initName("DeviceGray"));	  
+  
+  imgXObj->dictSet("BitsPerComponent", obj.initInt(info_png->bit_depth));	  
+  imgXObj->dictSet("Width", obj.initInt(width));	  
+  imgXObj->dictSet("Height", obj.initInt(height));	  
+  imgXObj->dictSet("Length", obj.initInt(numbytes));
+  
+  MemStream *imgStream = new MemStream (img_buffer, 0, numbytes, imgXObj);
+  imgStream->setNeedFree(gTrue);
+
+  png_destroy_read_struct (&read_png, &info_png, (png_infopp)NULL);
+  delete numrows;
+
+  fclose(f);
+  return imgStream;
+}
+
+GBool AnnotScreen::SetAction(const char* video_file, const char* mimetype, const char* img_file) {
+  if (!video_file) {
+    error(-1, "Need to pass the video file");
+    return gFalse;
+  }
+  
+  if (!img_file) {
+    error(-1, "Need to pass the image for appearance");
+    return gFalse;
+  }
+   
+  FILE *fs; 
+  unsigned int size = 0;
+  if (!(fs = fopen(video_file, "rb"))) {
+    error(-1, "Couldn't open video file '%s'", video_file);
+    return gFalse;
+  }
+  fseek(fs, 0, SEEK_END);
+  size = ftell(fs);
+  fseek(fs, 0, SEEK_CUR); 
+  
+  // Extract the video name from the file uri 
+  const char *video_name = strrchr(video_file, '/');
+  video_name++;
+
+  Object obj1, obj2, obj3, obj4;
+ 
+  annotObj.dictSet("T", obj1.initString(new GooString(video_name))); // title
+  annotObj.dictSet("Contents", obj2.initString(new GooString(video_name))); // alternate text to be dispalyed for the annotation
+  annotObj.dictSet("F", obj3.initInt(4)); // No Zoom
+
+  Object formXObj;
+  formXObj.initDict(xref);
+
+  formXObj.dictSet("Type", obj1.initName("XObject"));
+  formXObj.dictSet("Subtype", obj1.initName("Form"));
+  Object bbox;
+  bbox.initArray(xref);
+  bbox.arrayAdd(obj1.initReal(0.0000));
+  bbox.arrayAdd(obj2.initReal(0.0000));
+  bbox.arrayAdd(obj3.initReal(1.0000));
+  bbox.arrayAdd(obj4.initReal(1.0000));
+  formXObj.dictSet("BBox", &bbox);
+  
+  Object imgXObj;
+  imgXObj.initDict(xref);
+  imgXObj.dictSet("Type", obj1.initName("XObject"));	  
+  imgXObj.dictSet("Subtype", obj1.initName("Image"));	  
+
+  // Load the stream from the png file
+  MemStream *imgStream = load_from_png (img_file, &imgXObj, xref);
+  if (!imgStream) {
+    obj1.free();
+    obj2.free();
+    obj3.free();
+    formXObj.free();
+    imgXObj.free();
+    return gFalse;
+  }
+  obj1.initStream(imgStream);
+  Ref imgRef = xref->addIndirectObject(&obj1);
+  
+  obj2.initDict(xref); // Image XObject
+  obj2.dictSet("Im1", obj3.initRef(imgRef.num, imgRef.gen));
+  obj4.initDict(xref);
+  obj4.dictSet("XObject", &obj2);
+
+  formXObj.dictSet("Resources", &obj4);
+  
+  GooString *newString = new GooString();	
+  newString->append("/Im1 Do");
+  formXObj.dictSet("Length", obj1.initInt(newString->getLength()));
+  
+  MemStream *fstream = new MemStream(copyString(newString->getCString()), 0, newString->getLength(), &formXObj);
+  fstream->setNeedFree(gTrue);
+  delete(newString);
+
+  obj1.initStream(fstream);
+  Ref appRef = xref->addIndirectObject(&obj1);
+
+  obj2.initDict(xref);
+  obj2.dictSet("N", obj3.initRef(appRef.num, appRef.gen));
+  annotObj.dictSet("AP", &obj2);
+
+  formXObj.initDict(xref);
+  formXObj.dictSet("Type", obj2.initName("XObject"));
+  formXObj.dictSet("Subtype", obj2.initName("Form"));
+
+  bbox.initArray(xref);
+  bbox.arrayAdd(obj1.initReal(0.0000));
+  bbox.arrayAdd(obj2.initReal(0.0000));
+  bbox.arrayAdd(obj3.initReal(1.0000));
+  bbox.arrayAdd(obj4.initReal(1.0000));
+  formXObj.dictSet("BBox", &bbox);
+  
+  obj2.initDict(xref);
+  obj2.dictSet("Im1", obj3.initRef(imgRef.num, imgRef.gen));
+  obj1.initDict(xref);
+  obj1.dictSet("XObject", &obj2);
+  formXObj.dictSet("Resources", &obj1);
+
+  newString = new GooString();	
+  newString->append("/Im1 Do");
+  formXObj.dictSet("Length", obj1.initInt(newString->getLength()));
+
+  fstream = new MemStream(copyString(newString->getCString()), 0, newString->getLength(), &formXObj);
+  fstream->setNeedFree(gTrue);
+  delete(newString);
+
+  obj1.initStream(fstream);
+  appRef = xref->addIndirectObject(&obj1);
+
+  obj2.initDict(xref); // MK dictionary
+  obj2.dictSet("I", obj3.initRef(appRef.num, appRef.gen));
+  annotObj.dictSet("MK", &obj2);
+  
+  // Rendition Action to be add
+  Object actionDict;
+  actionDict.initDict(xref);
+  actionDict.dictSet("Type", obj1.initName("Action"));
+  actionDict.dictSet("S", obj2.initName("Rendition"));
+  actionDict.dictSet("OP", obj3.initInt(0));
+  
+  // Media Rendition
+  Object MRendition;
+  MRendition.initDict(xref);
+  MRendition.dictSet("S", obj1.initName("MR"));
+  MRendition.dictSet("N", obj2.initString(new GooString(video_name)));
+  
+  // Media Clip Dictionary
+  Object MClipDict;
+  MClipDict.initDict(xref);
+  MClipDict.dictSet("S", obj1.initName("MCD"));
+  MClipDict.dictSet("N", obj2.initString(new GooString(video_name)));
+
+  if (mimetype)
+    MClipDict.dictSet("CT", obj3.initString(new GooString(mimetype)));
+
+  obj4.initString(new GooString("TEMPACCESS"));
+  obj1.initDict(xref);
+  obj1.dictSet("TF", &obj4);
+  MClipDict.dictSet("P", &obj1);
+  
+  // File Specification Dictionary
+  Object fsDict;
+  fsDict.initDict(xref);
+  fsDict.dictSet("Type", obj1.initName("Filespec"));
+  fsDict.dictSet("F", obj2.initName((char*)video_name));
+  fsDict.dictSet("UF", obj3.initName((char*)video_name));
+ 
+  obj3.initDict(xref); // file stream eictionary
+  obj3.dictSet("DL", obj1.initInt(size));  
+  obj3.dictSet("Length", obj2.initInt(size)); 
+ 
+  FileStream *stream = new FileStream(fs, 0, 0, size, &obj3);
+  obj1.initStream(stream);
+  
+  Ref newRef;
+  newRef = xref->addIndirectObject(&obj1);
+  obj2.initRef(newRef.num, newRef.gen);
+  obj1.initDict(xref);
+  obj1.dictSet("F", &obj2);
+  fsDict.dictSet("EF", &obj1);
+  
+  newRef = xref->addIndirectObject(&fsDict);
+  obj1.initRef(newRef.num, newRef.gen);
+  MClipDict.dictSet("D", &obj1);
+  
+  newRef = xref->addIndirectObject(&MClipDict);
+  obj1.initRef(newRef.num, newRef.gen);
+  MRendition.dictSet("C", &obj1);
+  
+  newRef = xref->addIndirectObject(&MRendition);
+  obj1.initRef(newRef.num, newRef.gen);
+  actionDict.dictSet("R", &obj1);
+  
+  newRef = xref->addIndirectObject(&actionDict);
+  obj1.initRef(newRef.num, newRef.gen);
+  annotObj.dictSet("A", &obj1);
+
+  return gTrue;
+}
+
 //------------------------------------------------------------------------
 // AnnotStamp
 //------------------------------------------------------------------------
Index: poppler-0.16.2/glib/poppler-annot.cc
===================================================================
--- poppler-0.16.2/glib/poppler-annot.cc	(revision 6)
+++ poppler-0.16.2/glib/poppler-annot.cc	(working copy)
@@ -332,7 +332,36 @@
   return poppler_annot;
 }
 
+/**
+ * poppler_annot_screen_new:
+ * @doc: a #PopplerDocument
+ * @rect: a #PopplerRectangle
+ *
+ * Creates a new Screen annotation that will be
+ * located on @rect when added to a page. See
+ * poppler_page_add_annot()
+ *
+ * Return value: A newly created #PopplerAnnotScreen annotation
+ *
+ */
+PopplerAnnot *
+poppler_annot_screen_new (PopplerDocument  *doc,
+                          PopplerRectangle *rect,
+                          const char* video_file,
+                          const char* mimetype,
+                          const char* png_img_file)
+{
+  AnnotScreen *annot;
+  PDFRectangle pdf_rect(rect->x1, rect->y1,
+                        rect->x2, rect->y2);
 
+  annot = new AnnotScreen (doc->doc->getXRef(), &pdf_rect, doc->doc->getCatalog());
+  if (annot->SetAction(video_file, mimetype, png_img_file))
+    return _poppler_annot_screen_new ((Annot*)annot);
+  else
+    return NULL;
+}
+
 /* Public methods */
 /**
  * poppler_annot_get_annot_type:
Index: poppler-0.16.2/glib/poppler-annot.h
===================================================================
--- poppler-0.16.2/glib/poppler-annot.h	(revision 6)
+++ poppler-0.16.2/glib/poppler-annot.h	(working copy)
@@ -218,6 +218,11 @@
 /* PopplerAnnotScreen */
 GType                         poppler_annot_screen_get_type                    (void) G_GNUC_CONST;
 PopplerAction                *poppler_annot_screen_get_action                  (PopplerAnnotScreen *poppler_annot);
+PopplerAnnot		     *poppler_annot_screen_new			       (PopplerDocument  *doc,
+										PopplerRectangle *rect,
+										const char* video_file,
+										const char* mimetype,
+										const char* png_img_file);
 
 /* PopplerCalloutLine */
 GType                         poppler_annot_callout_line_get_type              (void) G_GNUC_CONST;
_______________________________________________
poppler mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/poppler

Reply via email to