Working with JPEG format, but not jpg file...

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Samishii23
    New Member
    • Sep 2009
    • 246

    Working with JPEG format, but not jpg file...

    A project I am working on has me thinking of going two ways, 1) Use own "In House" images with come with the end product, or 2) Using a proprietary image format from the producers of the program my project is based on.

    The image format is a RGBA image format. Though I have heard of it based off of JPEG libraries.

    This is the header struct:
    Code:
    struct BLP2Header
    {
        FourCC      ID; // Always 'BLP2'
        UInt32      Type;
        UInt8       Encoding;
        UInt8       AlphaDepth;
        UInt8       AlphaEncoding;
        UInt8       HasMips;
        UInt32      Width;
        UInt32      Height;+7
        UInt32      Offsets[16];
        UInt32      Lengths[16];
        ARGBColor8  Palette[256];
    };
    
    Type
        0: JPEG compression
        1: Uncompressed or DirectX compression
    
    Encoding
        1: Uncompressed
        2: DirectX compression
    
    AlphaDepth
        0: No alpha channel
        1: 1 bit alpha
        4: 4 bit alpha (DXT3 only)
        8: 8 bit alpha
    
    AlphaEncoding
        0: DXT1 alpha (0 or 1 bit alpha)
        1: DXT2/3 alpha (4 bit alpha)
        7: DXT4/5 alpha (interpolated alpha)
    
    HasMips
        0: No mip levels
        1: Mip levels present (the number of levels is determined by the image size)
    
    Width, Height: Dimensions of the image in pixels (always a power of two)
    
    Offsets[0]: Offset from the start of the file to the image data
    Lengths[0]: Length in bytes of the image data
    Palette: 4-byte BGRA color values for paletted textures (this field is present regardless of whether the texture actually uses palettes)
    I'm not familar enough with the more advanced aspects of C# to know where to begin with this. Or how to go about it.

    Please an suggestions?
  • RedSon
    Recognized Expert Expert
    • Jan 2007
    • 4980

    #2
    I am not familiar enough with your question to understand what you are talking about. There are image libraries available in C# for you to use to manipulate images. Why would you re-invent the wheel?

    Comment

    • Samishii23
      New Member
      • Sep 2009
      • 246

      #3
      My problem isn't simply working with another image file. Its not a supported file type, and I don't think simply calling the image would display anything useful in the program besides an Unsupported Type exception.

      I was just wondering if there was a way in .NET to possible read that above header information for a binary level. I've seen libraries for the file format with programs out there, but I don't have the necessary information on the library to be able to use it for my project. I was wondering if anyone knew where I should begin.
      Last edited by Samishii23; Jan 25 '10, 07:03 PM. Reason: typos

      Comment

      • RedSon
        Recognized Expert Expert
        • Jan 2007
        • 4980

        #4
        What is the file format?

        Comment

        • Samishii23
          New Member
          • Sep 2009
          • 246

          #5
          .blp
          Its a proprietary image format from Blizzard Inc.. Its used in alot of their 3D graphics and modeling. It uses a RBGA format based on jpeg library I believe.

          Its about all I know about the format.
          I posted the header information above.

          Comment

          • RedSon
            Recognized Expert Expert
            • Jan 2007
            • 4980

            #6
            I'm not sure... you can try:

            Comment

            • Samishii23
              New Member
              • Sep 2009
              • 246

              #7
              Refer to post #3.

              I do have that program, however. I would like to be able to use said files in my own programs. And I can't just port a .dll without knowing what methods are in it. If I did alot of things would be easier.

              Comment

              • Plater
                Recognized Expert Expert
                • Apr 2007
                • 7872

                #8



                You could parse the data yourself. You can read the header and setup a new Bitmap object from it.
                Then you can scan through the image data building the correct pixel/color combinations from it and drawing them onto your Bitmap object.
                It will not be easy.

                Comment

                • RedSon
                  Recognized Expert Expert
                  • Jan 2007
                  • 4980

                  #9
                  Yea, what he said, plus:

                  Good luck.

                  Comment

                  • Samishii23
                    New Member
                    • Sep 2009
                    • 246

                    #10
                    Hmm, your right thats alot of work.
                    Is it possible to get a push in the right direction?
                    My concern, is that because of my lack of experience. I don't know where to begin... Though reading the header of the file is the 1st step. Thats my problem. I have not an idea how to begin.
                    Once I know where to start the digging I should be able to carry my own weight.

                    Thank you in advance.

                    Comment

                    • Plater
                      Recognized Expert Expert
                      • Apr 2007
                      • 7872

                      #11
                      Well I think learning how to make the header struct correctly in managed code would be good.
                      Will need to look into StructLayout and Marshalling.
                      Since I happen to know first hand how difficult it is to find information on it, here's the struct:
                      [code=c#]
                      [StructLayout(La youtKind.Sequen tial, Pack = 1, CharSet = CharSet.Ansi)]
                      public struct BLP2Header
                      {
                      [MarshalAs(Unman agedType.ByValT Str, SizeConst = 4)]
                      public string ID;//FourCC = 4 character codes
                      public UInt32 Type;
                      public byte Encoding;
                      public byte AlphaDepth;
                      public byte AlphaEncoding;
                      public byte HasMips;
                      public UInt32 Width;
                      public UInt32 Height;//+7
                      [MarshalAs(Unman agedType.ByValA rray, SizeConst = 16)]
                      public UInt32[] Offsets;
                      [MarshalAs(Unman agedType.ByValA rray, SizeConst = 16)]
                      public UInt32[] Lengths;
                      [MarshalAs(Unman agedType.ByValA rray, SizeConst = 256)]
                      public byte[] Palette;
                      }
                      [/code]

                      Now look into how you can marshal the first 404 bytes of the file into that header struct

                      Comment

                      • Darky28
                        New Member
                        • Mar 2010
                        • 1

                        #12
                        I already wrote a C# lib for blp images

                        Howdy

                        I've already wrote a perfectly working C# lib (all managed) for asp.net that handles the blp image format.

                        At this point its a read lib.. so you can only load blps and display / convert em to gif / tiff / png e.t.c... but not convert something into blp.

                        Greets

                        Chris

                        If your interrested in the lib drop me a message in MSN: DELETED

                        Comment

                        • Samishii23
                          New Member
                          • Sep 2009
                          • 246

                          #13
                          H3ll yes I'm interested... I have added your contact info. Hope to catch you online.

                          Comment

                          • RedSon
                            Recognized Expert Expert
                            • Jan 2007
                            • 4980

                            #14
                            Do not post your email address. If you want to share email information use the PM feature of this site.

                            Comment

                            Working...