Announcement

Collapse
No announcement yet.

[REQUEST] JPEG to C array

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • [REQUEST] JPEG to C array

    I am trying to create a new GUI for LDv3 using Gtlcpimp's drawing functions. However when I use bmp2c to convert a bitmap to a c array, the image loads up black and white with two identical images in different positions. It seems Gltcpimp made LDv3's GUI with jpeg images.

    Since I am not experienced with anything related to image files, could someone please point me to or create a JPEG to c array program/script? I would prefer if it was in the same format as bmp2c's outputs. Thanks.

    EDIT:
    Problem solved; I wrote a program, with some help from ORCXodus, that loads any image into a picture box and then grabs each pixel from the PBox and makes an array from it. The reason it is called "640x480 to C" is because that is the only image size supported right now. I may update it to make any image of any size compatible.
    Attached Files
    Last edited by dnawrkshp; 02-25-2013, 04:58:14 AM. Reason: Problem solved

  • #2
    How large (in pixels) is the image you're using? I think there's a limit in bmp2c, after which the results can be unpredictable.

    I don't think it should matter whether gtlc used BMPs or JPGs, since a C array is a C array...unless I'm forgetting something.

    gtlc did use some nonstandard features - I believe he made a modified version of my modified version of Tony Saveski/DreamTime's graphics lib (G2), for one thing. As a matter of fact, it shouldn't stray too far from bmp2c if that's what he used for LDv3, since G2 relies on bmp2c for its C arrays.

    Sorry my answer wasn't simply "Yes, here's a JPG to C array app" :P It may be of some use to take a look at libjpg in the PS2SDK, since it's basically converting JPG data to pixel arrays anyway.
    I may be lazy, but I can...zzzZZZzzzZZZzzzZZZ...

    Comment


    • #3
      It is 900 kb in size, and the original JPEG that Gltcpimp used is 217 kb. Not sure if it matters, but I have to use a 24 bit BMP for bmp2c to accept the file.

      I will take a look at it and see if I can port it to Windows C++. That would be nice.

      Comment


      • #4
        I believe I have figured it out, and I will report my findings once I have fully tested it.

        My idea is that Gltcpimp's functions load the enter C array and parses through 3 bytes at a time (RGB). However bmp2c converts formats the data as 0x00RGB, not RGBR, GBRG... So there are a ton of 0x00's being loaded, which would explain the black and white effect.

        I also did a bit of math as well, and it proves I am right in theory. The array size for Gtlcpimp's background is 921600 bytes long. I, along with help from ORCXodus have created a VB6 program that loads an image into a picturebox and then reads through each pixel and stores the RGB in a string. I set it up so that the size of the array would be in terms of 4 bytes, not 1. That returns 307200, which is not 1/4 of 921600... However, since only 3/4 of every 4 bytes are actual RGB values, I multiplied 307200 by 0.75 and got 230400. That is 1/4 of 921600.

        Now to test it...

        Comment


        • #5
          WORKED! I had to convert the RGB from Big Endian to Little Endian and remove the 0x00's at the beginning of every 4 bytes. Going to add some error detection and hand the app out.

          At this point it only takes images that are 640 x 480, but it can take any image type. Maybe in the future I will make it dynamically load up any image of any frame size.
          Last edited by dnawrkshp; 02-25-2013, 04:59:58 AM.

          Comment


          • #6
            Nice detective work Let us know when you've fine-tuned the app for release.
            I may be lazy, but I can...zzzZZZzzzZZZzzzZZZ...

            Comment


            • #7
              Of course. If you haven't already noticed; I have implemented a few new features into LDv3 on this thread: http://gamehacking.org/vb/threads/72...bug-Mod-Update
              Last edited by dnawrkshp; 02-25-2013, 08:48:18 PM.

              Comment


              • #8
                A Question,Do You Start The Value Search From The Left Or Right?,I Can Never Get This To Search Like I Want I To.

                Comment


                • #9
                  If you wanted to search for a value of 2, the value in LDv3 would look like this: 00000000000000000000000000000002.
                  If you wanted to search for a 64 bit hexadecimal value of 0x123456789ABCDEF0, the value would like this: 0000000000000000123456789ABCDEF0. With this the bit should be set to 64.

                  So in short, you search from the right. It would require more code to flip it around, and to be honest, it really doesn't matter that much. With the mod I made for it; you can press the select button to jump to the right most value.
                  Last edited by dnawrkshp; 02-25-2013, 09:59:32 PM.

                  Comment


                  • #10
                    Thanks For The Info,Not Sure Why I Have Two Of The Same Posts?

                    Comment

                    Working...
                    X