Jump to content

  •  

  • iBotModz CBox


    Photo

    Poke-Cancer's texture deswizzling research.


    • Please log in to reply
    3 replies to this topic

    #1 T3A guy

    T3A guy

      :)

    • Members+

    • 1,191 posts
    • Joined: 09-May 08
    • Gender:Male

    Posted 10 March 2009 - 08:10 PM

    Hey I was wondering how pokecancer found out that the textures were A8R8G8B8.

    I figured I would release my deswizzle method for A8R8G8B8 so people can do more research on bitmaps. This applies to not only H3 but most game's resources for Xbox 360 and could probably be easily adjusted to deal with different argb formats by changing some of the math in my code. BTW this is using my own modified BinaryReader class so you will have to change that if you want to use this code. also keep in mind the data is in big endian format and need to 32 bit
    swapped in order to be in a format the pc can understand.

    public static byte[] Deswizzle(byte[] raw, int width, int height)
    			{
    				MemoryStream ms = new MemoryStream();
    				core.IO.EndianIO.EndianWriter ew = new core.IO.EndianIO.EndianWriter(ms, core.IO.EndianType.LittleEndian);
    				ew.BaseStream.Position = 0;
    
    				int realsize = width * height * 4;
    				int lines = realsize / 16;
    
    				int templine = 0;
    				int rowcount = 0;
    				int offsetby = 0;
    				int i = 0;
    				int sections = width / 32;
    				for (int x = 0; x < lines; x++)
    				{
    
    
    					if (rowcount % 32 == 0 && rowcount != 0)
    					{
    
    						templine = (i+1)*((width * 32) /4);
    
    						i++;
    
    					}
    
    
    
    					if (rowcount % 8 == 0 && rowcount != 0)
    					{
    						if (offsetby == 0)
    						{
    							offsetby = 8 * 16;
    						}
    						else
    						{
    							offsetby = 0;
    						}
    					}
    
    
    					if (rowcount == height) break;
    
    					///get row 1 - 224 pixels(one row) = 7 * 32   
    					for (int y = 0; y < sections; y++)
    					{
    
    						//get 32 pixels
    						for (int z = 0; z < 8; z++)
    						{
    							if (z < 4)
    							{
    								int offset = (templine * 16) + ((y * 256) * 16) + ((z * 2) * 16) + offsetby;
    								int oi1 = BitConverter.ToInt32(raw, offset + 0);
    								int oi2 = BitConverter.ToInt32(raw, offset + 4);
    								int oi3 = BitConverter.ToInt32(raw, offset + 8);
    								int oi4 = BitConverter.ToInt32(raw, offset + 12);
    
    								ew.Write(oi1);
    								ew.Write(oi2);
    								ew.Write(oi3);
    								ew.Write(oi4);
    							}
    							else
    							{
    								int offset = (templine * 16) + ((y * 256) * 16) + ((z * 2) * 16) - offsetby;
    								int oi1 = BitConverter.ToInt32(raw, offset + 0);
    								int oi2 = BitConverter.ToInt32(raw, offset + 4);
    								int oi3 = BitConverter.ToInt32(raw, offset + 8);
    								int oi4 = BitConverter.ToInt32(raw, offset + 12);
    
    								ew.Write(oi1);
    								ew.Write(oi2);
    								ew.Write(oi3);
    								ew.Write(oi4);
    							}
    						}
    
    					}
    					rowcount++;
    
    					if (rowcount == height) break;
    					///get row 2
    					for (int y = 0; y < sections; y++)
    					{
    
    						//get 32 pixels
    						for (int z = 0; z < 8; z++)
    						{
    							if (offsetby != 0)
    							{
    							}
    							if (z < 4)
    							{
    								int offset = (templine * 16) + 16 + ((y * 256) * 16) + ((z * 2) * 16) + offsetby;
    								int oi1 = BitConverter.ToInt32(raw, offset + 0);
    								int oi2 = BitConverter.ToInt32(raw, offset + 4);
    								int oi3 = BitConverter.ToInt32(raw, offset + 8);
    								int oi4 = BitConverter.ToInt32(raw, offset + 12);
    								ew.Write(oi1);
    								ew.Write(oi2);
    								ew.Write(oi3);
    								ew.Write(oi4);
    							}
    							else
    							{
    								int offset = (templine * 16) + 16 + ((y * 256) * 16) + ((z * 2) * 16) - offsetby;
    								int oi1 = BitConverter.ToInt32(raw, offset + 0);
    								int oi2 = BitConverter.ToInt32(raw, offset + 4);
    								int oi3 = BitConverter.ToInt32(raw, offset + 8);
    								int oi4 = BitConverter.ToInt32(raw, offset + 12);
    								ew.Write(oi1);
    								ew.Write(oi2);
    								ew.Write(oi3);
    								ew.Write(oi4);
    							}
    						}
    
    					}
    					rowcount++;
    					templine += 16;
    				}
    				return ms.ToArray();
    			}


    Edited by T3A_guy, 12 March 2009 - 03:56 PM.


    #2 DEEhunter

    DEEhunter

      Corporal Grade 2

    • Members+

    • 228 posts
    • Joined: 19-June 08

    Posted 01 April 2009 - 10:33 PM

    ... Bitmaps are rarely 32 bit. This is old stuff.

    #3 maomaochong

    maomaochong

      Apprentice Grade 1

    • Members+

    • 5 posts
    • Joined: 17-May 09

    Posted 17 May 2009 - 11:19 PM

    VINA DEL MAR, Chile (Reuters) - Center-left world leaders including Britain's Gordon Brown and Brazil's Luiz Inacio Lula da Silva on Saturday called for global financial reforms at next week's G20 summit, but the U.S. warned against over-regulation.
    Meeting in the Chilean coastal resort of Vina del Mar in a pre-G20 warm-up, Brown, Lula, host Chilean President Michelle Bachelet and Spanish Prime Minister Jose Luis Rodriguez Zapatero said deep financial reforms were vital to avert a another financial meltdown.
    "The whole world is paying the price for the collapse of a reckless venture of those that have turned the world economy into a gigantic casino," Lula told fellow leaders in a roundtable discussion.
    "We are rejecting blind faith in the markets."
    Brown said the G20 summit in London had to focus on concrete ways to revive growth and create jobs while protecting the environment and the world's poor.
    "We have got to be very clear that banking cannot be unsupervised any more; there's got to be cross border supervision," he said, calling for an overhaul of the system of international finance and coordinated policies to help underpin sustainable growth.
    wow power leveling
    Health Top Tips Nutrition Love Lifestyle Happiness Weight Loss
    U.S. President Barack Obama has called on fellow G20 leaders to agree on immediate action to help boost the struggling global economy, wow power leveling while Brown wants the group to back a $100 billion expansion of trade financing and agree upon a long-delayed global trade pact.
    U.S. Vice President Joe Biden told the meeting overlooking Chile's Pacific coast the United States was eager to coordinate international policy to reduce systemic risk to global markets, but warned over-regulation could hurt healthy markets.
    world of warcraft power leveling
    "We should not over-react. It is not a choice of markets or governments," Biden said. "A free market still needs to be able to function."
    Thousands of people marched in Britain, France, Germany and Italy on Saturday to protest the economic crisis and urge world leaders to act to reduce poverty, create jobs and avert climate change at the G20 summit.
    world of warcraft power leveling
    "We have to democratize the economy, globalization and the financial system. How to do this? We already know: with information, transparency and responsibility," Zapatero said.
    (With reporting by Rodrigo Martinez, Antonio de la Jara, Patricia Velez and Adrian Croft in Vina del Mar; editing by Todd Eastham)

    #4 Lockon

    Lockon

      "I never asked for this"

    • VIP

    • 1,896 posts
    • Joined: 17-June 08
    • Gender:Male
    • Location:N.Ireland

    Posted 18 May 2009 - 01:12 AM

    ^what?