Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def dc():
- global w, h
- def decode(inp):
- if(ord("A") <= ord(inp) <= ord("Z")):
- return(ord(inp) - ord("A"))
- if(ord("a") <= ord(inp) <= ord("z")):
- return(ord(inp) - ord("a") + 26)
- if(ord("0") <= ord(inp) <= ord("9")):
- return(ord(inp) - ord("0") + 52)
- if(inp == "+"):
- return(62)
- if(inp == "/"):
- return(63)
- st = ''
- while(len(st) < w * h * 4 // 3):
- st += input()
- st = list(map(decode, st))
- ans = []
- for i in range(0, len(st), 4):
- cnt = 0
- for j in st[i:i + 4]:
- cnt = cnt << 6
- cnt += j
- arr = []
- for j in range(3):
- a = cnt & (255 << (8 * j))
- a = a >> (8 * j)
- arr.insert(0, a)
- ans += arr
- out = []
- while(ans):
- out.append(ans[:w])
- ans = ans[w:]
- return out
- def bicubic(inp):
- def wrk(p, y, k):
- def sr(p, st, ln):
- out = []
- for i in p:
- out.append(i[st:st + ln])
- return out
- def cubicInterpolate(p, x):
- x *= 0.25
- a = p[1] + 0.5 * x*(p[2] - p[0] + x*(2.0*p[0] - 5.0*p[1] + 4.0*p[2] - p[3] + x*(3.0*(p[1] - p[2]) + p[3] - p[0])))
- return min(255, max(0, int(a)))
- def bicubicInterpolate(p, x, y):
- arr = [0] * 4
- arr[0] = cubicInterpolate(p[0], y)
- arr[1] = cubicInterpolate(p[1], y)
- arr[2] = cubicInterpolate(p[2], y)
- arr[3] = cubicInterpolate(p[3], y)
- return cubicInterpolate(arr, x)
- global w, h
- out = [0] * w * 2
- if(k):
- out[0] = p[y][0]
- out[1] = bicubicInterpolate(sr(p, 0, 4), 0.5, y)
- out[2] = p[y][1]
- for i in range(w - 3):
- out[i * 2 + 3] = bicubicInterpolate(sr(p, i, 4), 1.5, y)
- out[i * 2 + 4] = p[y][i + 2]
- out[-3] = bicubicInterpolate(sr(p, w - 4, 4), 2.5, y)
- out[-2] = out[-1] = p[y][-1]
- else:
- out[0] = bicubicInterpolate(sr(p, 0, 4), 0, y)
- out[1] = bicubicInterpolate(sr(p, 0, 4), 0.5, y)
- out[2] = bicubicInterpolate(sr(p, 0, 4), 1, y)
- for i in range(w - 3):
- out[i * 2 + 3] = bicubicInterpolate(sr(p, i, 4), 1.5, y)
- out[i * 2 + 4] = bicubicInterpolate(sr(p, i, 4), 2, y)
- out[-3] = bicubicInterpolate(sr(p, w - 4, 4), 2.5, y)
- out[-2] = out[-1] = bicubicInterpolate(sr(p, w - 4, 4), 3, y)
- return out
- arr = [0] * h * 2
- arr[0] = wrk(inp[:4], 0, 1)
- arr[1] = wrk(inp[:4], 0.5, 0)
- arr[2] = wrk(inp[:4], 1, 1)
- for i in range(h - 3):
- arr[i * 2 + 3] = wrk(inp[i:i + 4], 1.5, 0)
- arr[i * 2 + 4] = wrk(inp[i:i + 4], 2, 1)
- arr[-3] = wrk(inp[h - 4:h], 2.5, 0)
- arr[-2] = arr[-1] = wrk(inp[h - 4:h], 3, 1)
- return arr
- def middling(inp):
- global w, h
- out = [0] * h * 2
- for i in range(h):
- arr = [0] * w * 2
- for j in range(w - 1):
- arr[j * 2] = inp[i][j]
- arr[j * 2 + 1] = (inp[i][j] + inp[i][j + 1]) // 2
- arr[-2] = arr[-1] = inp[i][-1]
- out[i * 2] = arr
- for i in range(h - 1):
- arr = [0] * w * 2
- for j in range(w * 2):
- arr[j] = (out[i * 2][j] + out[i * 2 + 2][j]) // 2
- out[i * 2 + 1] = arr
- out[-1] = out[-2]
- return out
- def ic(inp):
- def toChr(i):
- dc = {
- 0:'A',
- 1:'B',
- 2:'C',
- 3:'D',
- 4:'E',
- 5:'F',
- 6:'G',
- 7:'H',
- 8:'I',
- 9:'J',
- 10:'K',
- 11:'L',
- 12:'M',
- 13:'N',
- 14:'O',
- 15:'P',
- 16:'Q',
- 17:'R',
- 18:'S',
- 19:'T',
- 20:'U',
- 21:'V',
- 22:'W',
- 23:'X',
- 24:'Y',
- 25:'Z',
- 26:'a',
- 27:'b',
- 28:'c',
- 29:'d',
- 30:'e',
- 31:'f',
- 32:'g',
- 33:'h',
- 34:'i',
- 35:'j',
- 36:'k',
- 37:'l',
- 38:'m',
- 39:'n',
- 40:'o',
- 41:'p',
- 42:'q',
- 43:'r',
- 44:'s',
- 45:'t',
- 46:'u',
- 47:'v',
- 48:'w',
- 49:'x',
- 50:'y',
- 51:'z',
- 52:'0',
- 53:'1',
- 54:'2',
- 55:'3',
- 56:'4',
- 57:'5',
- 58:'6',
- 59:'7',
- 60:'8',
- 61:'9',
- 62:'+',
- 63:'/'
- }
- return dc[i]
- for i in inp:
- for j in range(0, len(i), 3):
- cnt = 0
- for k in i[j:j + 3]:
- cnt = cnt << 8
- cnt += k
- p = ''
- for k in range(4):
- a = cnt & 63
- cnt -= a
- cnt = cnt >> 6
- p = toChr(a) + p
- print(p, end = '')
- w, h = map(int, input().split())
- print(w * 2, h * 2)
- arr = dc()
- arr = bicubic(arr)
- ic(arr)
- #f = open("output.txt", "w")
- #f.write(arr)
- '''
- for i in arr:
- for j in i:
- f.write(str(j) + ' ' * (4 - len(str(j))))
- f.write("\n")
- '''
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement