IrisRGBReader.st
author Claus Gittinger <cg@exept.de>
Wed, 03 Dec 2003 12:48:56 +0100
changeset 1869 c6800c75b7d0
parent 1848 864ca2cd4e71
child 2726 de3b045610a0
permissions -rw-r--r--
resource file handling cleaned up
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
527
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     1
"
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     2
 COPYRIGHT (c) 1997 by eXept Software AG / Claus Gittinger
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     3
              All Rights Reserved
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     4
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     5
 This software is furnished under a license and may be used
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    10
 hereby transferred.
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    11
"
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    12
1745
4fa0fad2a463 code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
    13
"{ Package: 'stx:libview2' }"
4fa0fad2a463 code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
    14
527
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    15
ImageReader subclass:#IrisRGBReader
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    16
	instanceVariableNames:'bytesPerPixel'
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    17
	classVariableNames:''
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    18
	poolDictionaries:''
1745
4fa0fad2a463 code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
    19
	category:'Graphics-Images-Readers'
527
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    20
!
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    21
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    22
!IrisRGBReader class methodsFor:'documentation'!
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    23
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    24
copyright
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    25
"
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    26
 COPYRIGHT (c) 1997 by eXept Software AG / Claus Gittinger
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    27
              All Rights Reserved
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    28
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    29
 This software is furnished under a license and may be used
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    30
 only in accordance with the terms of that license and with the
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    31
 inclusion of the above copyright notice.   This software may not
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    32
 be provided or otherwise made available to, or used by, any
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    33
 other person.  No title to or ownership of the software is
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    34
 hereby transferred.
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    35
"
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    36
!
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    37
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    38
documentation
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    39
"
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    40
    this class provides methods for loading Iris RGB format images. 
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    41
    Only 3-byte/pixel format is supported.
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    42
    Writing is not (yet) supported.
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    43
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    44
    [author:]
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    45
        Claus Gittinger
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    46
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    47
    [See also:]
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    48
        Image Form Icon
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    49
        BlitImageReader FaceReader GIFReader JPEGReader PCXReader 
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    50
        ST80FormReader SunRasterReader TargaReader TIFFReader WindowsIconReader 
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    51
        XBMReader XPMReader XWDReader 
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    52
"
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    53
! !
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    54
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    55
!IrisRGBReader class methodsFor:'initialization'!
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    56
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    57
initialize
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    58
    "install myself in the Image classes fileFormat table
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    59
     for the `.rgb' extension."
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    60
647
6f26c76aa0c9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 623
diff changeset
    61
    MIMETypes defineImageType:'image/x-rgb' suffix:'rgb' reader:self.
527
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    62
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    63
    "Modified: 14.4.1997 / 15:49:19 / cg"
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    64
! !
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    65
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    66
!IrisRGBReader class methodsFor:'testing'!
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    67
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    68
isValidImageFile:aFileName
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    69
    "return true, if aFileName contains an IRIS_RGB image"
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    70
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    71
    |inStream magic type bpp dim w h bytesPerPixel|
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    72
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    73
    inStream := self streamReadingFile:aFileName.
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    74
    inStream isNil ifTrue:[^ false].
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    75
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    76
    inStream binary.
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    77
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    78
    magic := inStream nextShortMSB:true.
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    79
    type := inStream nextShortMSB:true.
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    80
    dim := inStream nextShortMSB:true.
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    81
    w := inStream nextShortMSB:true.
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    82
    h := inStream nextShortMSB:true.
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    83
    bytesPerPixel := inStream nextShortMSB:true.
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    84
    inStream close.
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    85
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    86
    magic ~~ 8r0732 ifTrue:[^ false].
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    87
    bpp := type bitAnd:16r00FF.
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    88
    bpp ~~ 1 ifTrue:[^ false].
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    89
    bytesPerPixel ~~ 3 ifTrue:[^ false].
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    90
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    91
    ^ true
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    92
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    93
    "
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    94
     IrisRGBReader isValidImageFile:'/home2/cg/capture.rgb'
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    95
    "
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    96
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    97
    "Modified: 14.4.1997 / 16:51:58 / cg"
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    98
! !
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    99
1848
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   100
!IrisRGBReader methodsFor:'private-reading'!
527
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   101
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   102
readRLEData 
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   103
    "read RLE compressed data"
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   104
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   105
    |rleBufferLen tableLen startTable lengthTable rleData
919
d0e28bc28b25 unused locals
tz
parents: 883
diff changeset
   106
     tblIdx dstIdx|
527
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   107
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   108
    rleBufferLen := width * 2 + 10.
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   109
    tableLen := height * bytesPerPixel.
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   110
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   111
    startTable := Array new:tableLen.
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   112
    lengthTable := Array new:tableLen.
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   113
    rleData := ByteArray uninitializedNew:rleBufferLen.
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   114
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   115
    "/ read rowStart & length table
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   116
1753
aa246112438a avoid position
Claus Gittinger <cg@exept.de>
parents: 1745
diff changeset
   117
    inStream position1Based:512+1.
527
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   118
    1 to:tableLen do:[:i |
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   119
        startTable at:i put:(inStream nextLongMSB:true).
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   120
    ].
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   121
    1 to:tableLen do:[:i |
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   122
        lengthTable at:i put:(inStream nextLongMSB:true).
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   123
    ].
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   124
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   125
    data := ByteArray uninitializedNew:(width*height*3).
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   126
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   127
    dstIdx := width * (height-1) * 3 + 1.
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   128
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   129
    0 to:(height-1) do:[:y |
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   130
        0 to:(bytesPerPixel-1) do:[:z |
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   131
            |start length|
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   132
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   133
            tblIdx := y + (z*height) + 1.
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   134
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   135
            start := startTable at:tblIdx.
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   136
            length := lengthTable at:tblIdx.
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   137
1753
aa246112438a avoid position
Claus Gittinger <cg@exept.de>
parents: 1745
diff changeset
   138
            inStream position1Based:(start + 1).
527
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   139
            (inStream nextBytes:length into:rleData startingAt:1) ~~ length ifTrue:[
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   140
                self halt:'short read'
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   141
            ].
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   142
            (rleData at:length) ~~ 0 ifTrue:[
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   143
                self halt.
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   144
            ].
559
06bcbb6e3f32 use common RLE helper
Claus Gittinger <cg@exept.de>
parents: 527
diff changeset
   145
06bcbb6e3f32 use common RLE helper
Claus Gittinger <cg@exept.de>
parents: 527
diff changeset
   146
            self class
06bcbb6e3f32 use common RLE helper
Claus Gittinger <cg@exept.de>
parents: 527
diff changeset
   147
                decompressRLEFrom:rleData at:1 
06bcbb6e3f32 use common RLE helper
Claus Gittinger <cg@exept.de>
parents: 527
diff changeset
   148
                into:data at:dstIdx+z increment:3.
06bcbb6e3f32 use common RLE helper
Claus Gittinger <cg@exept.de>
parents: 527
diff changeset
   149
06bcbb6e3f32 use common RLE helper
Claus Gittinger <cg@exept.de>
parents: 527
diff changeset
   150
"/            self expandRow:rleData to:dstIdx+z. "/ (3-z).
527
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   151
        ].
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   152
        dstIdx := dstIdx - (width * 3).
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   153
    ].
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   154
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   155
    "
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   156
     IrisRGBReader fromFile:'/home2/cg/capture.rgb'
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   157
    "
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   158
559
06bcbb6e3f32 use common RLE helper
Claus Gittinger <cg@exept.de>
parents: 527
diff changeset
   159
    "Modified: 23.4.1997 / 18:59:11 / cg"
527
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   160
! !
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   161
1848
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   162
!IrisRGBReader methodsFor:'reading'!
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   163
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   164
fromStream:aStream
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   165
    "read a Portable bitmap file format as of Jeff Poskanzers Portable Bitmap Package.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   166
     supported are IRIS_RGB, PGB and PNM files." 
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   167
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   168
    | magic type dim isRLE bpp|
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   169
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   170
    inStream := aStream.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   171
    inStream binary.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   172
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   173
    magic := inStream nextShortMSB:true.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   174
    magic ~~ 8r0732 ifTrue:[
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   175
        ^ self fileFormatError:'bad magic number'.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   176
    ].
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   177
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   178
    type := inStream nextShortMSB:true.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   179
    dim := inStream nextShortMSB:true.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   180
    width := inStream nextShortMSB:true.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   181
    height := inStream nextShortMSB:true.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   182
    bytesPerPixel := inStream nextShortMSB:true.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   183
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   184
    isRLE := (type bitAnd:16rFF00) == 16r0100.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   185
    bpp := type bitAnd:16r00FF.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   186
    bpp ~~ 1 ifTrue:[
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   187
        ^ self fileFormatError:'only 1byte/pixel channel supported'.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   188
    ].
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   189
    bytesPerPixel ~~ 3 ifTrue:[
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   190
        ^ self fileFormatError:'can only read 3-channel images'.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   191
    ].
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   192
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   193
    self reportDimension.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   194
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   195
    isRLE ifTrue:[
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   196
        self readRLEData
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   197
    ] ifFalse:[
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   198
        ^ self fileFormatError:'currently, only RLE encoding supported'.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   199
        "/ self readVerbatimData
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   200
    ].
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   201
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   202
    photometric := #rgb.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   203
    samplesPerPixel := 3.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   204
    bitsPerSample := #(8 8 8).
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   205
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   206
    "
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   207
     IrisRGBReader fromFile:'/home2/cg/capture.rgb'
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   208
    "
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   209
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   210
    "Created: / 14.4.1997 / 15:38:51 / cg"
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   211
    "Modified: / 1.4.1998 / 14:28:51 / cg"
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   212
! !
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   213
527
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   214
!IrisRGBReader methodsFor:'testing '!
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   215
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   216
canRepresent:anImage
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   217
    "return true, if anImage can be represented in my file format.
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   218
     Currently only B&W and Depth8 images are supported."
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   219
919
d0e28bc28b25 unused locals
tz
parents: 883
diff changeset
   220
"/    |depth|
d0e28bc28b25 unused locals
tz
parents: 883
diff changeset
   221
"/
527
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   222
"/    anImage photometric == #rgb ifTrue:[
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   223
"/        ^ false  "/ not yet implemented
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   224
"/    ].
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   225
"/    (depth := anImage depth) == 1 ifTrue:[^ true].
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   226
"/    depth == 8 ifTrue:[^ true].
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   227
    ^ false
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   228
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   229
    "Created: 14.4.1997 / 15:38:51 / cg"
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   230
    "Modified: 14.4.1997 / 15:58:20 / cg"
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   231
! !
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   232
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   233
!IrisRGBReader class methodsFor:'documentation'!
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   234
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   235
version
1848
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   236
    ^ '$Header: /cvs/stx/stx/libview2/IrisRGBReader.st,v 1.12 2003-11-19 15:38:49 cg Exp $'
527
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   237
! !
1745
4fa0fad2a463 code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
   238
527
8c9d7178db4b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   239
IrisRGBReader initialize!