Code Monkey home page Code Monkey logo

Comments (3)

Quaker762 avatar Quaker762 commented on July 30, 2024

Hi @316austin316

I believe the swizzle of these textures is based on the TIM2 format. You can find more information here: https://openkh.dev/common/tm2.html

This page didn't exist when I was working on this. Hopefully this helps.

from sh3redux.

316austin316 avatar 316austin316 commented on July 30, 2024

Hi @316austin316

I believe the swizzle of these textures is based on the TIM2 format. You can find more information here: https://openkh.dev/common/tm2.html

This page didn't exist when I was working on this. Hopefully this helps.

yes i have managed to unswizzle 8bpp textures friend thank you, now i'm struggling with 4 bpp. also i have looked at your palette data code and while it worked maybe 50% of the time, i am having issues with sometimes incorrect palette. If you have any information, I would appreciate it

from sh3redux.

Quaker762 avatar Quaker762 commented on July 30, 2024

If you have any information, I would appreciate it

Sure. This guys has some pseudocode related to unswizzling TM2 stuff, he took it from the (now defunct) Xentax wiki. I believe this is where the original implementation of this came from when it was submitted to sh3redux, however this was approaching 8 years old now.

Maybe @muddle12 can himself comment on this further.

https://github.com/muddle12/DCExtractor/blob/main/Specifications/Images/TM2.md

//Convert the TIM2Picture's palette to linear 32-bit True Color.
Color[] ConvertPicturePaletteToRGBA(TIM2Picture tPicture)
{
	//If there is no palette, return an empty palette.
	if (tPicture.paletteBytes == null || tPicture.paletteBytes.Length == 0)
		return null;

	//Otherwise, we're going to have to figure out which palette we're using based on the paletteColorSize.
	Color[] tPalette;
	if (tPicture.bitsPerPixel <= 8)
	{
		//We'll infer which palette type we're using based on the size of each individual palette entry.
		switch (tPicture.colorSize)
		{
			case 2://16 BIT LE_ABGR_1555?
				{
					tPalette = FromBufferABGR1555(tPicture.paletteBytes, tPicture.paletteSize);
				}
				break;
			case 3://24 BIT RGB?
				{
					tPalette = FromBufferRGB24Bit(tPicture.paletteBytes, tPicture.paletteSize);
				}
				break;
			case 4://32 BIT RGBA?
				{
					tPalette = FromBufferRGBA32Bit(tPicture.paletteBytes, tPicture.paletteSize);
				}
				break;
			default://Invalid data.
				return null;
		}

		//If the palette is interleaved, we need to unpack that into something linear.
		if (tPicture.isLinearPalette == false)
		{
			//The TIM2 palettes always have these fixed values.
			const int nBlockCount = 2;
			const int nStripeCount = 2;
			const int nColorCount = 8;

			//Some calculations for unpacking the palette.
			int nPartCount = tPalette.Length / 32;
			int nPartStride = nColorCount * nStripeCount * nBlockCount;
			int nStripeStride = nStripeCount * nColorCount;

			//This next part was ripped wholesale from the xentax references. I couldn't tell you exactly what's going on, but it appears to work.
			//If I had to guess, TIM2 has a very particular kind of interleave using blocks instead of straight stripes.
			int i = 0;
			Color[] tUnpackedColors = new Color[tPalette.Length];
			for (int part = 0; part < nPartCount; part++)
			{
				for (int block = 0; block < nBlockCount; block++)
				{
					for (int stripe = 0; stripe < nStripeCount; stripe++)
					{
						for (int color = 0; color < nColorCount; color++)
						{
							tUnpackedColors[i++] = tPalette[(part * nPartStride) + (block * nColorCount) + (stripe * nStripeStride) + color];
						}
					}
				}
			}

			//overwrite the original palette, as we don't need it anymore.
			tPalette = tUnpackedColors;
		}
	}
	return tPalette;
}

from sh3redux.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.