Former-commit-id:2b462d8665
[formerly133dc97f67
] [formerlya02aeb236c
] [formerlya02aeb236c
[formerly9f19e3f712
]] [formerly2b462d8665
[formerly133dc97f67
] [formerlya02aeb236c
] [formerlya02aeb236c
[formerly9f19e3f712
]] [formerly06a8b51d6d
[formerlya02aeb236c
[formerly9f19e3f712
] [formerly06a8b51d6d
[formerly 64fa9254b946eae7e61bbc3f513b7c3696c4f54f]]]]] Former-commit-id:06a8b51d6d
Former-commit-id:2c3569dd39
[formerly9bb8decbcf
] [formerly8e80217e59
] [formerlye2ecdcfe33
[formerly377dcd10b9
] [formerly8e80217e59
[formerly3360eb6c5f
]]] Former-commit-id:e2ecdcfe33
[formerly377dcd10b9
] Former-commit-id:e2ecdcfe33
Former-commit-id:7dbd17a5aa
74 lines
1.7 KiB
Python
74 lines
1.7 KiB
Python
#
|
|
# The Python Imaging Library.
|
|
# $Id: McIdasImagePlugin.py 2134 2004-10-06 08:55:20Z fredrik $
|
|
#
|
|
# Basic McIdas support for PIL
|
|
#
|
|
# History:
|
|
# 97-05-05 fl Created (8-bit images only)
|
|
#
|
|
# Thanks to Richard Jones <richard.jones@bom.gov.au> for specs
|
|
# and samples.
|
|
#
|
|
# Copyright (c) Secret Labs AB 1997.
|
|
# Copyright (c) Fredrik Lundh 1997.
|
|
#
|
|
# See the README file for information on usage and redistribution.
|
|
#
|
|
|
|
__version__ = "0.1"
|
|
|
|
import string
|
|
|
|
import Image, ImageFile
|
|
|
|
def i16(c,i=0):
|
|
return ord(c[1+i])+(ord(c[i])<<8)
|
|
|
|
def i32(c,i=0):
|
|
return ord(c[3+i])+(ord(c[2+i])<<8)+(ord(c[1+i])<<16)+(ord(c[i])<<24)
|
|
|
|
def _accept(s):
|
|
return i32(s) == 0 and i32(s, 4) == 4
|
|
|
|
##
|
|
# Image plugin for McIdas area images.
|
|
|
|
class McIdasImageFile(ImageFile.ImageFile):
|
|
|
|
format = "MCIDAS"
|
|
format_description = "McIdas area file"
|
|
|
|
def _open(self):
|
|
|
|
# parse area file directory
|
|
s = self.fp.read(256)
|
|
if not _accept(s):
|
|
raise SyntaxError, "not an McIdas area file"
|
|
|
|
# get mode
|
|
if i32(s, 40) != 1 or i32(s, 52) != 1:
|
|
raise SyntaxError, "unsupported McIdas format"
|
|
|
|
self.mode = "L"
|
|
|
|
# get size
|
|
self.size = i32(s, 36), i32(s, 32)
|
|
|
|
# setup image descriptor
|
|
prefix = i32(s, 56)
|
|
offset = i32(s, 132)
|
|
|
|
self.tile = [("raw", (0, 0) + self.size, offset,
|
|
("L", prefix + self.size[0], 1))]
|
|
|
|
# FIXME: should store the navigation and calibration blocks
|
|
# somewhere (or perhaps extract some basic information from
|
|
# them...)
|
|
|
|
# --------------------------------------------------------------------
|
|
# registry
|
|
|
|
Image.register_open("MCIDAS", McIdasImageFile, _accept)
|
|
|
|
# no default extension
|