mirror of
https://github.com/GeoffreyFrogeye/steginack.git
synced 2024-11-20 18:06:04 +01:00
Made faster
This commit is contained in:
parent
be39a7d840
commit
3921dddaad
43
steginack.py
43
steginack.py
|
@ -2,58 +2,49 @@
|
||||||
|
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
import argparse
|
import argparse
|
||||||
from eta import ETA
|
|
||||||
|
|
||||||
get_bin = lambda x, n: x >= 0 and str(bin(x))[2:].zfill(n) or "-" + str(bin(x))[3:].zfill(n)
|
|
||||||
# From http://stackoverflow.com/a/21732313/2766106
|
|
||||||
|
|
||||||
|
|
||||||
def hideInFile(args):
|
def hideInFile(args):
|
||||||
inim = Image.open(args.infile)
|
inim = Image.open(args.infile)
|
||||||
hideim = Image.open(args.hidefile)
|
hideim = Image.open(args.hidefile)
|
||||||
assert inim.size == hideim.size, "Both image must be of the same size"
|
assert inim.size == hideim.size, "Both image must be of the same size"
|
||||||
assert 0 <= args.bits <= 8
|
bits = args.bits
|
||||||
|
assert 0 <= bits <= 8
|
||||||
outim = Image.new('RGB', inim.size)
|
outim = Image.new('RGB', inim.size)
|
||||||
eta = ETA(inim.size[0] * inim.size[1])
|
|
||||||
for x in range(inim.size[0]):
|
for x in range(inim.size[0]):
|
||||||
for y in range(inim.size[1]):
|
for y in range(inim.size[1]):
|
||||||
incol = inim.getpixel((x, y))
|
incol = inim.getpixel((x, y))
|
||||||
hidecol = hideim.getpixel((x, y))
|
hidecol = hideim.getpixel((x, y))
|
||||||
outcol = []
|
outcol = []
|
||||||
for cp in range(len(incol)):
|
for cp in range(len(incol)):
|
||||||
inbyt = get_bin(incol[cp], 8)
|
inbyt = '{0:08b}'.format(incol[cp])
|
||||||
hidebyt = get_bin(hidecol[cp], 8)
|
hidebyt = '{0:08b}'.format(hidecol[cp])
|
||||||
outbyt = list(inbyt)
|
outbyt = inbyt[:8 - bits] + hidebyt[bits - 1::-1]
|
||||||
for bit in range(args.bits):
|
outcol.append(int(outbyt, 2))
|
||||||
outbyt[-bit - 1] = hidebyt[bit]
|
|
||||||
outcol.append(int(''.join(outbyt), 2))
|
|
||||||
outim.putpixel((x, y), tuple(outcol))
|
outim.putpixel((x, y), tuple(outcol))
|
||||||
eta.print_status(x * inim.size[1] + y)
|
|
||||||
eta.done()
|
|
||||||
inim.close()
|
inim.close()
|
||||||
hideim.close()
|
hideim.close()
|
||||||
outim.save(args.outfile, 'PNG')
|
outim.save(args.outfile, 'PNG')
|
||||||
|
outim.close()
|
||||||
|
|
||||||
|
|
||||||
def inverseFile(args):
|
def inverseFile(args):
|
||||||
inim = Image.open(args.infile)
|
inim = Image.open(args.infile)
|
||||||
outim = Image.new('RGB', inim.size)
|
outim = Image.new('RGB', inim.size)
|
||||||
eta = ETA(inim.size[0] * inim.size[1])
|
xS, yS = inim.size[0], inim.size[1]
|
||||||
for x in range(inim.size[0]):
|
for x in range(xS):
|
||||||
for y in range(inim.size[1]):
|
for y in range(yS):
|
||||||
incol = inim.getpixel((x, y))
|
pos = (x, y)
|
||||||
|
incol = inim.getpixel(pos)
|
||||||
outcol = []
|
outcol = []
|
||||||
for cp in range(len(incol)):
|
for cp in range(len(incol)):
|
||||||
inbyt = get_bin(incol[cp], 8)
|
inbyt = '{0:08b}'.format(incol[cp])
|
||||||
outbyt = list(inbyt)
|
outbyt = inbyt[::-1]
|
||||||
for bit in range(8):
|
outcol.append(int(outbyt, 2))
|
||||||
outbyt[-bit - 1] = inbyt[bit]
|
outim.putpixel(pos, tuple(outcol))
|
||||||
outcol.append(int(''.join(outbyt), 2))
|
|
||||||
outim.putpixel((x, y), tuple(outcol))
|
|
||||||
eta.print_status(x * inim.size[1] + y)
|
|
||||||
eta.done()
|
|
||||||
inim.close()
|
inim.close()
|
||||||
outim.save(args.outfile, 'PNG')
|
outim.save(args.outfile, 'PNG')
|
||||||
|
outim.close()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
Loading…
Reference in a new issue