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
|
||||
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):
|
||||
inim = Image.open(args.infile)
|
||||
hideim = Image.open(args.hidefile)
|
||||
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)
|
||||
eta = ETA(inim.size[0] * inim.size[1])
|
||||
for x in range(inim.size[0]):
|
||||
for y in range(inim.size[1]):
|
||||
incol = inim.getpixel((x, y))
|
||||
hidecol = hideim.getpixel((x, y))
|
||||
outcol = []
|
||||
for cp in range(len(incol)):
|
||||
inbyt = get_bin(incol[cp], 8)
|
||||
hidebyt = get_bin(hidecol[cp], 8)
|
||||
outbyt = list(inbyt)
|
||||
for bit in range(args.bits):
|
||||
outbyt[-bit - 1] = hidebyt[bit]
|
||||
outcol.append(int(''.join(outbyt), 2))
|
||||
inbyt = '{0:08b}'.format(incol[cp])
|
||||
hidebyt = '{0:08b}'.format(hidecol[cp])
|
||||
outbyt = inbyt[:8 - bits] + hidebyt[bits - 1::-1]
|
||||
outcol.append(int(outbyt, 2))
|
||||
outim.putpixel((x, y), tuple(outcol))
|
||||
eta.print_status(x * inim.size[1] + y)
|
||||
eta.done()
|
||||
inim.close()
|
||||
hideim.close()
|
||||
outim.save(args.outfile, 'PNG')
|
||||
outim.close()
|
||||
|
||||
|
||||
def inverseFile(args):
|
||||
inim = Image.open(args.infile)
|
||||
outim = Image.new('RGB', inim.size)
|
||||
eta = ETA(inim.size[0] * inim.size[1])
|
||||
for x in range(inim.size[0]):
|
||||
for y in range(inim.size[1]):
|
||||
incol = inim.getpixel((x, y))
|
||||
xS, yS = inim.size[0], inim.size[1]
|
||||
for x in range(xS):
|
||||
for y in range(yS):
|
||||
pos = (x, y)
|
||||
incol = inim.getpixel(pos)
|
||||
outcol = []
|
||||
for cp in range(len(incol)):
|
||||
inbyt = get_bin(incol[cp], 8)
|
||||
outbyt = list(inbyt)
|
||||
for bit in range(8):
|
||||
outbyt[-bit - 1] = inbyt[bit]
|
||||
outcol.append(int(''.join(outbyt), 2))
|
||||
outim.putpixel((x, y), tuple(outcol))
|
||||
eta.print_status(x * inim.size[1] + y)
|
||||
eta.done()
|
||||
inbyt = '{0:08b}'.format(incol[cp])
|
||||
outbyt = inbyt[::-1]
|
||||
outcol.append(int(outbyt, 2))
|
||||
outim.putpixel(pos, tuple(outcol))
|
||||
inim.close()
|
||||
outim.save(args.outfile, 'PNG')
|
||||
outim.close()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
Loading…
Reference in a new issue