Talk:Image Formats

From Custom Mario Kart
Jump to navigation Jump to search

Blocks

Can anyone explain the meaning of "block size"? What is a block and for what are blocks used?
Wiimm 20:38, 18 June 2011 (CEST)

It's explained a little at the top of the format section. Basically, rather than encoding pixels in the order left to right, top to bottom, it goes left to right for the block width, then top to bottom for the block height, then does the next blocks in a left to right, top to bottom order. Example
It looks like this on screen
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
But if the block size was 2x2 it would be encoded as 1, 2, 5, 6, 3, 4, 7, 8, 9, 10, 13, 14, 11, 12, 15, 16.
Chadderz 08:59, 19 June 2011 (CEST)
Ohh, that's the reason that I see garbage in my png export. Thanx.
Wiimm 09:53, 19 June 2011 (CEST)

Byte Formats

I have some more questions about interpreting the bytes. Perhaps I can solve them by myself, but hints are welcome.

  1. I4: Is the high or low nibble (=4 bits) used for the first pixel?
  2. I4 (and some other formats): The text says: "multiply with 0x10 to get the color value". The result are values between 0x00..0xf0. Why not using the usual factor 0x11 (range 0x00..0xff)?
  3. Some formats: There are multiply factors given to find RGB+Alpha values. Are this factors based on the correct endian (most big endian)? Or on intel format (little endian)?
  4. What is the alpha channel: opacity or transparency? (I think opacity)

Wiimm 10:39, 19 June 2011 (CEST)

  1. High then low
  2. You're quite right, my mistake it should be 0x11. The old SZS Mod implementation was 0x10 due to a mistake, and I was just mindlessly copying.
  3. I'm not quite sure what you mean. Mario Kart Wii is always big endian.
  4. Generally the two are considered synonymous in this context but yes, 0xff is fully opaque, and 0x00 is fully transparent.
Chadderz 21:39, 19 June 2011 (CEST)
Thanx again. I have already implemented I4, I8, IA4 and IA8 conversions to PNG, the others will follow. In the moment, TEX0 and BREFT subfiles are converted, hooks for other formats are easy.
Point 3 was a thinking error of me. Point 4: You described opacity. If the alpha channel is "transparency" then 0x00 is fully opaque, and 0xff is fully transparent. Both are valid definitions and (but not sure) PNG and other image formats support both.
Wiimm 22:53, 19 June 2011 (CEST)
The trickiest format to implement is the CMPR, I found looking at someone else's source code the most helpful for seeing how it actually works, it's hard to describe.
On point 4, I've never heard that distinction made before, I've only ever seen formats which call 0xff opaque, and 0x00 transparent, whether they call it opacity or transparency. I'll be more specific in future though.
Chadderz 07:58, 20 June 2011 (CEST)
libpng support both kinds of alpha channel: "PNG_TRANSFORM_INVERT_ALPHA Change alpha from opacity to transparency" But I think, it's only the interface and not the png file itself that supports inverting.
Hanno 08:53, 20 June 2011 (CEST)
@Chadderz: I had read CMPR twice but I think I have understood it. I'll implement the other formats first, but I have not found any of the palette formats in Mario Kart. Do you known some examples?
@Hanno: Perhaps it was an mistake by me to mix the interface with the data structure.
Wiimm 16:22, 20 June 2011 (CEST)
@Chadderz: Are you sure about RGBA32? my Analysis (repeated values) says that the either block width is 2 or bits per pixel is 16, but no of many tests show the same images as SZS Modifier.
Wiimm 23:03, 20 June 2011 (CEST)
I am certain about RGBA32. The wii dev kit supports tpl creation and it always uses RGBA32 and they render fine. The pallette formats are used in the country flag's tpl files. I've forgotten where they are located.
Chadderz 09:10, 21 June 2011 (CEST)
The trick with RGBA32 is, that A and R is coded in the first half of the block data and G and B in the second half. Therefor my assumption of 16 bits per pixel is correct (for each half).
I have now implemented the PNG export from all formats but not the palette formats (C4, C8, C14x2). I haven't looked into other source, because your description is good (ok, I have made 2 edits). The next steps is the conversion from PNG to the internal formats and perhaps a conversion tool.
Wiimm 12:52, 21 June 2011 (CEST)

Image Format CMPR

I'm on the way to write an general image format converter:

  • Support image formats I4, I8, IA4, IA8, RGB565, RGB5A3, RGBA32, CMPR.
    • Converting from one to each other is planed.
  • Support file formats BREFT sub, TEX, TPL (and perhaps more if I find them).
    • Converting from one to each other is planed.
  • Support export to and import from PNG.

All of this is clear in my mind, but I need a good CMPR compression/encoding algorithm. Do you know some?
Wiimm 12:18, 23 June 2011 (CEST)