Skip to content

Commit

Permalink
Add updated tests for Lut
Browse files Browse the repository at this point in the history
  • Loading branch information
myrsloik committed Jul 14, 2013
1 parent 735816a commit 83d9594
Showing 1 changed file with 32 additions and 57 deletions.
89 changes: 32 additions & 57 deletions test/filter_test.py
Expand Up @@ -5,6 +5,10 @@ class FilterTestSequence(unittest.TestCase):

def setUp(self):
self.core = vs.get_core()
self.Lut = self.core.std.Lut
self.Lut2 = self.core.std.Lut2
self.BlankClip = self.core.std.BlankClip
self.mask = lambda val, bits: val & ((1 << bits) - 1)

def checkDifference(self, cpu, gpu):
diff = self.core.std.PlaneDifference([cpu, gpu], 0, prop="PlaneDifference0")
Expand All @@ -18,98 +22,69 @@ def checkDifference(self, cpu, gpu):
self.assertEqual(frame.props.PlaneDifference2[0], 0)

def testLUT16Bit(self):
clip = self.core.std.BlankClip(format=vs.YUV420P16, color=[69, 242, 115])
clip = self.BlankClip(format=vs.YUV420P16, color=[69, 242, 115])

lut = []
for x in range(2 ** clip.format.bits_per_sample):
lut.append(x)

ret = self.core.std.Lut(clip, lut, [0, 1, 2])
ret = self.Lut(clip, planes=[0, 1, 2], function=lambda x: x)

self.checkDifference(clip, ret)

def testLUT2_8Bit(self):
clipx = self.core.std.BlankClip(format=vs.YUV420P8, color=[69, 242, 115])
clipy = self.core.std.BlankClip(format=vs.YUV420P8, color=[115, 103, 205])

lut = []
for y in range(2 ** clipy.format.bits_per_sample):
for x in range(2 ** clipx.format.bits_per_sample):
lut.append(x)
clipx = self.BlankClip(format=vs.YUV420P8, color=[69, 242, 115])
clipy = self.BlankClip(format=vs.YUV420P8, color=[115, 103, 205])

ret = self.core.std.Lut2(clips=[clipx, clipy], lut=lut, planes=[0, 1, 2], bits=8)
ret = self.Lut2(clips=[clipx, clipy], planes=[0, 1, 2], function=lambda x, y: x, bits=8)
self.checkDifference(clipx, ret)

ret = self.core.std.Lut2(clips=[clipx, clipy], lut=lut, planes=[0, 1, 2], bits=10)
comp = self.core.std.BlankClip(format=vs.YUV420P10, color=[69, 242, 115])
ret = self.Lut2(clips=[clipx, clipy], planes=[0, 1, 2], function=lambda x, y: x, bits=10)
comp = self.BlankClip(format=vs.YUV420P10, color=[69, 242, 115])
self.checkDifference(comp, ret)

def testLUT2_8Bit_10Bit(self):
# Check 8-bit, 10-bit source.
clipx = self.core.std.BlankClip(format=vs.YUV420P8, color=[69, 242, 115])
clipy = self.core.std.BlankClip(format=vs.YUV420P10, color=[15, 900, 442])

lut = []
for y in range(2 ** clipy.format.bits_per_sample):
for x in range(2 ** clipx.format.bits_per_sample):
lut.append(x)
clipx = self.BlankClip(format=vs.YUV420P8, color=[69, 242, 115])
clipy = self.BlankClip(format=vs.YUV420P10, color=[15, 900, 442])

ret = self.core.std.Lut2(clips=[clipx, clipy], lut=lut, planes=[0, 1, 2], bits=8)
ret = self.Lut2(clips=[clipx, clipy], planes=[0, 1, 2], function=lambda x, y: self.mask(x, 8), bits=8)
self.checkDifference(clipx, ret)

ret = self.core.std.Lut2(clips=[clipx, clipy], lut=lut, planes=[0, 1, 2], bits=10)
comp = self.core.std.BlankClip(format=vs.YUV420P10, color=[69, 242, 115])
ret = self.Lut2(clips=[clipx, clipy], planes=[0, 1, 2], function=lambda x, y: x, bits=10)
comp = self.BlankClip(format=vs.YUV420P10, color=[69, 242, 115])
self.checkDifference(comp, ret)

# Check 10-bit, 8-bit source.
# Colors are 8-bit levels for 10-bit clip so that we can verify output.
clipx = self.core.std.BlankClip(format=vs.YUV420P10, color=[15, 235, 115])
clipy = self.core.std.BlankClip(format=vs.YUV420P8, color=[69, 242, 115])
clipx = self.BlankClip(format=vs.YUV420P10, color=[15, 235, 115])
clipy = self.BlankClip(format=vs.YUV420P8, color=[69, 242, 115])

lut = []
for y in range(2 ** clipy.format.bits_per_sample):
for x in range(2 ** clipx.format.bits_per_sample):
lut.append(x)

ret = self.core.std.Lut2(clips=[clipx, clipy], lut=lut, planes=[0, 1, 2], bits=8)
comp = self.core.std.BlankClip(format=vs.YUV420P8, color=[15, 235, 115])
ret = self.Lut2(clips=[clipx, clipy], planes=[0, 1, 2], function=lambda x, y: self.mask(x, 8), bits=8)
comp = self.BlankClip(format=vs.YUV420P8, color=[15, 235, 115])
self.checkDifference(comp, ret)

ret = self.core.std.Lut2(clips=[clipx, clipy], lut=lut, planes=[0, 1, 2], bits=10)
ret = self.Lut2(clips=[clipx, clipy], planes=[0, 1, 2], function=lambda x, y: x, bits=10)
self.checkDifference(clipx, ret)

def testLUT2_9Bit_10Bit(self):
# Check 9-bit, 10-bit source.
clipx = self.core.std.BlankClip(format=vs.YUV420P9, color=[384, 10, 500])
clipy = self.core.std.BlankClip(format=vs.YUV420P10, color=[15, 600, 900])

lut = []
for y in range(2 ** clipy.format.bits_per_sample):
for x in range(2 ** clipx.format.bits_per_sample):
lut.append(x)
clipx = self.BlankClip(format=vs.YUV420P9, color=[384, 10, 500])
clipy = self.BlankClip(format=vs.YUV420P10, color=[15, 600, 900])

ret = self.core.std.Lut2(clips=[clipx, clipy], lut=lut, planes=[0, 1, 2], bits=9)
ret = self.Lut2(clips=[clipx, clipy], planes=[0, 1, 2], function=lambda x, y: self.mask(x, 9), bits=9)
self.checkDifference(clipx, ret)

ret = self.core.std.Lut2(clips=[clipx, clipy], lut=lut, planes=[0, 1, 2], bits=8)
comp = self.core.std.BlankClip(format=vs.YUV420P8, color=[128, 10, 244])
ret = self.Lut2(clips=[clipx, clipy], planes=[0, 1, 2], function=lambda x, y: self.mask(x, 8), bits=8)
comp = self.BlankClip(format=vs.YUV420P8, color=[128, 10, 244])
self.checkDifference(comp, ret)

# Check 10-bit, 9-bit source.
clipx = self.core.std.BlankClip(format=vs.YUV420P10, color=[384, 10, 500])
clipy = self.core.std.BlankClip(format=vs.YUV420P9, color=[15, 384, 511])

lut = []
for y in range(2 ** clipy.format.bits_per_sample):
for x in range(2 ** clipx.format.bits_per_sample):
lut.append(x)
clipx = self.BlankClip(format=vs.YUV420P10, color=[384, 10, 500])
clipy = self.BlankClip(format=vs.YUV420P9, color=[15, 384, 511])

ret = self.core.std.Lut2(clips=[clipx, clipy], lut=lut, planes=[0, 1, 2], bits=9)
comp = self.core.std.BlankClip(format=vs.YUV420P9, color=[384, 10, 500])
ret = self.Lut2(clips=[clipx, clipy], planes=[0, 1, 2], function=lambda x, y: self.mask(x, 9), bits=9)
comp = self.BlankClip(format=vs.YUV420P9, color=[384, 10, 500])
self.checkDifference(comp, ret)

ret = self.core.std.Lut2(clips=[clipx, clipy], lut=lut, planes=[0, 1, 2], bits=8)
comp = self.core.std.BlankClip(format=vs.YUV420P8, color=[128, 10, 244])
ret = self.Lut2(clips=[clipx, clipy], planes=[0, 1, 2], function=lambda x, y: self.mask(x, 8), bits=8)
comp = self.BlankClip(format=vs.YUV420P8, color=[128, 10, 244])
self.checkDifference(comp, ret)

if __name__ == '__main__':
Expand Down

0 comments on commit 83d9594

Please sign in to comment.