Hi,
I am trying to get
CHDKPTPRemote to display the live screen from my
SX60HS. When I do, I get this exception when I try to call session.GetLiveImage(live_image).
"could not get live image: Index was outside the bounds of the array.
at CHDKPTPRemote.Session.add_pixel(Byte[] buf, Int32 pos, Byte y, SByte u, SByte v) in D:\Home Data\Visual Studio 2010\Projects\CHDKPTPRemote-master LiveView Branch\CHDKPTPRemote-master\CHDKPTPRemote\Session.cs:line 207
at CHDKPTPRemote.Session.GetLiveImage(Boolean set_active_area, Rectangle& active_area, Bitmap old_img) in D:\Home Data\Visual Studio 2010\Projects\CHDKPTPRemote-master LiveView Branch\CHDKPTPRemote-master\CHDKPTPRemote\Session.cs:line 302"
The 302 line in GetLiveImage(live_image) is highlighted below
// convert uyvyyy to rgbrgbrgbrgb
byte[] pixels = new byte[vp_max_width * vp_max_height * 3];
for (int img_idx = image_start, pxls_idx = 0; img_idx < image_end; img_idx += ((vp_buffer_width - vp_max_width) * 6) / 4)
{
for (int x = 0; x < vp_max_width; x++, img_idx += 6, pxls_idx += 12)
{
sbyte u = (sbyte)img[img_idx];
sbyte v = (sbyte)img[img_idx + 2];
add_pixel(pixels, pxls_idx, img[img_idx + 1], u, v); // line 302
add_pixel(pixels, pxls_idx + 3, img[img_idx + 3], u, v);
add_pixel(pixels, pxls_idx + 6, img[img_idx + 4], u, v);
add_pixel(pixels, pxls_idx + 9, img[img_idx + 5], u, v);
}
}
The error comes in line 207 in the add_pixel method below
private void add_pixel(byte[] buf, int pos, byte y, sbyte u, sbyte v)
{
buf[pos] = clip(((y << 12) + u * 7258 + 204😎 >> 12); // b // line 207
buf[pos + 1] = clip(((y << 12) - u * 1411 - v * 2925 + 204😎 >> 12); // g
buf[pos + 2] = clip(((y << 12) + v * 5743 + 204😎 >> 12); // r
}
I am guessing the numbers like 7258, 2925, etc in add_pixel() are not correct for the SX60 but I don't know where they came from. Any idea on how to solve my problem?
thanks in advance