Custom Decoder for JBig2

11 posts, 1 answers
  1. Arnaud
    Arnaud avatar
    25 posts
    Member since:
    Jan 2013

    Posted 16 Apr 2014 Link to this post

    Hello
    I am working on JBIG2DecodeFilter and I need some help
    I have read this thread and this article in the documentation and I have write this class
    01.public class JBIG2DecodeFilter : IPdfFilter
    02.{
    03.        private JBIG2StreamDecoder jBig2Decoder =  new JBIG2StreamDecoder();
    04. 
    05.        public byte[] Encode(PdfObject encodedObject, byte[] inputData)
    06.        {
    07.            throw new NotImplementedException();
    08.        }
    09. 
    10.        public byte[] Decode(PdfObject decodedObject, byte[] inputData, DecodeParameters parms)
    11.        {
    12. 
    13.            Debug.WriteLine("You are now in the Decode method of JBIG2Decode");  
    14.            byte[] tiffData = jBig2Decoder.decodeJBIG2(inputData, ImageFormat.TIFF);
    15.            System.IO.File.WriteAllBytes("c:\\image.tiff", tiffData);
    16. 
    17.            return tiffData;         
    18.        }
    19. 
    20.        public string Name { get { return "JBIG2Decode"; }
    21.}
    I success to convert jbig2 images of my PDF in tiff format (my "image.tiff" is correctly displayed in XnView) and now I need to convert my tiff image to the correct format for the pdfViewer
    I try to use CCITTFaxDecode but is an internal class.
    How I can convert my Tiff image ?
    Thanks
  2. Kammen
    Admin
    Kammen avatar
    312 posts

    Posted 16 Apr 2014 Link to this post

    Hi Arnaud,

    Thank you for contacting us.

    The CCITTFaxDecode filter has its limitations as well and that is why we do not recommend to use it. Moreover, converting from one format to another will slow your application unnecessary. The best way to use this decoder is to access the raw data (for example pixels) and return it as a byte array as described in the end of the this article.

    It can be useful for us if you are able to tell us more about the capabilities of the JBIG2StreamDecoder you are using.

    We are looking forward to your reply.

    Regards,
    Kammen
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. DevCraft banner
  4. Arnaud
    Arnaud avatar
    25 posts
    Member since:
    Jan 2013

    Posted 16 Apr 2014 in reply to Kammen Link to this post

    Hi Kammen
    JBIG2StreamDecoder can directly decode jbig2 byte array to a tiff byte array (or jpeg) 
    But it's not the correct byte array expected by pdfViewer.
    At the end of your article you specify "The resulting byte array should contain exactly BitsPerComponent bits " my PdfObject expect a ColorSpace=Gray and BitsPerComponent=1, my byte array to return contain 1 dimension.
    I am aware converting from one format to another will slow my application unnecessary butI do not have the skills for converting directly and I search a solution.
    Thanks in advance
  5. Answer
    Kammen
    Admin
    Kammen avatar
    312 posts

    Posted 17 Apr 2014 Link to this post

    Hello Arnaud,

    We will consider you request about making the PdfFiters public.

    Until then you can use some third party library to get the pixels from the image you have already converted.

    We are sorry for the inconvenience.

    Regards,
    Kammen
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  6. Arnaud
    Arnaud avatar
    25 posts
    Member since:
    Jan 2013

    Posted 24 Apr 2014 in reply to Kammen Link to this post

    Hello Kammen
    For information, I success to implement a JBig2 filter.
    I have dump this code link and I recreate a project (one for WPF and one for SL) with a lot of change I create my Filter :
    public class JBIG2DecodeFilter : IPdfFilter
        {
            private JBIG2StreamDecoder jBig2Decoder =  new JBIG2StreamDecoder();
     
            public byte[] Encode(PdfObject encodedObject, byte[] inputData)
            {
                throw new NotImplementedException();
            }
     
            public byte[] Decode(PdfObject decodedObject, byte[] inputData, DecodeParameters parms)
            {
                return jBig2Decoder.decodeJBIG2(inputData);           
            }
     
            public string Name { get { return "JBIG2Decode"; } }
        }
    Thanks again for help
    Regards

    PS : How I can mark this thread resolved ?
  7. Arnaud
    Arnaud avatar
    25 posts
    Member since:
    Jan 2013

    Posted 24 Apr 2014 in reply to Arnaud Link to this post

    Sorry I found
  8. Arnaud
    Arnaud avatar
    25 posts
    Member since:
    Jan 2013

    Posted 24 Apr 2014 in reply to Arnaud Link to this post

    Sorry I found how
  9. Petya
    Admin
    Petya avatar
    975 posts

    Posted 24 Apr 2014 Link to this post

    Hello Arnaud,

    We're happy to hear you were able to implement the desired behavior. If you want to you can upload your code in our code libraries for the benefit of other users. Here are the instructions on how to create a code library.

    Should you encounter any issues or have additional questions feel free to get back to us.

    Regards,
    Petya
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
  10. Kristoffer Rødseth
    Kristoffer Rødseth avatar
    4 posts
    Member since:
    Mar 2010

    Posted 22 May 2014 in reply to Arnaud Link to this post

    Hi Arnaud,

    We are also in need of a custom filter for this, so your solution looks promising. When I take a look at your code it only seems to include the WPF library. If you could make the SL implementation available that would be greatly appreciated. 

    Regards,
    Kristoffer
  11. Arnaud
    Arnaud avatar
    25 posts
    Member since:
    Jan 2013

    Posted 26 Jun 2014 Link to this post

    Hi Kristoffer Rødseth and Petya
    I am sorry for the late.
    I post my project in code libraries, wait for validating.
    Regards
  12. Kammen
    Admin
    Kammen avatar
    312 posts

    Posted 26 Jun 2014 Link to this post

    Hello Arnaud,

    Thank you for uploading code library. We really appreciate your effort.

    Regards,
    Kammen
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
Back to Top
DevCraft banner