Created
June 14, 2010 17:26
-
-
Save mcrisc/437981 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf-8 | |
# Python Bitmap (bmp) Image Negation (using module struct) | |
import struct | |
with open('in.bmp', 'rb') as fd, open('out.bmp', 'wb') as out: | |
s = fd.read(1) | |
count = 1 | |
while s: | |
if count < 37: # header bytes | |
out.write(s) | |
else: # data bytes | |
b = struct.unpack('B', s)[0] | |
out.write(struct.pack('B', 255 - b)) | |
s = fd.read(1) | |
count += 1 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment