public void TestFileBlockIds() { var fileBlock = new FileBlock(); var animBlock = new AnimationBlock(); var animHeaderBlock = new AnimationHeaderBlock(); var sheetBlock = new AnimationSheetBlock(); var frameBlock = new FrameBlock(); var treeBlock = new ProjectTreeBlock(); // Assert block IDs Assert.AreEqual(FileBlock.BLOCKID_NULL, fileBlock.BlockID, "The ID for the FileBlock must equal to FileBlock.BLOCKID_NULL"); Assert.AreEqual(FileBlock.BLOCKID_ANIMATION, animBlock.BlockID, "The ID for the AnimationBlock instance does not match the ID specified for it on the FileBlock class"); Assert.AreEqual(FileBlock.BLOCKID_ANIMATION_HEADER, animHeaderBlock.BlockID, "The ID for the AnimationHeaderBlock instance does not match the ID specified for it on the FileBlock class"); Assert.AreEqual(FileBlock.BLOCKID_ANIMATIONSHEET, sheetBlock.BlockID, "The ID for the AnimationSheetBlock instance does not match the ID specified for it on the FileBlock class"); Assert.AreEqual(FileBlock.BLOCKID_FRAME, frameBlock.BlockID, "The ID for the frameBlock instance does not match the ID specified for it on the FileBlock class"); Assert.AreEqual(FileBlock.BLOCKID_PROJECTTREE, treeBlock.BlockID, "The ID for the treeBlock instance does not match the ID specified for it on the FileBlock class"); }
public void FrameBlockDeltaTest() { for (int oldbyte = byte.MinValue; oldbyte <= byte.MaxValue; oldbyte++) { for (int newbyte = byte.MinValue; newbyte <= byte.MaxValue; newbyte++) { var delta = FrameBlock.EncodeDelta((byte)oldbyte, (byte)newbyte); var reconstructedNewByte = FrameBlock.ReconstructOriginal((byte)oldbyte, delta); var error = Math.Abs(newbyte - reconstructedNewByte); Assert.IsTrue(error < 2); } } }
/// <summary> /// Add the <see cref="FrameBlock"/> to the passed <see cref="AnimationMeshBlock"/>. /// </summary> public void AddFrameBlock(AnimationMeshBlock amb) { if (amb == null) { return; } amb.Part2 = (AnimationFrameBlock[])Helper.Add(amb.Part2, FrameBlock); if (ruf) { FrameBlock.RemoveUnneededFrames(); } FrameBlock.Duration = FrameBlock.GetDuration(); }
private static Queue <FrameBlock> GetFrameBlockQueue() { var queue = new Queue <FrameBlock>(); var ctxFactory = new JpegFrameContextFactory(VideoConstants.VideoBlockSize, VideoConstants.VideoBlockSize); for (byte i = 0; i < 100; i++) { var block = new FrameBlock(ctxFactory); block.BlockX = i; block.BlockY = i; // block.FrameNumber = i; block.JpegQuality = 50; var payload = new byte[i + 1]; block.EncodedStream = new MemoryStream(payload); queue.Enqueue(block); } return(queue); }
public void EncodingOffsetTest() { var ctxFactory = new JpegFrameContextFactory(VideoConstants.VideoBlockSize, VideoConstants.VideoBlockSize); for (int offset = 0; offset < 255; offset++) { // Setup the frame. var frame = new FrameBlock(ctxFactory) { BlockType = BlockType.Jpeg }; for (int i = 0; i < frame.RgbaRaw.Length; i++) { frame.RgbaRaw[i] = (byte)(i + offset); } var original = new byte[frame.RgbaRaw.Length]; Buffer.BlockCopy(frame.RgbaRaw, 0, original, 0, original.Length); // Encode and decode it. frame.Encode(50); frame.Decode(); // Calculate and display the error int totalError = 0; for (int i = 0; i < original.Length; i++) { if (i % 4 != 3) { totalError += Math.Abs(frame.RgbaRaw[i] - original[i]); } } double samples = original.Length * .75; double averageError = totalError / samples; Debug.WriteLine("Offset:{0}; Error:{1:0.00}", offset, averageError); } }
public void FrameBlockJpegDeltaEncodingTest() { // ks 10/28/11 - This particular method doesn't really test anything, other than that everything runs without exceptions, // but it's a helpful little framework to have around when troubleshooting encoding issues, so I'll leave it here. const int offset = 20; var ctxFactory = new JpegFrameContextFactory(VideoConstants.VideoBlockSize, VideoConstants.VideoBlockSize); var oldFrame = new FrameBlock(ctxFactory) { BlockType = BlockType.Jpeg }; var newFrame = new FrameBlock(ctxFactory) { BlockType = BlockType.JpegDiff }; var newFrameWithJpeg = new FrameBlock(ctxFactory) { BlockType = BlockType.Jpeg }; for (int i = 0; i < oldFrame.RgbaRaw.Length; i++) { oldFrame.RgbaRaw[i] = (byte)i; newFrame.RgbaRaw[i] = (byte)(i + offset); newFrameWithJpeg.RgbaRaw[i] = (byte)(i + offset); } newFrame.SubtractFrom(oldFrame, double.MinValue, double.MaxValue); // Make some copies for later comparison var oldFrameOriginal = new byte[oldFrame.RgbaRaw.Length]; Buffer.BlockCopy(oldFrame.RgbaRaw, 0, oldFrameOriginal, 0, oldFrameOriginal.Length); var newFrameOriginal = new byte[newFrame.RgbaRaw.Length]; Buffer.BlockCopy(newFrame.RgbaRaw, 0, newFrameOriginal, 0, newFrameOriginal.Length); var newFrameDelta = new byte[newFrame.RgbaDelta.Length]; Buffer.BlockCopy(newFrame.RgbaDelta, 0, newFrameDelta, 0, newFrameDelta.Length); oldFrame.Encode(50); oldFrame.Decode(); newFrameWithJpeg.Encode(50); newFrameWithJpeg.Decode(); newFrame.Encode(50); newFrame.Decode(); newFrame.AddTo(oldFrame); int totalOldError = 0; int totalNewError = 0; int totalNewDeltaError = 0; int totalNewJpegError = 0; for (int i = 0; i < newFrameOriginal.Length; i++) { if (i % 4 != 3) { totalOldError += Math.Abs(oldFrame.RgbaRaw[i] - oldFrameOriginal[i]); totalNewError += Math.Abs(newFrame.RgbaRaw[i] - newFrameOriginal[i]); totalNewDeltaError += Math.Abs(newFrame.RgbaDelta[i] - newFrameDelta[i]); totalNewJpegError += Math.Abs(newFrameWithJpeg.RgbaRaw[i] - newFrameOriginal[i]); Debug.WriteLine("OLD: Original: {0}; Encoded: {1}; Error: {2}; NEWJPEG: Original: {3}; Encoded: {4}; Error: {5}", oldFrameOriginal[i], oldFrame.RgbaRaw[i], Math.Abs(oldFrameOriginal[i] - oldFrame.RgbaRaw[i]), newFrameOriginal[i], newFrameWithJpeg.RgbaRaw[i], Math.Abs(newFrameOriginal[i] - newFrameWithJpeg.RgbaRaw[i])); // Assert.IsTrue(diff < 2); //if (oldError > 2) //{ // Debug.WriteLine("JPEG: Original:{0}, Encoded:{1}, Error:{2}", oldFrameOriginal[i], oldFrame.RgbaRaw[i], oldError); //} // Assert.IsTrue(diff < 2); //if (newError > 2) //{ // Debug.WriteLine("JPEGDIFF: Original:{0}, Encoded:{1}, Error:{2}", newFrameOriginal[i], newFrame.RgbaRaw[i], newError); //} } } double samples = oldFrameOriginal.Length * .75; double averageOldError = totalOldError / samples; double averageNewError = totalNewError / samples; double averageNewDeltaError = totalNewDeltaError / samples; double averageNewJpegError = totalNewJpegError / samples; Debug.WriteLine("old error: {0:0.00}; new error: {1:0.00}; new delta error: {2:0.00}; new with jpeg error: {3:0.00}", averageOldError, averageNewError, averageNewDeltaError, averageNewJpegError); }
public BlockBase CreateAndInitialiseBlock(View hostView, Node parentNode, BlockBase parentBlock, BlockDefinition definition, FieldList contentData, bool isRoot) { if (definition != null) { BlockBase block = null; if (definition is ContainerBlockDefinition) { ContainerBlockDefinition cdef = (ContainerBlockDefinition)definition; switch (cdef.HintedType) { case UIHintedType.ApplicationBar: block = new ApplicationBarBlock(hostView, parentNode, parentBlock, definition, contentData, isRoot); break; case UIHintedType.NativeMessageBox: block = new NativeMessageBoxBlock(hostView, parentNode, parentBlock, definition, contentData, isRoot); break; case UIHintedType.TabBar: block = new TabBarBlock(hostView, parentNode, parentBlock, definition, contentData, isRoot); break; case UIHintedType.ActionSheet: block = new ActionSheetBlock(hostView, parentNode, parentBlock, definition, contentData, isRoot); break; case UIHintedType.Pivot: block = new PivotBlock(hostView, parentNode, parentBlock, definition, contentData, isRoot); break; case UIHintedType.Panorama: block = new PanoramaBlock(hostView, parentNode, parentBlock, definition, contentData, isRoot); break; case UIHintedType.None: default: { if (cdef is BoxLayoutBlockDefinition) { block = new BoxLayoutBlock(hostView, parentNode, parentBlock, definition, contentData, isRoot); } else if (cdef is GridBlockDefinition) { block = new GridBlock(hostView, parentNode, parentBlock, definition, contentData, isRoot); } else if (cdef is ListBlockDefinition) { block = new ListBlock(hostView, parentNode, parentBlock, definition, contentData, isRoot); } else if (cdef is FrameDefinition) { block = new FrameBlock(hostView, parentNode, parentBlock, definition, contentData, isRoot); } break; } } } else if (definition is CommonAtomicBlockDefinition) { CommonAtomicBlockDefinition cabdef = (CommonAtomicBlockDefinition)definition; switch (cabdef.HintedType) { case UIHintedType.ApplicationBarOptions: block = new ApplicationBarOptionsBlock(hostView, parentNode, parentBlock, definition, contentData, isRoot); break; case UIHintedType.ApplicationBarButton: block = new ApplicationBarButtonBlock(hostView, parentNode, parentBlock, definition, contentData, isRoot); break; case UIHintedType.ApplicationBarMenuItem: block = new ApplicationBarMenuItemBlock(hostView, parentNode, parentBlock, definition, contentData, isRoot); break; case UIHintedType.NativeMessageBoxBody: block = new NativeMessageBoxBodyBlock(hostView, parentNode, parentBlock, definition, contentData, isRoot); break; case UIHintedType.NativeMessageBoxButton: block = new NativeMessageBoxButtonBlock(hostView, parentNode, parentBlock, definition, contentData, isRoot); break; case UIHintedType.TabBarButton: block = new TabBarButtonBlock(hostView, parentNode, parentBlock, definition, contentData, isRoot); break; case UIHintedType.SystemTray: block = new SystemTrayBlock(hostView, parentNode, parentBlock, definition, contentData, isRoot); break; case UIHintedType.Placeholder: block = new PlaceholderBlock(hostView, parentNode, parentBlock, definition, contentData, isRoot); break; case UIHintedType.None: default: { if (cabdef is AtomicBlockDefinition) { block = new AtomicBlock(hostView, parentNode, parentBlock, definition, contentData, isRoot); } else if (cabdef is SingleSlotBlockDefinition) { block = new SingleSlotBlock(hostView, parentNode, parentBlock, definition, contentData, isRoot); } break; } } } else if (definition is ScrollingTextBlockDefinition) { block = new ScrollingTextBlock(hostView, parentNode, parentBlock, definition, contentData, isRoot); } else if (definition is MapPluginBlockDefinition) { block = new MapPluginBlock(hostView, parentNode, parentBlock, definition, contentData, isRoot); } if (block != null) { if (block.IsHidden) { block.Visibility = Visibility.Collapsed; } return(block); } } return(null); }
private void EncodeAndDecodeImages() { // Encode and decode a delta (p-frame) image. var ctxFactory = new JpegFrameContextFactory(VideoConstants.Height, VideoConstants.Width); var remoteSourceBlock = new FrameBlock(ctxFactory) { BlockType = BlockType.Jpeg }; Buffer.BlockCopy(mRawFrames[0], 0, remoteSourceBlock.RgbaRaw, 0, mRawFrames[0].Length); remoteSourceBlock.Encode(jpegQuality); remoteSourceBlock.Decode(); var imgJpegDeltaFrame0 = new Image(); SetImage(imgJpegDeltaFrame0, mRawFrames[0], remoteSourceBlock.RgbaRaw, remoteSourceBlock.EncodedStream.Length); lstJpegDeltaFrames.Items.Clear(); lstJpegDeltaFrames.Items.Add(imgJpegDeltaFrame0); int frames = Math.Min(mRawFrames.Count, 20); for (int i = 1; i < frames; i++) { // Create a new source block, since we need to start with one that hasn't been encoded yet. var localSourceBlock = new FrameBlock(ctxFactory) { BlockType = BlockType.Jpeg }; Buffer.BlockCopy(mRawFrames[i - 1], 0, localSourceBlock.RgbaRaw, 0, mRawFrames[i - 1].Length); // Create the delta block based on the local source block (which has the raw data). var deltaFrameBlock = new FrameBlock(ctxFactory) { BlockType = BlockType.JpegDiff }; Buffer.BlockCopy(mRawFrames[i], 0, deltaFrameBlock.RgbaRaw, 0, mRawFrames[i].Length); deltaFrameBlock.SubtractFrom(localSourceBlock, double.MinValue, double.MaxValue); deltaFrameBlock.Encode(jpegQuality); // Decode the delta block off of the remote source block (which has the cumulative encoded/decoded data) deltaFrameBlock.Decode(); deltaFrameBlock.AddTo(remoteSourceBlock); // Add the image to the UI. var img = new Image(); SetImage(img, mRawFrames[i], deltaFrameBlock.RgbaRaw, deltaFrameBlock.EncodedStream.Length); lstJpegDeltaFrames.Items.Add(img); // Set the remote source block to the most recently processed delta block for the next loop. remoteSourceBlock = deltaFrameBlock; } // Get the initial image and display it. SetImage(imgRawFrame0, mRawFrames[0], mRawFrames[0], mRawFrames[0].Length); SetImage(imgRawFrame1, mRawFrames[1], mRawFrames[1], mRawFrames[0].Length); // Encode and decode two images using the FJCore Jpeg library. var stream = EncodeJpeg(mRawFrames[0]); stream.Position = 0; var jpegOutputBmp = DecodeJpeg(stream); SetImage(imgJpegFrame0, mRawFrames[0], jpegOutputBmp, stream.Length); stream = EncodeJpeg(mRawFrames[1]); stream.Position = 0; jpegOutputBmp = DecodeJpeg(stream); SetImage(imgJpegFrame1, mRawFrames[1], jpegOutputBmp, stream.Length); // Encode and decode two images using the JpegFrame extensions to the FJCore Jpeg library. var frameBlock0 = new FrameBlock(ctxFactory); Buffer.BlockCopy(mRawFrames[0], 0, frameBlock0.RgbaRaw, 0, mRawFrames[0].Length); frameBlock0.Encode(jpegQuality); frameBlock0.Decode(); SetImage(imgJpegFrameFrame0, mRawFrames[0], frameBlock0.RgbaRaw, frameBlock0.EncodedStream.Length); var frameBlock1 = new FrameBlock(ctxFactory); Buffer.BlockCopy(mRawFrames[1], 0, frameBlock1.RgbaRaw, 0, mRawFrames[1].Length); frameBlock1.Encode(jpegQuality); frameBlock1.Decode(); SetImage(imgJpegFrameFrame1, mRawFrames[1], frameBlock1.RgbaRaw, frameBlock1.EncodedStream.Length); }