Log in or register to post comments

Found bug in Image class, how to report it?

March 26, 2012 - 2:05pm #1

Seems there's a bug in Image.CopyPixelsFromUnmanagedBuffer(). It's copying width * height bytes. Not accounting for the depth. So for 565 it was off by a factor of 2, and for 888 off by a factor of 3. Not sure about the other formats, those are the two I care about. Fixed locally.

Re: Found bug in Image class, how to report it?

March 27, 2012 - 12:47pm #3

(I really hate how this site works, this is the second time I have to type this all in):

In Image.cs I make this modification:

    // Called by the QCARBehaviour when the unmanaged data buffer has been
    // filled:
    public void CopyPixelsFromUnmanagedBuffer()
    {
        if (mData == null || mUnmanagedData == IntPtr.Zero)
        {
            Debug.LogError("Image: Cannot copy image image data.");
            return;
        }
		int size = mBufferWidth * mBufferHeight;
		if (mPixelFormat == PIXEL_FORMAT.RGB565)
			size *= 2;
		else if (mPixelFormat == PIXEL_FORMAT.RGB888)
			size *= 3;
        Marshal.Copy(mUnmanagedData, mData, 0, size);
        mDataSet = true;
    }

It's accessed from code I got from another user on another thread:

using UnityEngine;
using System;

public class ImageHandler : MonoBehaviour, ITrackerEventHandler
{
    private Image.PIXEL_FORMAT mPixelFormat = Image.PIXEL_FORMAT.RGB888;
	public byte[] pixelBytes = null;
	public CameraDevice.VideoModeData videoModeData;

    void Start()
    {
        QCARBehaviour qcarBehaviour = (QCARBehaviour) FindObjectOfType(typeof(QCARBehaviour));
        if (qcarBehaviour)
        {
            qcarBehaviour.RegisterTrackerEventHandler(this);
			videoModeData = CameraDevice.Instance.GetVideoMode (qcarBehaviour.CameraDeviceModeSetting);
        }

        CameraDevice.Instance.SetFrameFormat(mPixelFormat, true);
    }

    public void OnTrackablesUpdated()
    {
        Image cameraImage = CameraDevice.Instance.GetCameraImage(mPixelFormat);

        if (cameraImage != null)
        {
            pixelBytes = cameraImage.Pixels;
	//		Debug.Log("pixelBytes.Length = "+pixelBytes.Length);
            // Do something with the pixels!
        }
    }
}

Re: Found bug in Image class, how to report it?

March 26, 2012 - 8:26pm #2

I can look into this. Can you post an example of how you're obtaining the Image so that I can replicate your case?

Log in or register to post comments