READ THE RULES: Click here

Follow us on Facebook: https://www.facebook.com/xentax/ :)

How do I read a "skewed" image?

Get your graphics formats figures out here! Got details for others? Post here!
finale00
M-M-M-Monster veteran
M-M-M-Monster veteran
Posts: 2382
Joined: Sat Apr 09, 2011 1:22 am
Has thanked: 170 times
Been thanked: 296 times

How do I read a "skewed" image?

Post by finale00 » Thu Feb 21, 2013 6:08 am

I am using TextureFinder and it has a "skew" option.

I'm assuming that is image shearing, but I don't understand how it works on a byte level.
I've read some general explanations about how you transform a rectangle into a...slanted looking one...but how would I take those pixels and transform it back to a normal rectangle?

The image format I am working is RGB24 with a skew value of 3, and I would like my image converter to shear the image correctly.

How do I read pixels that have been "skewed" by some value?
You do not have the required permissions to view the files attached to this post.
Last edited by finale00 on Thu Feb 21, 2013 4:42 pm, edited 1 time in total.

User avatar
shakotay2
MEGAVETERAN
MEGAVETERAN
Posts: 2800
Joined: Fri Apr 20, 2012 9:24 am
Location: Nexus, searching for Jim Kirk
Has thanked: 697 times
Been thanked: 1439 times

Re: How do I "skew" an image?

Post by shakotay2 » Thu Feb 21, 2013 4:16 pm

finale00 wrote:but I don't understand how it works on a byte level.
Hah, who will?;-)
You could draw a 32x32 pixels bmp setting 3 pels at 17,15, 16,16 and 15,17.
Then unskew this bmp with TextureFinder (skew: +3) and save it as unskewed.bmp for example.

Load both bmps into a hex editor to compare them (visually) on byte level. Kinda difficult I think.
...but how would I take those pixels and transform it back to a normal rectangle?
The image format I am working is RGB24 with a skew value of 3, and I would like my image converter to shear the image correctly.
How do I read pixels that have been "skewed" by some value?
Read this one? http://stackoverflow.com/questions/2446 ... transforms
Most important info imho: "If you don't feel like re-inventing the wheel, check out [some graphics] library."

That's what I did: performed a shearing on your swizzeld image (do you remember? :D)
Image

This is the main part of the code:

Code: Select all

       case WM_PAINT:
                SetWindowHandle(hwndDlg);
                InvalidateRect (hwndDlg, &rect, TRUE) ;
                hdc = BeginPaint (hwndDlg, &ps);
                graphics = new Graphics(hdc);
	        {
		       Matrix matrix;
  		       //matrix.Translate(220.0f, 0.0f);            // first a translation
		       //matrix.Rotate(30.0f, MatrixOrderAppend);   // then a rotation
		       // Shear
		       matrix.Shear(2, 1);            // params: horizontal and vertical shear factors 
		       // Apply transformation
		       graphics->SetTransform(&matrix);
	        }
                graphics->DrawImage(ourImage,5,5);
                delete(graphics);
                EndPaint( hwndDlg, &ps );
                break;
Last edited by shakotay2 on Thu Feb 21, 2013 4:46 pm, edited 1 time in total.
Bigchillghost, Reverse Engineering a Game Model: viewtopic.php?f=29&t=17889
extracting simple models: viewtopic.php?f=29&t=10894
Make_H2O-ForzaHor3-jm9.zip
"You quoted the whole thing, what a mess."

finale00
M-M-M-Monster veteran
M-M-M-Monster veteran
Posts: 2382
Joined: Sat Apr 09, 2011 1:22 am
Has thanked: 170 times
Been thanked: 296 times

Re: How do I "skew" an image?

Post by finale00 » Thu Feb 21, 2013 4:41 pm

I probably meant pixel level lol
I've already used the shear function that comes with .NET but it just takes whatever pixels I've read into my bitmap and changes THAT picture.

So I'm guessing the issue I have to deal with is to figure out how to actually read the pixels and map them to my rectangular bitmap in the correct order, and not just how to shear a bitmap.

I'll start experimenting with some pictures and see how texfinder saves the skewed output.

Polefish
veteran
Posts: 94
Joined: Sat Jun 20, 2009 1:47 pm
Has thanked: 16 times
Been thanked: 13 times

Re: How do I read a "skewed" image?

Post by Polefish » Thu Feb 21, 2013 5:20 pm

I would look up on shearing computer graphics on google to get a basic understanding of the transformation process. Maybe this example in matlab is useful for you http://stackoverflow.com/questions/2818 ... -functions

finale00
M-M-M-Monster veteran
M-M-M-Monster veteran
Posts: 2382
Joined: Sat Apr 09, 2011 1:22 am
Has thanked: 170 times
Been thanked: 296 times

Re: How do I read a "skewed" image?

Post by finale00 » Thu Feb 21, 2013 5:27 pm

I looked at the easiest explanation I could find from those answers and this is what it looks like to me

Code: Select all

for row i = 0 to blah
  shift row i by n * i bytes (loop as needed)
So if I want to skew by 1 pixel, then n = 1 and the first row would be shifted by 0 bytes, the second row shifted by 1 byte, the third row shifted by 2 bytes, etc.

Which kind of makes sense, cause in the image I can see the stuff that should be on the right, spilling over to the left.

But that's one of the easy one. The other ones have complicated calculations involved hmm I wonder guess I'll start with the simple row-shifting.

Polefish
veteran
Posts: 94
Joined: Sat Jun 20, 2009 1:47 pm
Has thanked: 16 times
Been thanked: 13 times

Re: How do I read a "skewed" image?

Post by Polefish » Thu Feb 21, 2013 5:57 pm

Yes it's basically a shifting of pixels by a given amount. This link makes the process very clear: http://cs.fit.edu/~wds/classes/cse5255/ ... shear.html What you mean by 'complicated' calculations could be the angle representation of the shearing matrix explained here: http://www.cs.colorado.edu/~mcbryan/5229.03/mail/55.htm

finale00
M-M-M-Monster veteran
M-M-M-Monster veteran
Posts: 2382
Joined: Sat Apr 09, 2011 1:22 am
Has thanked: 170 times
Been thanked: 296 times

Re: How do I read a "skewed" image?

Post by finale00 » Thu Feb 21, 2013 9:13 pm

Some images are sheared, while other images aren't.
The image header contains 6 shorts, which sort of look like coordinates (x1, y1) (x2, y2) (x3, y3)

Currently I'm just randomly guessing at when they might be sheared, but maybe I have to do some math involving these three points.

A parallelogram can be represented using 3 points on a plane, and if shearing is mapping pixels from a rectangle to some arbitrary parallelogram, then these would need to be used somehow.

Of course my interpretation of this data may be completely off, but I can't come up with anything sensible based on my existing knowledge.

Here's a sample
You do not have the required permissions to view the files attached to this post.

Polefish
veteran
Posts: 94
Joined: Sat Jun 20, 2009 1:47 pm
Has thanked: 16 times
Been thanked: 13 times

Re: How do I read a "skewed" image?

Post by Polefish » Fri Feb 22, 2013 12:02 am

If I saw this right only the colour channel (24bpp) appears sheared, the alpha channel (8bpp) looks totally fine. It doesn't make much sense this way. Can you think of any reason an image looks skewed/sheared when you parse it wrong?

User avatar
shakotay2
MEGAVETERAN
MEGAVETERAN
Posts: 2800
Joined: Fri Apr 20, 2012 9:24 am
Location: Nexus, searching for Jim Kirk
Has thanked: 697 times
Been thanked: 1439 times

Re: How do I read a "skewed" image?

Post by shakotay2 » Fri Feb 22, 2013 12:39 am

finale00 wrote:Of course my interpretation of this data may be completely off, but I can't come up with anything sensible based on my existing knowledge.

Here's a sample
Is an original or your interpretation of data?
I'm seeing this: Image

edit: with a width of 518 the skew is 0 (pixel format 888)

The header I used:

Code: Select all

Offs   0  1  2  3  4  5  6  7   8  9  A  B  C  D  E  F

00000 42 4D 36 34 10 00 00 00  00 00 36 00 00 00 28 00
00010 00 00 FE 00 00 00 02 01  00 00 01 00 20 00 00 00
00020 00 00 00 34 10 00 00 00  00 00 00 00 00 00 00 00
00030 00 00 00 00 00 00
Last edited by shakotay2 on Fri Feb 22, 2013 9:25 am, edited 1 time in total.
Bigchillghost, Reverse Engineering a Game Model: viewtopic.php?f=29&t=17889
extracting simple models: viewtopic.php?f=29&t=10894
Make_H2O-ForzaHor3-jm9.zip
"You quoted the whole thing, what a mess."

finale00
M-M-M-Monster veteran
M-M-M-Monster veteran
Posts: 2382
Joined: Sat Apr 09, 2011 1:22 am
Has thanked: 170 times
Been thanked: 296 times

Re: How do I read a "skewed" image?

Post by finale00 » Fri Feb 22, 2013 1:20 am

The sample is the original.
I am unable to find a way to accurately determine the skew value.
Polefish wrote:If I saw this right only the colour channel (24bpp) appears sheared, the alpha channel (8bpp) looks totally fine. It doesn't make much sense this way. Can you think of any reason an image looks skewed/sheared when you parse it wrong?
Nope...

Well, the background info is that these are sprites used in a game engine and so some frames are stored normally, while some frames are sheared. Performance reasons maybe? Wouldn't know why the alpha and image would not be stored the same way though.

I've packed a bunch of files up if you want to compare.
The format is pretty much always the same (there is one format that isn't RGB24 though and I've sort of just ignored it)
You do not have the required permissions to view the files attached to this post.

User avatar
shakotay2
MEGAVETERAN
MEGAVETERAN
Posts: 2800
Joined: Fri Apr 20, 2012 9:24 am
Location: Nexus, searching for Jim Kirk
Has thanked: 697 times
Been thanked: 1439 times

Re: How do I read a "skewed" image?

Post by shakotay2 » Fri Feb 22, 2013 9:06 am

finale00 wrote:The sample is the original.
I am unable to find a way to accurately determine the skew value.
Displaying the image as RGB 888 there is no skew: Image
edit: same with pic387 (ok, that doesn't help if you need the alpha channel).

Displaying them as RGB 8888 there's always the same skew, isn't it? (Checked 3 pics only.)
So you could get unskewed images by using an "8888 to 888" converter (Fujitsu Bitmap Converter) without knowing the skew. (Ok, alpha lost then).
Last edited by shakotay2 on Fri Feb 22, 2013 6:08 pm, edited 2 times in total.
Bigchillghost, Reverse Engineering a Game Model: viewtopic.php?f=29&t=17889
extracting simple models: viewtopic.php?f=29&t=10894
Make_H2O-ForzaHor3-jm9.zip
"You quoted the whole thing, what a mess."

finale00
M-M-M-Monster veteran
M-M-M-Monster veteran
Posts: 2382
Joined: Sat Apr 09, 2011 1:22 am
Has thanked: 170 times
Been thanked: 296 times

Re: How do I read a "skewed" image?

Post by finale00 » Fri Feb 22, 2013 5:28 pm

Some images are normal, others are skewed.
Try pic387.

The black/white image you see at the bottom is the alpha mask.
There are 3 formats I have seen so far

-RGB24
-RGB24 + 8-bit mask
-something else

You would start by reading in the image data, and if the format contains an alpha mask, you read that in as well, and then merge that with the image to get your final, transparent image.

The format I have spec'd out so far is

Code: Select all

# header
int32 ?
int32 ?
int32 size # rgb24 and alpha
int16 width
int16 height
byte ?
byte format # might be just a single int32
byte ?
byte ?

# presumably, some coordinates
int16 ?
int16 ?
int16 ?
int16 ?
int16 ?
int16 ?

if format == 4
  # don't know

byte[width*height*3] pixData

if format == 0x10
   byte[width*height] maskData

finale00
M-M-M-Monster veteran
M-M-M-Monster veteran
Posts: 2382
Joined: Sat Apr 09, 2011 1:22 am
Has thanked: 170 times
Been thanked: 296 times

Re: How do I read a "skewed" image?

Post by finale00 » Fri Feb 22, 2013 6:04 pm

eh, that's weird that one's not skewed lol hold on let me find a skewed one.
As polefish pointed out, a lot of images have only the alphas skewed, but I remember seeing a couple where the whole thing was skewed.

EDIT: found some skewed ones! lol
59 and 63 are skewed. The others are normal.

But the skewed alphas are a little annoying as well, since...then I can't properly apply it over the image.
The integer at offset 4 has a few different numbers that I have seen: 0, 1, 2, 4

I am not sure if this indicates the skew type. For example, 0 = no skew, 1 = alpha mask skewed, 2 = image skewed, 4 = both skewed? don't know.
You do not have the required permissions to view the files attached to this post.

Sir Kane
veteran
Posts: 98
Joined: Mon Aug 06, 2012 4:14 am
Been thanked: 77 times

Re: How do I read a "skewed" image?

Post by Sir Kane » Fri Feb 22, 2013 7:21 pm

What game is this actually from? And could you provide the exe/whatever? Format 4 seems to be RLE encoding of some kind, pic422 is 2*5 px in size, image data is 0xA for count, 3 bytes for color then 0 as end tag.

finale00
M-M-M-Monster veteran
M-M-M-Monster veteran
Posts: 2382
Joined: Sat Apr 09, 2011 1:22 am
Has thanked: 170 times
Been thanked: 296 times

Re: How do I read a "skewed" image?

Post by finale00 » Fri Feb 22, 2013 8:04 pm

Here's the exe: http://www.mediafire.com/?gshsms49h4y4hph

Currently I am not particularly worried about the type 4's since skewing seems to be a more interesting problem when it comes to images lol

Post Reply