Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Graphics
  4. How to use GDI to convert these SPRs and MAPs files to bmp files, so I can invoke LoadImage function to load the bmp files and render them on my window by invoking the BitBlt function

How to use GDI to convert these SPRs and MAPs files to bmp files, so I can invoke LoadImage function to load the bmp files and render them on my window by invoking the BitBlt function

Scheduled Pinned Locked Moved Graphics
graphicshelpalgorithmsdata-structuresjson
5 Posts 3 Posters 6 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    EZCodeProject
    wrote on last edited by
    #1

    I have a set of SPRs and MAPs files in my harddisk, which I have uploaded all of them to OneDrive in the shared folder. You can download some of them or all of them from the following link: There is the link LoadImage fails to open these files directly, even though I change their extension to bmp, because they are not in the format of bmp, but I know for sure that these are image files and they are convertible to bmp files. In other words, there is a way or algorithm to convert all these files to bmp files, so LoadImage succeeds and BitBlt renders the images to my window. But the problem is that I don't know how to convert these files to bmp files. When I invoke CreateBitmap function, to create new 32 bit BGRA bitmap, open them by invoking the CreateFile function, reading all their bytes to an array of bytes, also called "buffer", by invoking ReadFile function, then CloseHandle, then SetBitmapBits or SetDIBits, and finally BitBlt (after CreateCompatibleDC and SelectObject), I see unclear image on my window. Later I figured out that these images are 8 bit color, in the SPR files, the first byte is the width of the image, and the second byte is the height of the image, and the rest of the bytes are the pixels of the image, each byte for each pixel. MAP files are always 320x200 pixels image, so all their bytes are the pixels of the MAP image itself, the same as in the SPR files. When I read one byte, I set all channels of the bitmap to this byte. Then BitBlt renders the bitmap and I can see the image clearly, but it is grayscaled. But I want to see it colorful. When I use 2 bits for Blue, 3 bits for Green and 3 bits for Red, I see the image in the wrong colors. I know how it suppose to look like in DOSBox. I need help about how to convert and correct the colors, rather than shape. Shape is fine. I want to convert the SPR and MAP images to 32 bit BGRA colorful and not grayscaled bitmap. That's my purpose.

    L J 2 Replies Last reply
    0
    • E EZCodeProject

      I have a set of SPRs and MAPs files in my harddisk, which I have uploaded all of them to OneDrive in the shared folder. You can download some of them or all of them from the following link: There is the link LoadImage fails to open these files directly, even though I change their extension to bmp, because they are not in the format of bmp, but I know for sure that these are image files and they are convertible to bmp files. In other words, there is a way or algorithm to convert all these files to bmp files, so LoadImage succeeds and BitBlt renders the images to my window. But the problem is that I don't know how to convert these files to bmp files. When I invoke CreateBitmap function, to create new 32 bit BGRA bitmap, open them by invoking the CreateFile function, reading all their bytes to an array of bytes, also called "buffer", by invoking ReadFile function, then CloseHandle, then SetBitmapBits or SetDIBits, and finally BitBlt (after CreateCompatibleDC and SelectObject), I see unclear image on my window. Later I figured out that these images are 8 bit color, in the SPR files, the first byte is the width of the image, and the second byte is the height of the image, and the rest of the bytes are the pixels of the image, each byte for each pixel. MAP files are always 320x200 pixels image, so all their bytes are the pixels of the MAP image itself, the same as in the SPR files. When I read one byte, I set all channels of the bitmap to this byte. Then BitBlt renders the bitmap and I can see the image clearly, but it is grayscaled. But I want to see it colorful. When I use 2 bits for Blue, 3 bits for Green and 3 bits for Red, I see the image in the wrong colors. I know how it suppose to look like in DOSBox. I need help about how to convert and correct the colors, rather than shape. Shape is fine. I want to convert the SPR and MAP images to 32 bit BGRA colorful and not grayscaled bitmap. That's my purpose.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      You cannot just read the files and expect the system to figure out what the content is. You need to reformat the data into proper bitmap structures before you can display them. See BITMAP structure (Windows)[^] .

      1 Reply Last reply
      0
      • E EZCodeProject

        I have a set of SPRs and MAPs files in my harddisk, which I have uploaded all of them to OneDrive in the shared folder. You can download some of them or all of them from the following link: There is the link LoadImage fails to open these files directly, even though I change their extension to bmp, because they are not in the format of bmp, but I know for sure that these are image files and they are convertible to bmp files. In other words, there is a way or algorithm to convert all these files to bmp files, so LoadImage succeeds and BitBlt renders the images to my window. But the problem is that I don't know how to convert these files to bmp files. When I invoke CreateBitmap function, to create new 32 bit BGRA bitmap, open them by invoking the CreateFile function, reading all their bytes to an array of bytes, also called "buffer", by invoking ReadFile function, then CloseHandle, then SetBitmapBits or SetDIBits, and finally BitBlt (after CreateCompatibleDC and SelectObject), I see unclear image on my window. Later I figured out that these images are 8 bit color, in the SPR files, the first byte is the width of the image, and the second byte is the height of the image, and the rest of the bytes are the pixels of the image, each byte for each pixel. MAP files are always 320x200 pixels image, so all their bytes are the pixels of the MAP image itself, the same as in the SPR files. When I read one byte, I set all channels of the bitmap to this byte. Then BitBlt renders the bitmap and I can see the image clearly, but it is grayscaled. But I want to see it colorful. When I use 2 bits for Blue, 3 bits for Green and 3 bits for Red, I see the image in the wrong colors. I know how it suppose to look like in DOSBox. I need help about how to convert and correct the colors, rather than shape. Shape is fine. I want to convert the SPR and MAP images to 32 bit BGRA colorful and not grayscaled bitmap. That's my purpose.

        J Offline
        J Offline
        Jochen Arndt
        wrote on last edited by
        #3

        According to SPR files | Creatures Wiki | Fandom powered by Wikia[^] the colour values are palette indexes:

        Quote:

        The actual image data is simply color indexes arranged into horizontal scanlines. The mappings between color indices and 256 RGB colors is given in the PALETTE.DTA[^] file; Multiply the red, green and blue results returned by 4 to gain the full colour range.

        If you don't have the palette file you can try to use the default palette provided in the link. So you have to load the SPR file into memory, create a bitmap of the same size, and set the bitmap pixels to the RGB values retrieved from the colour table using the colour index from the SPR pixels.

        E 1 Reply Last reply
        0
        • J Jochen Arndt

          According to SPR files | Creatures Wiki | Fandom powered by Wikia[^] the colour values are palette indexes:

          Quote:

          The actual image data is simply color indexes arranged into horizontal scanlines. The mappings between color indices and 256 RGB colors is given in the PALETTE.DTA[^] file; Multiply the red, green and blue results returned by 4 to gain the full colour range.

          If you don't have the palette file you can try to use the default palette provided in the link. So you have to load the SPR file into memory, create a bitmap of the same size, and set the bitmap pixels to the RGB values retrieved from the colour table using the colour index from the SPR pixels.

          E Offline
          E Offline
          EZCodeProject
          wrote on last edited by
          #4

          Strange. The game doesn't come with it's own palette file .DTA, and I have tried the default one, but the images are still in the wrong colors.

          J 1 Reply Last reply
          0
          • E EZCodeProject

            Strange. The game doesn't come with it's own palette file .DTA, and I have tried the default one, but the images are still in the wrong colors.

            J Offline
            J Offline
            Jochen Arndt
            wrote on last edited by
            #5

            I'm sorry that I can't help further because I don't know about your game. You can try to search the web for more information about the used colour tables and where they are stored.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups