• Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

We're also offering banner ads on our site from just \$5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.

# explaining arm neon code

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

9 replies to this topic

### #1Ahmed Egyptian  Members   -  Reputation: 137

Like
0Likes
Like

Posted 21 March 2013 - 03:52 AM

Hi all,

so I'm trying to resize and downsample it by 3.

So I'm trying to get how the iterations occurred like srcHeight/3 and the math behing srcPitch*3, and s[0]. s[width], s[width*3]

  for (int r = 0; r < srcHeight/3; r++)
{
d = &dst[iDestPitch* r];
s = &src[iSrcPitch * r*3];

for (int c = 0; c < srcWidth/3; c+=8)
{
// ------------------
//   B1  B4  B7 ... B B B
//   B2  B5  B8 ... B B B
//   B3  B6  B9 ... B B B
// -------------------
// load 8 sets of 3x3 pixels (grayscale)
u88line0 = vld3_u8(&s[0]);
u88line1 = vld3_u8(&s[iSrcPitch]);
u88line2 = vld3_u8(&s[iSrcPitch*2]);
s += 24;
//processing


### #2Olof Hedman  Crossbones+   -  Reputation: 2896

Like
2Likes
Like

Posted 21 March 2013 - 04:49 AM

You are converting 3x3 blocks to 1x1.

In src you step over every third line:

s = &src[iSrcPitch * r*3];

so you have to limit the number of times you do that to 1/3 of the lines in src.

same thing inside each line.

s[0] reads a pixel on the current line, s[width] on the next, and s[width*2] on the next after that.

Edited by Olof Hedman, 21 March 2013 - 04:51 AM.

### #3Ahmed Egyptian  Members   -  Reputation: 137

Like
0Likes
Like

Posted 21 March 2013 - 04:54 AM

I can not imaging s[0], s[iSrcPitch], s[iSrcPitch*2]

s[480] of examples gives the last row of the image? not the second line ?

s[0] first row, then s[1] second row ? correct? so if he wants to load pixels from the 2nd row why writting s[iSrcPitch] ?

Edited by Ahmed Egyptian, 21 March 2013 - 04:56 AM.

### #4Olof Hedman  Crossbones+   -  Reputation: 2896

Like
0Likes
Like

Posted 21 March 2013 - 05:26 AM

the pointer s is pointing to the current pixel that is processed, not row.

s = &src[width*y] sets it to point at the first pixel in row y.

s[0] is that first pixel. s[1] is the next pixel in the row.

s[width] is the first pixel in the next row. (pixel directly below current)

s[width + 1] would be the pixel below to the right.

s += 24 steps s to point to the next pixel in the row.

### #5Ahmed Egyptian  Members   -  Reputation: 137

Like
0Likes
Like

Posted 21 March 2013 - 05:43 AM

can you direct me to a picture or article about processing images like that ?

Thank you so much. I need just to see a picture that shows that. I can't get s[width] can point to the next pixel in the next row..

### #6Brother Bob  Moderators   -  Reputation: 8429

Like
2Likes
Like

Posted 21 March 2013 - 05:52 AM

Let's just take a small image with some sensible numbers. Here's a 10x10 image, and the numbers represents the indices into that image.

     0     1     2     3     4     5     6     7     8     9
10    11    12    13    14    15    16    17    18    19
20    21    22    23    24    25    26    27    28    29
30    31    32    33    34    35    36    37    38    39
40    41    42    43    44    45    46    47    48    49
50    51    52    53    54    55    56    57    58    59
60    61    62    63    64    65    66    67    68    69
70    71    72    73    74    75    76    77    78    79
80    81    82    83    84    85    86    87    88    89
90    91    92    93    94    95    96    97    98    99


In this case, width=10 and height=10. As you can see, no matter which pixel you are at, if you add width to its index, you get to the next pixel below it. Similarly, if you subtract width from any index, you get to the pixel above it.

Take the pixel at coordinate (5, 4) which has the index 45. If you want to go down one pixel to the coordinate (5, 5), you add 10 to 45 and you get to index 55, which is the index at coordinate (5, 5). If you thus have a pointer p=&image[45], then p[width] references the pixel width units from p, and thus reaching the pixel below it.

Edited by Brother Bob, 21 March 2013 - 05:53 AM.

### #7Ahmed Egyptian  Members   -  Reputation: 137

Like
0Likes
Like

Posted 21 March 2013 - 05:54 AM

Thank you so much,  this is what I wanted

it would be easier to say  x  + y*width ?

does the above code loads the pixels from horizontal side or vertical side?

Edited by Ahmed Egyptian, 21 March 2013 - 05:59 AM.

### #8Ahmed Egyptian  Members   -  Reputation: 137

Like
0Likes
Like

Posted 21 March 2013 - 06:02 AM

srcWidth/3; c+=8

so it process 3*8 bytes, then move again 8 bytes to the right ?

then after that

for (int r = 0; r < srcHeight/3; r++)
{
d = &dst[iDestPitch* r];
s = &src[iSrcPitch * r*3];

}

it goes down 3 rows ? it so complex algorithm :/

Edited by Ahmed Egyptian, 21 March 2013 - 06:08 AM.

### #9Brother Bob  Moderators   -  Reputation: 8429

Like
2Likes
Like

Posted 21 March 2013 - 06:32 AM

From what I can decipher, it processed 8 consecutive 3x3 blocks per iteration. Therefore, you move left by 8x3=24 bytes, the width of 8 blocks, per column-iteration, and down 3 rows, or 3x width bytes, per row-iteration.

### #10Ahmed Egyptian  Members   -  Reputation: 137

Like
0Likes
Like

Posted 21 March 2013 - 07:07 AM

so to move back s = &src[srcPitch*r*3] ?

I have never coded image filtering like this before, is that easy for any intermediate or I'm dumb ?  I wrote it in ARM Neon, but someone fixed things in it...

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

PARTNERS