예제 #1
0
파일: hq.py 프로젝트: Libertium/openmsx
def blendWeights(weights1, weights2, factor1 = 1, factor2 = 1):
	factor1 *= sum(weights2)
	factor2 *= sum(weights1)
	return simplifyWeights(
		factor1 * w1 + factor2 * w2
		for w1, w2 in izip(weights1, weights2)
		)
예제 #2
0
def blendWeights(weights1, weights2, factor1 = 1, factor2 = 1):
	factor1 *= sum(weights2)
	factor2 *= sum(weights1)
	return simplifyWeights(
		factor1 * w1 + factor2 * w2
		for w1, w2 in zip(weights1, weights2)
		)
예제 #3
0
def convertExpr4to2(case, expr4):
	weights2 = [0] * 4
	for weights4 in expr4:
		for neighbour, weight in enumerate(scaleWeights(weights4, 256)):
			weights2[neighbour] += weight
	weights2 = simplifyWeights(weights2)
	if ((case >> 4) & 15) in (2, 6, 8, 12):
		assert sorted(weights2) == [0, 2, 7, 23]
		weightMap = { 0: 0, 2: 1, 7: 1, 23: 2 }
	elif ((case >> 4) & 15) in (0, 1, 4, 5):
		assert sorted(weights2) == [0, 3, 3, 10]
		weightMap = { 0: 0, 3: 1, 10: 2 }
	else:
		weightMap = None
	if weightMap:
		weights2 = tuple(weightMap[weight] for weight in weights2)
	return [weights2]
예제 #4
0
파일: hq.py 프로젝트: Libertium/openmsx
def lighten(case, weights, neighbourPreference):
	equalNeighboursOf = neighbourToSet[case]
	if equalNeighboursOf is None:
		return None
	else:
		done = set()
		newWeights = [ 0 ] * 9
		for neighbour in neighbourPreference:
			if neighbour not in done:
				equalNeighbours = equalNeighboursOf[neighbour]
				newWeights[neighbour] = sum(
					weights[n] for n in equalNeighbours
					)
				done |= equalNeighbours
		for c in (0, 1, 2, 6, 7, 8):
			# Only c4, c5, c6 have non-zero weight.
			assert newWeights[c] == 0
		return simplifyWeights(newWeights)
예제 #5
0
    for expr in [[expr[subPixel] for subPixel in quadrantMap]
                 for expr in pixelExpr]:
        for weights in expr:
            for neighbour in (2, 5, 6, 7, 8):
                assert weights[neighbour] == 0, weights
    return [[
        extractTopLeftWeights(expr[subPixel]) for subPixel in quadrantMap
    ] for expr in pixelExpr]


def convertExpr4to2(case, expr4):
    weights2 = [0] * 4
    for weights4 in expr4:
        for neighbour, weight in enumerate(scaleWeights(weights4, 256)):
            weights2[neighbour] += weight
    weights2 = simplifyWeights(weights2)
    if ((case >> 4) & 15) in (2, 6, 8, 12):
        assert sorted(weights2) == [0, 2, 7, 23]
        weightMap = {0: 0, 2: 1, 7: 1, 23: 2}
    elif ((case >> 4) & 15) in (0, 1, 4, 5):
        assert sorted(weights2) == [0, 3, 3, 10]
        weightMap = {0: 0, 3: 1, 10: 2}
    else:
        weightMap = None
    if weightMap:
        weights2 = tuple(weightMap[weight] for weight in weights2)
    return [weights2]


def convert4to2(topLeftQuadrant4):
    return [
예제 #6
0
	if equalNeighboursOf is None:
		return None
	else:
		done = set()
		newWeights = [ 0 ] * 9
		for neighbour in neighbourPreference:
			if neighbour not in done:
				equalNeighbours = equalNeighboursOf[neighbour]
				newWeights[neighbour] = sum(
					weights[n] for n in equalNeighbours
					)
				done |= equalNeighbours
		for c in (0, 1, 2, 6, 7, 8):
			# Only c4, c5, c6 have non-zero weight.
			assert newWeights[c] == 0
		return simplifyWeights(newWeights)

def makeLite(pixelExpr, biased):
	zoom = getZoom(pixelExpr)
	biasLeft  = (4, 3, 5, 1, 7, 0, 2, 6, 8)
	biasRight = (4, 5, 3, 1, 7, 2, 0, 8, 6)
	if biased:
		center = (zoom - 1) / 2
		neighbourPreferences = [
			biasRight if subPixel % zoom > center else biasLeft
			for subPixel in range(zoom ** 2)
			]
	else:
		neighbourPreferences = [ biasLeft ] * (zoom ** 2)
	return [
		[ lighten(case, weights, pref)