~ubuntu-branches/ubuntu/saucy/python-imaging/saucy-proposed

« back to all changes in this revision

Viewing changes to .pc/git-updates.diff/PIL/MspImagePlugin.py

  • Committer: Package Import Robot
  • Author(s): Matthias Klose
  • Date: 2013-01-31 20:49:20 UTC
  • mfrom: (27.1.1 raring-proposed)
  • Revision ID: package-import@ubuntu.com-20130131204920-b5zshy6vgfvdionl
Tags: 1.1.7+1.7.8-1ubuntu1
Rewrite build dependencies to allow cross builds.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#
 
2
# The Python Imaging Library.
 
3
# $Id$
 
4
#
 
5
# MSP file handling
 
6
#
 
7
# This is the format used by the Paint program in Windows 1 and 2.
 
8
#
 
9
# History:
 
10
#       95-09-05 fl     Created
 
11
#       97-01-03 fl     Read/write MSP images
 
12
#
 
13
# Copyright (c) Secret Labs AB 1997.
 
14
# Copyright (c) Fredrik Lundh 1995-97.
 
15
#
 
16
# See the README file for information on usage and redistribution.
 
17
#
 
18
 
 
19
 
 
20
__version__ = "0.1"
 
21
 
 
22
import Image, ImageFile
 
23
 
 
24
 
 
25
#
 
26
# read MSP files
 
27
 
 
28
def i16(c):
 
29
    return ord(c[0]) + (ord(c[1])<<8)
 
30
 
 
31
def _accept(prefix):
 
32
    return prefix[:4] in ["DanM", "LinS"]
 
33
 
 
34
##
 
35
# Image plugin for Windows MSP images.  This plugin supports both
 
36
# uncompressed (Windows 1.0).
 
37
 
 
38
class MspImageFile(ImageFile.ImageFile):
 
39
 
 
40
    format = "MSP"
 
41
    format_description = "Windows Paint"
 
42
 
 
43
    def _open(self):
 
44
 
 
45
        # Header
 
46
        s = self.fp.read(32)
 
47
        if s[:4] not in ["DanM", "LinS"]:
 
48
            raise SyntaxError, "not an MSP file"
 
49
 
 
50
        # Header checksum
 
51
        sum = 0
 
52
        for i in range(0, 32, 2):
 
53
            sum = sum ^ i16(s[i:i+2])
 
54
        if sum != 0:
 
55
            raise SyntaxError, "bad MSP checksum"
 
56
 
 
57
        self.mode = "1"
 
58
        self.size = i16(s[4:]), i16(s[6:])
 
59
 
 
60
        if s[:4] == "DanM":
 
61
            self.tile = [("raw", (0,0)+self.size, 32, ("1", 0, 1))]
 
62
        else:
 
63
            self.tile = [("msp", (0,0)+self.size, 32+2*self.size[1], None)]
 
64
 
 
65
#
 
66
# write MSP files (uncompressed only)
 
67
 
 
68
def o16(i):
 
69
    return chr(i&255) + chr(i>>8&255)
 
70
 
 
71
def _save(im, fp, filename):
 
72
 
 
73
    if im.mode != "1":
 
74
        raise IOError, "cannot write mode %s as MSP" % im.mode
 
75
 
 
76
    # create MSP header
 
77
    header = [0] * 16
 
78
 
 
79
    header[0], header[1] = i16("Da"), i16("nM") # version 1
 
80
    header[2], header[3] = im.size
 
81
    header[4], header[5] = 1, 1
 
82
    header[6], header[7] = 1, 1
 
83
    header[8], header[9] = im.size
 
84
 
 
85
    sum = 0
 
86
    for h in header:
 
87
        sum = sum ^ h
 
88
    header[12] = sum # FIXME: is this the right field?
 
89
 
 
90
    # header
 
91
    for h in header:
 
92
        fp.write(o16(h))
 
93
 
 
94
    # image body
 
95
    ImageFile._save(im, fp, [("raw", (0,0)+im.size, 32, ("1", 0, 1))])
 
96
 
 
97
#
 
98
# registry
 
99
 
 
100
Image.register_open("MSP", MspImageFile, _accept)
 
101
Image.register_save("MSP", _save)
 
102
 
 
103
Image.register_extension("MSP", ".msp")