curiousity
curiousity

Reputation: 4741

image processing (general)

Sorry for dummy question but I am new in this and I could not find the answers.

  1. What is image stride?
  2. I am creating a buffer byte[] from Bitframe (there is no problem.) the bitframe width is 1200, the bitframe height is 900. So (As I suspect) buffer must be 1200*900 = 108,0000. But buffer size is stride * height = 432,0000 (4 * 108,0000).

Stride calculates as bitFrame.PixelWidth * ((bitFrame.Format.BitsPerPixel + 7) / 8); Then I using bitFrame.CopyPixels(pixels, stride, 0); //(byte[] pixels) And I have the function of processing current pixel (that is a struct.)

struct pixel {
    float r;
    float g;
    float b;
};

And there is also pixel processing function pixel processPixel(int x, int y). How could I use this function with my buffer ? I think it must be called somehow like this:

for(int i = 0; i < height; i++) {
  for(int j = 0; j < height; j++) {
    processPixel(i, j); 
    // But how could I use this function with my byte[] buffer?
    // And what exactly in this buffer? 
    // (why stride*height = 4*width*height? cause there are 3 values for pixel RGB)
  }
}

Upvotes: 1

Views: 1186

Answers (1)

BlueMonkMN
BlueMonkMN

Reputation: 25601

Stride is the number of bytes per row of pixels regardless of how many of those pixels are part of the image, so you have to use stride in calculating which bytes to affect based on 2-D coordinates:

void processPixel(int x, int y)
{
    // This is if your image format is 4 bytes per pixel such as RGBA
    int startByteIndex = x * 4 + y * stride; 
}

Edit: I was too rushed -- answer updated based on comments.

Upvotes: 0

Related Questions