Using ESCAPI with Allegro
Bingocat

I am trying to use a library called ESCAPI (http://sol.gfxile.net/escapi/index.html) with allegro to get images from the webcam. I've gotten the data from the webcam, but I am having very strange problems copying that to an allegro bitmap. The image is only copied down to certain parts, which seem to be color sensitive. Like it only goes down to a certain part on my face and if I move my face up and down more or less of the image gets shown.

#SelectExpand
1ALLEGRO_LOCKED_REGION *reg = al_lock_bitmap(image, ALLEGRO_PIXEL_FORMAT_ARGB_8888, ALLEGRO_LOCK_WRITEONLY); 2 3_memccpy(reg->data, cap.mTargetBuf, cap.mHeight * cap.mWidth * reg->pixel_size, cap.mHeight * cap.mWidth * reg->pixel_size); 4al_unlock_bitmap(image);

SiegeLord

You need to copy the data row-by-row and use the locked region's pitch argument.

for (int y = 0; y < cap.mHeight; y++) {
  memcpy(reg->data + y * reg->pitch,
    cap.mTargetBuf + y * cap.mWidth * reg->pixel_size,
    cap.mWidth * reg->pixel_size)
}

The reason why is that OpenGL bitmaps are stored upside down, and also if the bitmap width isn't a power of 2, then there is padding on the right of each row.

Bingocat

Okay that definitely works better, but it copies the picture into an area like 1/4 of the bitmap and if I change the destination line at all it crashes. I also had to add in the (char *) for it to work at all. Any thoughts?

memcpy((char *)reg->data + y * reg->pitch,

SiegeLord

Are mWidth and mHeight what you expect with respect to the bitmap width/height? Is the image cropped/distorted/discolored in some way?

Bingocat

The width and height are the same for the allegro bitmap and also the webcam image. There is also no cropping or color distortion. The bitmap is just no as tall as it should be.

Neil Roy

Do you have the pixel size correct? I would check everything in your size calculations for your memcopy.

Bingocat

I ended up trying this and it seems to be working correctly now.

memcpy(reg->data, cap.mTargetBuf, cap.mWidth * cap.mHeight * reg->pixel_size);

Thread #617274. Printed from Allegro.cc