How to transfer image to assembly?

I am working on a project and I need to calculate something based on the rows and columns of the image. Easy to take bits of image lines. However, in order to take a bit of each column, I need to transpose the image so that the columns become rows.

I am using a BMP image as input. How many columns of row X are in the BMP image? I would like to see pseudo code or something, if possible.

+6
assembly x86 masm image-processing
source share
2 answers

It looks like you want to transpose the matrix, which is slightly different from rotation. In rotation, rows can become columns, but rows or columns will be in reverse order depending on the direction of rotation. Transposition maintains the original order of rows and columns.

I think that using the right algorithm is much more important than using an assembly or just C. Rotating 90 degrees or transposing really comes down to simply moving the memory. The biggest thing to consider is the cache miss effect if you use such a naive algorithm:

for(int x=0; x<width; x++) { for(y=0; y<height; y++) out[x][y] = in[y][x]; } 

This will cause many cache misses because you jump a lot in memory. Effectively use the block approach. Google for "caching an efficient transpose matrix."

In one place where you can get some value, use SSE instructions to move more than one piece of data at a time. They are available in assembly and in C. Also check this link . About half way they have a section on calculating the fast transpose of the matrix.

edit I just saw your comment that you are doing this for a class in an assembly, so you can probably ignore most of what I said. I suggested that you want to squeeze the best performance since you used the assembly.

+2
source share

This is changing. BMPs can be any size (to the limit), and they can be in different formats (32-bit RBG, 24-bit RBG, 16-bit palettes, 8-bit palettes, 1-bit monochrome), etc.

As with most other problems, it is best to first write the solution in the high-level language of your choice, and then convert parts or all of it to ASM as needed.

But yes, in its simplest form for this task, which will be a 32-bit RGB format, rotating with a multiple of 90-degressing will be similar to rotating a two-dimensional array.

+1
source share

All Articles