private void UpdateCameraFrame() { int num = 0; using (Dictionary <Image.PIXEL_FORMAT, Image> .ValueCollection.Enumerator enumerator = ((CameraDeviceImpl)CameraDevice.Instance).GetAllImages().Values.GetEnumerator()) { while (enumerator.MoveNext()) { ImageImpl imageImpl = (ImageImpl)enumerator.Current; VuforiaManagerImpl.ImageHeaderData imageHeaderData = (VuforiaManagerImpl.ImageHeaderData)Marshal.PtrToStructure(new IntPtr(this.mImageHeaderData.ToInt64() + (long)(num * Marshal.SizeOf(typeof(VuforiaManagerImpl.ImageHeaderData)))), typeof(VuforiaManagerImpl.ImageHeaderData)); imageImpl.Width = imageHeaderData.width; imageImpl.Height = imageHeaderData.height; imageImpl.Stride = imageHeaderData.stride; imageImpl.BufferWidth = imageHeaderData.bufferWidth; imageImpl.BufferHeight = imageHeaderData.bufferHeight; imageImpl.PixelFormat = (Image.PIXEL_FORMAT)imageHeaderData.format; if (imageHeaderData.reallocate == 1) { imageImpl.Pixels = new byte[VuforiaWrapper.Instance.QcarGetBufferSize(imageImpl.BufferWidth, imageImpl.BufferHeight, (int)imageImpl.PixelFormat)]; Marshal.FreeHGlobal(imageImpl.UnmanagedData); imageImpl.UnmanagedData = Marshal.AllocHGlobal(VuforiaWrapper.Instance.QcarGetBufferSize(imageImpl.BufferWidth, imageImpl.BufferHeight, (int)imageImpl.PixelFormat)); } else if (imageHeaderData.updated == 1) { imageImpl.CopyPixelsFromUnmanagedBuffer(); } num++; } } }
private void CreateInstanceImage() { this.mInstanceImageHeader = default(VuforiaManagerImpl.ImageHeaderData); this.mInstanceImageHeader.width = 0; this.mInstanceImageHeader.height = 0; this.mInstanceImageHeader.format = 16; if (this.CallNativeGetInstanceImage() == 0) { Debug.LogWarning("Not able to create VuMark instance image."); return; } this.mInstanceImage = new ImageImpl(); ImageImpl imageImpl = (ImageImpl)this.mInstanceImage; VuMarkTargetImpl.SetImageValues(this.mInstanceImageHeader, imageImpl); VuMarkTargetImpl.AllocateImage(imageImpl); this.mInstanceImageHeader.data = imageImpl.UnmanagedData; if (this.CallNativeGetInstanceImage() == 0) { Debug.LogWarning("Not able to create VuMark instance image."); return; } imageImpl.CopyPixelsFromUnmanagedBuffer(); this.mInstanceImage = imageImpl; }
private void UpdateImageContainer() { CameraDeviceImpl cameraDeviceImpl = (CameraDeviceImpl)CameraDevice.Instance; if (this.mNumImageHeaders != cameraDeviceImpl.GetAllImages().Count || (cameraDeviceImpl.GetAllImages().Count > 0 && this.mImageHeaderData == IntPtr.Zero)) { this.mNumImageHeaders = cameraDeviceImpl.GetAllImages().Count; Marshal.FreeHGlobal(this.mImageHeaderData); this.mImageHeaderData = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(VuforiaManagerImpl.ImageHeaderData)) * this.mNumImageHeaders); } int num = 0; using (Dictionary <Image.PIXEL_FORMAT, Image> .ValueCollection.Enumerator enumerator = cameraDeviceImpl.GetAllImages().Values.GetEnumerator()) { while (enumerator.MoveNext()) { ImageImpl imageImpl = (ImageImpl)enumerator.Current; IntPtr ptr = new IntPtr(this.mImageHeaderData.ToInt64() + (long)(num * Marshal.SizeOf(typeof(VuforiaManagerImpl.ImageHeaderData)))); Marshal.StructureToPtr(new VuforiaManagerImpl.ImageHeaderData { width = imageImpl.Width, height = imageImpl.Height, stride = imageImpl.Stride, bufferWidth = imageImpl.BufferWidth, bufferHeight = imageImpl.BufferHeight, format = (int)imageImpl.PixelFormat, reallocate = 0, updated = 0, data = imageImpl.UnmanagedData }, ptr, false); num++; } } }
public override bool SetFrameFormat(Image.PIXEL_FORMAT format, bool enabled) { if (enabled) { if (!this.mCameraImages.ContainsKey(format)) { if (VuforiaWrapper.Instance.QcarSetFrameFormat((int)format, 1) == 0) { Debug.LogError("Failed to set frame format"); return(false); } Image image = new ImageImpl(); image.PixelFormat = format; this.mCameraImages.Add(format, image); return(true); } } else if (this.mCameraImages.ContainsKey(format) && !this.mForcedCameraFormats.Contains(format)) { if (VuforiaWrapper.Instance.QcarSetFrameFormat((int)format, 0) == 0) { Debug.LogError("Failed to set frame format"); return(false); } return(this.mCameraImages.Remove(format)); } return(true); }
private static void AllocateImage(ImageImpl image) { int num = VuforiaWrapper.Instance.QcarGetBufferSize(image.BufferWidth, image.BufferHeight, (int)image.PixelFormat); image.Pixels = new byte[num]; Marshal.FreeHGlobal(image.UnmanagedData); image.UnmanagedData = Marshal.AllocHGlobal(num); }
public void RenderFrame(int frameIndex) { if (this.mLastFrameIdx != frameIndex) { Texture videoBackgroundTexture = VuforiaRenderer.Instance.VideoBackgroundTexture; if (videoBackgroundTexture != null && videoBackgroundTexture is Texture2D) { Texture2D texture2D = (Texture2D)videoBackgroundTexture; ImageImpl imageImpl = (ImageImpl)CameraDevice.Instance.GetCameraImage(Image.PIXEL_FORMAT.RGBA8888); if (imageImpl != null) { if (texture2D.width != imageImpl.BufferWidth || texture2D.height != imageImpl.BufferHeight || texture2D.format != TextureFormat.RGB24) { texture2D.Resize(imageImpl.BufferWidth, imageImpl.BufferHeight, TextureFormat.RGB24, false); } texture2D.SetPixels32(imageImpl.GetPixels32()); texture2D.Apply(); } } this.mLastFrameIdx = frameIndex; } }
private void CreateLetterMask() { this.InitImageHeader(); ImageImpl imageImpl = (ImageImpl)this.mLetterMask; WordImpl.SetImageValues(this.mLetterImageHeader, imageImpl); WordImpl.AllocateImage(imageImpl); this.mLetterImageHeader.data = imageImpl.UnmanagedData; IntPtr intPtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(VuforiaManagerImpl.ImageHeaderData))); Marshal.StructureToPtr(this.mLetterImageHeader, intPtr, false); VuforiaWrapper.Instance.WordGetLetterMask(base.ID, intPtr); this.mLetterImageHeader = (VuforiaManagerImpl.ImageHeaderData)Marshal.PtrToStructure(intPtr, typeof(VuforiaManagerImpl.ImageHeaderData)); if (this.mLetterImageHeader.reallocate == 1) { Debug.LogWarning("image wasn't allocated correctly"); return; } imageImpl.CopyPixelsFromUnmanagedBuffer(); this.mLetterMask = imageImpl; Marshal.FreeHGlobal(intPtr); }
private static void SetImageValues(VuforiaManagerImpl.ImageHeaderData imageHeader, ImageImpl image) { image.Width = imageHeader.width; image.Height = imageHeader.height; image.Stride = imageHeader.stride; image.BufferWidth = imageHeader.bufferWidth; image.BufferHeight = imageHeader.bufferHeight; image.PixelFormat = (Image.PIXEL_FORMAT)imageHeader.format; }