public void clampToByteTest() { YuvVideoInfo info = new YuvVideoInfo(); YuvVideoHandler handler = new YuvVideoHandler(); handler.setVideo(TESTVIDEO_PATH, info); PrivateObject param0 = new PrivateObject(handler); YuvVideoHandler_Accessor target = new YuvVideoHandler_Accessor(param0); int[] val = new int[] { -1, 128, 0, 255, 256, 500, int.MaxValue, int.MinValue }; byte[] expected = new byte[] { 0, 128, 0, 255, 255, 255, 255, 0}; for (int i = 0; i < expected.Length; i++) { byte actual; actual = target.clampToByte(val[i]); Assert.AreEqual(expected[i], actual); } }
public void convertToRGB_Black_Test() { YuvVideoInfo info = new YuvVideoInfo(); YuvVideoHandler handler = new YuvVideoHandler(); handler.setVideo(TESTVIDEO_PATH, info); PrivateObject param0 = new PrivateObject(handler); YuvVideoHandler_Accessor target = new YuvVideoHandler_Accessor(param0); //Testing standard colors according to //http://msdn.microsoft.com/en-us/library/windows/desktop/bb530104%28v=vs.85%29.aspx int y = 16; int u = 128; int v = 128; Color expected = Color.Black; Color actual; actual = target.convertToRGB(y, u, v); Assert.AreEqual(expected.A, actual.A, "A not equal"); Assert.AreEqual(expected.R, actual.R, "R not equal"); Assert.AreEqual(expected.G, actual.G, "G not equal"); Assert.AreEqual(expected.B, actual.B, "B not equal"); }
public void writeFramesTest() { YuvVideoHandler_Accessor yvh = new YuvVideoHandler_Accessor(); writePath = sampleVideosPath + "\\americanFootball_352x240_125_Copy.yuv"; YuvVideoInfo info = new YuvVideoInfo(); info.path = readPath; info.width = 352; info.height = 240; info.yuvFormat = YuvFormat.YUV420_IYUV; yvh.setReadContext(readPath, info); // write context cannot be set without a valid read context YuvVideoInfo writeinfo = new YuvVideoInfo(); writeinfo.path = writePath; writeinfo.width = 352; writeinfo.height = 240; writeinfo.yuvFormat = YuvFormat.YUV420_IYUV; yvh.setWriteContext(writePath, writeinfo); System.Drawing.Bitmap testframe = yvh.getFrame(); System.Drawing.Bitmap[] frames = new System.Drawing.Bitmap[20]; for (int i = 0; i < frames.Length; i++) { frames[i] = testframe; } yvh.writeFrames(4, frames); yvh.writeFrames(1000, frames); // is > totalFrames try { yvh.writeFrames(-1, frames); Assert.Fail("no exception thrown"); } catch (Exception ) { } try { yvh.writeFrames(3, new System.Drawing.Bitmap[3]); Assert.Fail("no exception thrown"); } catch (Exception) { } try { File.Delete(writePath); } catch (Exception ) { } }
public void convertToYUV_White_Test() { YuvVideoInfo info = new YuvVideoInfo(); YuvVideoHandler handler = new YuvVideoHandler(); handler.setVideo(TESTVIDEO_PATH, info); PrivateObject param0 = new PrivateObject(handler); YuvVideoHandler_Accessor target = new YuvVideoHandler_Accessor(param0); //Testing standard colors according to //http://msdn.microsoft.com/en-us/library/windows/desktop/bb530104%28v=vs.85%29.aspx int y = 235; int u = 128; int v = 128; byte[] actual; actual = target.convertToYUV(Color.White); Assert.AreEqual(y, actual[0], "Y not equal"); Assert.AreEqual(u, actual[1], "U not equal"); Assert.AreEqual(v, actual[2], "V not equal"); }
public void getFrameTest() { YuvVideoHandler_Accessor yvh = new YuvVideoHandler_Accessor(); YuvVideoInfo info = new YuvVideoInfo(readPath); info.width = 352; info.height = 240; info.yuvFormat = YuvFormat.YUV420_IYUV; yvh.setReadContext(readPath, info); // yvh.setImportContext(readPath); // dangerous to use setimportcontext here, as it initializes a // yuv video info with the given path, without setting height/width int i = 0; System.Drawing.Bitmap testframe = null; while (yvh.positionReader < yvh.readVidInfo.frameCount) { try { testframe = yvh.getFrame(); } catch (Exception ) { Assert.Fail("Fail to get frame +" + i); } if (yvh.positionReader != i + 1) { Assert.Fail("Reader possition is " + yvh.positionReader + " while supposed to be " + i + 1); } if (testframe == null) { Assert.Fail("Frame number " + i + " is null" + " queuecount" + yvh.readQueue.Count); } if (testframe.Width != yvh.readVidInfo.width || testframe.Height != yvh.readVidInfo.height) { int[] param = new int[3] {i, testframe.Width, testframe.Height}; Assert.Fail("Wrong frame size for frame " + param[0] + ":" + param[1] + "," + param[2]); } i++; } try { yvh.positionReader = 500; testframe = yvh.getFrame(); Assert.Fail("no exception thrown"); } catch (Exception ) { } }