| Author |
Message |
DF Veteran Ree-Yees
Joined: 24 Nov 2005
|
Posted: Jul 10, 2009 08:17 Post subject: Drawing BMs, FMEs, WAXs, etc |
|
|
Ok, so I am planning on making an all-purpose DF Texture editor. I've always wanted a quick and easy way to edit all of the files in DF. BmpDF is great, but it's a big hassle and you have to mess with a jumble of Bitmaps in the process.
Anyway, here is my question. Lucius, you probably know the answer to this, and some of the rest of you may as well. I started looking through the DF Specs and I understand most of it, but I don't understand how to get the pixels and the colors in the frames from the byte values given. Apparently they are encoded into columns, but do I take each byte and convert them to RGB values, or is each byte an offset of a color from some pallete? I have no clue.
I know that I have the right data for creating the image. I wrote a small test program to draw one frame of a Switch BM, but it's all gray and black colors. I compared it to the Bitmap that BmpDf spit out, and it's the same, just no RGB color.
|
|
sheepandshepherd Trandoshan
Joined: 01 Apr 2008
|
Posted: Jul 10, 2009 11:32 Post subject: |
|
|
I don't know much about file formats in DF, but I do know that the BMs use a separate pallete file, usually secbase.pal.
|
|
Lionel Fouillen Gamorrean
Joined: 27 Sep 2003
|
Posted: Jul 10, 2009 14:32 Post subject: |
|
|
I don't know if it is linked to your problem, but the CMP files in DARK.GOB are also involved in colors, although I never had to use them when creating new textures. They do however have an impact on the color of light. For example, the redish look-and-feel of Gromas Mines comes from that.
|
|
DF Veteran Ree-Yees
Joined: 24 Nov 2005
|
Posted: Jul 10, 2009 22:26 Post subject: |
|
|
I don't think I need a pallete from the game, because BmpDf doesn't need one. I could be wrong though.
Yah, the CMP file is pretty cool. I dinked around with the one from secbase and made some of the low colors look bluish gray. I was trying to create a fog looking effect like Matt H. did at one time. I was going to put it below a waterfall to simulate mist at the bottom. I gave it up, though. I got impatient. 
|
|
The MAZZTer Death Star

Joined: 25 Sep 2003
|
Posted: Jul 11, 2009 02:18 Post subject: |
|
|
Suggestion: Make your program in .NET if you know it. You have a complete wrapper around GDI and you get all the cool stuff, so you can load/save a bunch of different graphic formats.
Just a tip if you do: Learn how to use Bitmap.LockBits if you want to be able to read and write raw bitmap data at a reasonable speed (for loading/saving the DF image formats to/from a Bitmap object).
They got a code sample there but here's one which should be more helpful:
| Code: | Dim b As New Bitmap(128, 128, PixelFormat.Format32bppArgb)
' Sample test bitmap
Dim bd As Imaging.BitmapData = b.LockBits(New Rectangle(Point.Empty, b.Size), Imaging.ImageLockMode.WriteOnly, Imaging.PixelFormat.Format32bppArgb)
' We lock the ENTIRE bitmap (the rectangle covers it all) and we only need to write. The PixelFormat determines the format the raw data will be in, it doesn't have to be the same format as the image. ARGB is the most complete and easiest to work with. You can use Format24bppRgb if you don't need the alpha channel but keep in mind that you need to adjust the sample code since pixels will be 3 bytes instead of 4. Might be useful to use 8-bit Bitmap objects when working with DF stuff since it's easier to import and export DF objects, just keep in mind for 8-bit that pixels are 1 byte and the value is the offset into the Bitmap.Palette.Entries array.
Dim line As IntPtr = bd.Scan0
' Helper variable to help us keep track of the first byte in the current bitmap line. Scan0 points to the first byte of bitmap data.
Dim pixel As IntPtr = Nothing
' Helper variable to help us keep track of the first byte in the current pixel.
For i As Integer = 0 To bd.Height - 1
' For each row
pixel = line
' First pixel starts at the beginning of the line
For j As Integer = 0 To bd.Width - 1
' For each pixel in a row
Runtime.InteropServices.Marshal.WriteByte(col, 0, 255)
' 0 offset is the RED value in ARGB, set it to full color
Runtime.InteropServices.Marshal.WriteByte(col, 1, 0)
' 1 offset is the GREEN value in ARGB, set it to no color
Runtime.InteropServices.Marshal.WriteByte(col, 2, 255)
' 2 offset is the BLUE value in ARGB, set it to full color
Runtime.InteropServices.Marshal.WriteByte(col, 3, 255)
' 3 offset is the ALPHA value in ARGB, set it to full opacity
pixel = New IntPtr(col.ToInt32 + 4)
' Move to the next pixel
Next j
' Next pixel
line = New IntPtr(line.ToInt32 + bd.Stride)
' Move to the next line. Stride counts the number of bytes in a row, in some pixel formats padding bytes are used on every row so use Stride instead of counting it yourself.
Next i
' Next row
b.UnlockBits(bd)
' We are done with the bitmap manipulation. Unlock it so we can paint it
' We now have a solid purple bitmap. |
Of course in this example we just paint one color on every pixel, in yours you would want to load file data for each pixel's channel into the bitmap, or read the pixel data from the bitmap and write it into a DF format.
Hell maybe I'll make a texture converter in .NET since I know enough about bitmap formats etc to do it.
_________________ http://www.mzzt.net/ | I am a respectable admin with a respectable sig. |
|
DF Veteran Ree-Yees
Joined: 24 Nov 2005
|
Posted: Jul 11, 2009 04:28 Post subject: |
|
|
Well, that's the thing I don't understand. The DF Specs say that each byte in the picture-data-part of the file is one color, but How do I get that byte to represent the right color?
For instance, I read in the data for the first frame of the switch that opens the front door in Secbase. The first pixel in the top-left-hand corner of the frame is a gray color (in MS Paint it is R=104, G=104, B=104). In the file, the byte is 32-hex or 50-dec.
I think the ms paint "Edit Colors" section is in 32-bit or something. Maybe not. Anyway, I don't know how to get the byte to represent that gray color. Any help on that is appreciated.
Yah, I'm going to code it in C#. I can code in VB, but I'm not nearly as good at VB as you, apparently. 
|
|
DF Veteran Ree-Yees
Joined: 24 Nov 2005
|
Posted: Jul 11, 2009 04:33 Post subject: |
|
|
Oh, wait. I just saw what you said about the palette offset. That may be the answer I am looking for. Hopefully it is.
|
|
DF Veteran Ree-Yees
Joined: 24 Nov 2005
|
Posted: Jul 11, 2009 05:13 Post subject: |
|
|
Nope. Here's what I did.
Bitmap b = new Bitmap(128, 128, System.Drawing.Imaging.PixelFormat.Format8bppIndexed);
Color c = b.Palette.Entries[50]; //50-dec from the 32-hex value in the .BM file
e.Graphics.FillRectangle(new SolidBrush(c), 0, 0, 128, 128);
That gives me a 128x128 dark blue rectangle. Is there a default Palette used in DF that it takes all of the color values from or something?
|
|
DF Veteran Ree-Yees
Joined: 24 Nov 2005
|
Posted: Jul 11, 2009 06:10 Post subject: |
|
|
Ok, now I think I found it. BmpDf uses some the same info as in some dfuse.pal, which I don't have. The 8-bit values must be the offsets in the palette files in DF. I guess I'll just use those palettes in my program.
|
|
Lionel Fouillen Gamorrean
Joined: 27 Sep 2003
|
Posted: Jul 11, 2009 07:03 Post subject: |
|
|
DF Veteran wrote:
Yah, the CMP file is pretty cool. I dinked around with the one from secbase and made some of the low colors look bluish gray. I was trying to create a fog looking effect like Matt H. did at one time. I was going to put it below a waterfall to simulate mist at the bottom. I gave it up, though. I got impatient. 
Ha! I tried it on Archangel 2 to make the underwater sectors look blue but I gave up as well. Technically I succeeded, but aesthetically it didn't loog good.
|
|
DF Veteran Ree-Yees
Joined: 24 Nov 2005
|
Posted: Jul 11, 2009 07:27 Post subject: |
|
|
Lionel Fouillen wrote:
Ha! I tried it on Archangel 2 to make the underwater sectors look blue but I gave up as well. Technically I succeeded, but aesthetically it didn't loog good.
Mine did too. Plus, I was using Pacmut. Great utility, but it took FOREVER to edit even one light level.
Ok, so I just used secbase.pal and it worked. I had to multiply the color intensities by 4, though, to get the right light level in the picture. I guess that's because Windows has 32-bit color and I'm trying to draw 8-bit images. 8*4 = 32.
|
|
The MAZZTer Death Star

Joined: 25 Sep 2003
|
Posted: Jul 13, 2009 15:12 Post subject: |
|
|
I thought you would know all about palettes already. :X Sorry.
BTW palettes typically have 2^(PICTURE BIT DEPTH) colors. 8-bit images have 256 palette entries (numbered 0 to 255). 8-bit is the most common but there are also 4-bit palette. 2-bit tends to just be black and white and usually doesn't get it's own palette.
The reason for the colors being too dark is because color intensities in Dark Forces palettes are from 0-63 instead of the Windows standard 0-255 so you need to scale them. * 4 is not an exact scaling as it only scales to 0-252. I suppose that would be good enough as long as you don't convert back and forth a lot (IE allow the user to edit palettes using thbe 0-63 scale and only convert to 0-252 for rendering in the UI). * 255 / 63 is a more exact scaling.
_________________ http://www.mzzt.net/ | I am a respectable admin with a respectable sig. |
|
DF Veteran Ree-Yees
Joined: 24 Nov 2005
|
Posted: Jul 14, 2009 06:26 Post subject: |
|
|
Well, what I'm thinking of doing is to just use the DF Palettes to draw with. That way the only values I have to change/save/load in the files are the offsets in the palette. I can render the colors to the screen with that '*4' and no problems happen with conversions or anything.
I don't want to get to complicated with allowing custom colors, because I'm not sure what offsets to save out in the BM/FME/WAX files. Plus, if the custom color isn't in the palette to begin with, it will look bad in DF anyway, so I figure the restriction of using the DF ones will prevent that.
I will code in the ability to create/change a custom DF palette (.pal file), too, though, just in case custom colors are needed.
That, finally, brings me to a question. I have loaded all of the palettes from DF into the program, convertted them to the brighter colors, and re-saved the new colors out to a custom-formatted file. I plan on using my file to load the palettes. Is there anything legaly wrong with this? Again, new format for my file and all different RGB values, just the same offsets as DF.
|
|
The MAZZTer Death Star

Joined: 25 Sep 2003
|
Posted: Jul 14, 2009 15:26 Post subject: |
|
|
Well they say 3 copied notes in a row counts as plagiarism of a musical work. I don't know about palettes and such but... well... I doubt LA cares anymore.
The full game they might care about if they intend to release it on Steam in the future but other than that...
_________________ http://www.mzzt.net/ | I am a respectable admin with a respectable sig. |
|
The MAZZTer Death Star

Joined: 25 Sep 2003
|
Posted: Jul 16, 2009 17:15 Post subject: |
|
|
Well the DF-21 webserver ate my post so let me try that again.
I'm making a .NET library, and then a UI for converting between formats. So far I have PAL, PLTT, CMP, and BM support (need to test it all though, especially multiple BMs and compression... yes I implemented support for BM compression). Gonna add FME, WAX, ANIM, DELT, FNT, and FONT support.
[Edit: Here is the above BM in its compressed form:
I think I messed something up. >_>]
[Edit 3: FME class done. Making the transparent color actually transparent was more trouble than it should have been. Thanks Microsoft!
]
[Edit 4: DELT!
]
[Edit 5:
| Code: | 07/17/2009 11:49 AM 54,558 arc.DLT
07/17/2009 06:56 PM 69,457 arc-uncompressed.delt
07/17/2009 06:56 PM 41,134 arc-compressed.delt
|
First file is the original ARC Hammer level briefing. The second file is the briefing saved without RLE compression. The third file uses optimum compression using my own algorithm. Check those file sizes. ]
[Edit 6: Added CMP light level and BM/ANIM page support to my test app. The eyes, they are so bright aaaaah.
]
[Edit 7:
FNT and FONT support. Not much to see.
This is still my test window and not a real program but it's easier for me to use now.]
[Edit 8:
WAXs can be loaded. Now to figure out how to save them. WAXs are complicated. :X
]
[Edit 2: OK I gots a question. For FMEs, I'm guessing the "insertion point" determines how the image is drawn with respect to the position of the sprite in the game world. But the specs don't say what the 0,0 point is! Is it in the center of the image? Bottom middle? Top left?
I'm thinking bottom middle from the values I'm getting from FMEs I'm hex editing. Confirmation would be helpful.]
[Edit 4b: Yeah and what about the offsetx and offsety in DELTs? Same deal but I assume from the upper-left corner?
Also is color 0 transparent in DELTs? The help file doesn't say explicitly, only a DIFFERENT way to achieve transparency is explained.]
_________________ http://www.mzzt.net/ | I am a respectable admin with a respectable sig. |
|
|