5 Replies Latest reply: Aug 23, 2011 8:54 AM by Dave Merchant RSS

    3D JavaScript: I cannot create Image object from embedded JPEG file

    A. Grahn Community Member

      I'd like to create an Image object from an embedded JPEG file (as FileSpec object, referenced in the Resources Name tree of the 3D stream object), later to be used as canvas background. Unfortunately, the image object created has zero dimension and cannot be used further:

       

      res = new Resource('pdf://sunset.jpg');

      host.console.println(res.type);  //ok. outputs 'image'


      img = new Image(res);

      host.console.println(img.width+' '+img.height); //not ok. outputs '0 0'

       

      However, if the image is embedded as an Image XObject in the PDF which is referenced instead of  the FileSpec dictionary in the Resources Name tree, the code works and the Image object has nonzero size.

       

      Is this intended behaviour? I am asking because the 3D JavaScript API states that Image objects can be created from embedded File resources.

       

      Thanks for any comment,

      Alexander

        • 1. Re: 3D JavaScript: I cannot create Image object from embedded JPEG file
          Dave Merchant CommunityMVP

          Your bitmaps must be attached as Resources of the 3D annotation - it sounds like you're creating the PDF with third-party tools, in which case if there are any errors in the structure of the tags you're building, you will get the error as you're seeing it (you can create a Resource from anything provided there's a matching name, but you can only create an Image from that Resource if the Cos object exactly matches the specs - if creation of the Image fails you get a 0x0 "image" with zero color depth, corresponding to the prototype of the Image object).

           

          Suggest you inspect your PDF's Cos tree (via Preflight) and compare it to a 3D scene with Resources created using the Acrobat Pro dialogs. Something will be different, but i can't predict what.

          • 2. Re: 3D JavaScript: I cannot create Image object from embedded JPEG file
            A. Grahn Community Member

            Thanks, Dave, for your reply.

            Your bitmaps must be attached as Resources of the 3D annotation

            This I did. Something becomes a resource if it is referenced in the Assets Name Tree of the RichMediaContent directory. Names are matching. The step of creating the Resource is working. But creating the Image Object fails if the Resource was created from embedded file stream, but succeeds  if the Resource was created from XObject. Perhaps, for creating the Image Object, JavaScripts needs the info about image size/colour depth etc. stored in the Image XObject dictionary. Such information is not present in the dict of the EmbeddedFile stream:

             

            6 0 obj
            <<
            /Type /Annot
            /Subtype /RichMedia
            /Rect [133.92 564.12 236.88 667.2]
            /RichMediaContent 23 0 R
            /RichMediaSettings 24 0 R

            ...

            >>
            endobj


            23 0 obj 
            <<
            /Assets
            <<
            /Names [(dice.u3d) 14 0 R (sunset.jpg) 15 0 R]
            >>
            ...
            >>
            endobj


            sunset.jpg as Image XObject works; it can be loaded by JavaScript:


            15 0 obj
            <<
            /ColorSpace /DeviceRGB
            /Subtype /Image
            /Filter /DCTDecode
            /Length 6817
            /Width 320
            /Height 308
            /BitsPerComponent 8
            >>
            stream
            ÿØÿî...

            ....

            endstream

            endobj

             

            alternatively:

            sunset.jpg as Filespec ->EmbeddedFile; cannot be loaded by JavaScript: Image Object is 0 x 0:


            15 0 obj
            <<
            /EF
            <<
            /F 16 0 R
            >>
            /F (sunset.jpg)
            /Type /Filespec
            /UF (sunset.jpg)
            >>
            endobj

             

            16 0 obj

            <<

            /Length 6817
            >>
            stream
            ÿØÿî...

            ....

            endstream

            endobj

             

            Yes, I'am using a third party tool (pdfTeX) for pdf creation. BTW, does AA-X use the RichMedia annot for 3D or still the old 3D annot of AA-7? Thanks once more for your answer!

             

            Alexander

            • 3. Re: 3D JavaScript: I cannot create Image object from embedded JPEG file
              Dave Merchant CommunityMVP

              Correct - it needs those tags. Here's a screenshot of the structure when you use Acrobat Pro (one 3D scene, one Resource added, "bitmap.jpg") - as you can see the image is stored as an XObject, with the 3D model data elsewhere in the tree (the Binary Stream above the 3DV entry)

               

              pf-res.jpg

               

               

               

              3D annotations in Acrobat 9 and X are stored using the spec in part 9.5 of ISO 320000/1.7EL3 - they're similar to Rich Media Annotations, but not exactly equivalent. However if you add a SWF file to a 3D annotation's Resource table, the entire annot is repacked as a Rich Media Annotation (/T:Annot /S:RichMedia) with the 3D model and Resources both stored as FileSpec objects in the Assets library. Entries in the RichMediaSettings tree tell the renderer that it's still a 3D scene, but we need to switch containers like this as a 3D annot has limited support for non-Image Resources.

               

              pf-res-rma.jpg

              • 4. Re: 3D JavaScript: I cannot create Image object from embedded JPEG file
                A. Grahn Community Member

                Thanks a lot for clarification!

                 

                And thanks that you mentioned SWF. I am able to attach an SWF as a resource (Filespec) but cannot make use of it (trough 3D JavaScript). I tried to create a FlashMovie object from the Resource and then use it with the scene.addFlashForeground method. But I cannot see an effect within the 3D scene. What would be a typical use of an SWF resource in 3D context? Could you please give a short JavaScript example on how to make use of an SWF resource?

                 

                Thanks in advance

                Alexander