private MLResult InternalGetThumbnail(long entryId, out Texture2D imageThumbnail) { imageThumbnail = null; if (!_watchHistory.ContainsKey(entryId)) { return(MLResult.Create(MLResult.Code.InvalidParam, "Unknown entry Id")); } var thumbnail = new MLImageNativeBindings.MLImageNative(); MLResult.Code resultCode = MLScreensNativeBindings.MLScreensGetWatchHistoryThumbnail(entryId, ref thumbnail); var result = MLResult.Create(resultCode); if (!result.IsOk) { return(result); } imageThumbnail = new Texture2D((int)thumbnail.Width, (int)thumbnail.Height, TextureFormat.RGB24, false, true); imageThumbnail.LoadRawTextureData(thumbnail.Image, (int)(thumbnail.Height * thumbnail.Width) * RGBBytesPerPixel); resultCode = MLScreensNativeBindings.MLScreensReleaseWatchHistoryThumbnail(ref thumbnail); result = MLResult.Create(resultCode); return(result); }
private static MLImageNativeBindings.MLImageNative CreateGrayThumbnailImage() { byte[] imageData = Enumerable.Repeat(DefaultThumbnailIntensityValue, DefaultThumbnailWidth * DefaultThumbnailHeight * RGBBytesPerPixel).ToArray(); var thumbnail = new MLImageNativeBindings.MLImageNative { ImageType = MLImageNativeBindings.MLImageType.RGB24, Alignment = 1, Width = DefaultThumbnailWidth, Height = DefaultThumbnailHeight, Image = Marshal.AllocHGlobal(imageData.Length) }; Marshal.Copy(imageData, 0, thumbnail.Image, imageData.Length); return(thumbnail); }
/// Note: this function expects thumbnailImage to be 24-bit private MLImageNativeBindings.MLImageNative CreateThumbnailImage(Texture2D thumbnailImage) { // TODO: Change alignment to 4 and modify ConvertToByteArray to account for that. byte[] imageData = MLTextureUtils.ConvertToByteArray(thumbnailImage, out int numChannels); var thumbnail = new MLImageNativeBindings.MLImageNative { ImageType = MLImageNativeBindings.MLImageType.RGB24, Alignment = 1, Width = (uint)thumbnailImage.width, Height = (uint)thumbnailImage.height, Image = Marshal.AllocHGlobal(imageData.Length) }; Marshal.Copy(imageData, 0, thumbnail.Image, imageData.Length); return(thumbnail); }
private MLResult InternalUpdateWatchHistory(MLScreensWatchHistoryEntry entry, Texture2D thumbnailImage) { if (!entry.IsValid) { return(MLResult.Create(MLResult.Code.InvalidParam, "Invalid entry parameter")); } if (!_watchHistory.ContainsKey(entry.Id)) { return(MLResult.Create(MLResult.Code.InvalidParam, "Unknown entry Id")); } if (thumbnailImage != null && thumbnailImage.format != TextureFormat.RGB24) { return(MLResult.Create(MLResult.Code.InvalidParam, "Invalid thumbnail parameter format")); } MLScreensNativeBindings.MLScreensWatchHistoryEntryNative nativeEntry = MLScreensNativeBindings.MLScreensWatchHistoryEntryNative.Create(); nativeEntry.Data = entry; MLImageNativeBindings.MLImageNative thumbnail = thumbnailImage == null ? _defaultGrayThumbnailImage : CreateThumbnailImage(thumbnailImage); MLResult.Code resultCode = MLScreensNativeBindings.MLScreensUpdateWatchHistoryEntry(ref nativeEntry, ref thumbnail); if (thumbnail.Image != IntPtr.Zero && thumbnail.Image != _defaultGrayThumbnailImage.Image) { Marshal.FreeHGlobal(thumbnail.Image); } Marshal.FreeHGlobal(nativeEntry.Title); Marshal.FreeHGlobal(nativeEntry.Subtitle); Marshal.FreeHGlobal(nativeEntry.CustomData); var result = MLResult.Create(resultCode); if (result.IsOk) { _watchHistory[entry.Id] = entry; } return(result); }
/// <summary> /// Starts the screens object requests, Must be called to receive screens data from /// the underlying system /// </summary> protected override MLResult StartAPI() { MLResult.Code resultCode = MLScreensNativeBindings.MLScreensGetWatchHistoryList(ref _watchHistoryList); var result = MLResult.Create(resultCode); if (!result.IsOk) { MLPluginLog.ErrorFormat("MLScreens.StartAPI failed to retrieve saved screen information. Reason: {0}", result); return(result); } PopulateWatchHistory(); resultCode = MLScreensNativeBindings.MLScreensReleaseWatchHistoryList(ref _watchHistoryList); result = MLResult.Create(resultCode); if (!result.IsOk) { MLPluginLog.ErrorFormat("MLScreens.StartAPI failed to clean screens data. Reason: {0}", result); return(result); } _defaultGrayThumbnailImage = CreateGrayThumbnailImage(); return(result); }