Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use Python3 #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions pyhq2x.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python
#!/usr/bin/env python3

import Image
from PIL import Image

# Constants for indicating coordinates in a pixel's context
TOP_LEFT = 0
Expand All @@ -16,7 +16,7 @@
# There are eight flags: the cells in the context, skipping the center
context_flag = {}
cur_flag = 1
for i in xrange(9):
for i in range(9):
if i == CENTER:
continue
context_flag[i] = cur_flag
Expand Down Expand Up @@ -125,8 +125,8 @@ def get_px(x, y):

return sourcegrid[x, y]

for x in xrange(w):
for y in xrange(h):
for x in range(w):
for y in range(h):
# This is a flattened 3x3 grid with the current pixel in the
# middle; if the pixel is on an edge, the row/column in the void is
# just a copy of the edge
Expand All @@ -138,10 +138,10 @@ def get_px(x, y):

tl, tr, bl, br = hq2x_pixel(context)

destgrid[x * 2, y * 2] = tl
destgrid[x * 2 + 1, y * 2] = tr
destgrid[x * 2, y * 2 + 1] = bl
destgrid[x * 2 + 1, y * 2 + 1] = br
destgrid[x * 2, y * 2] = tuple(map(lambda x: int(x), tl))
destgrid[x * 2 + 1, y * 2] = tuple(map(lambda x: int(x), tr))
destgrid[x * 2, y * 2 + 1] = tuple(map(lambda x: int(x), bl))
destgrid[x * 2 + 1, y * 2 + 1] = tuple(map(lambda x: int(x), br))

return dest

Expand All @@ -162,7 +162,7 @@ def hq2x_pixel(context):
yuv_px = rgb_to_yuv(context[CENTER])

pattern = 0
for bit in xrange(9):
for bit in range(9):
if bit != CENTER and not yuv_equal(yuv_context[bit], yuv_px):
pattern = pattern | context_flag[bit]

Expand Down