TargaReader.st
author Claus Gittinger <cg@exept.de>
Thu, 24 Oct 2002 21:16:06 +0200
changeset 1646 da8d044c7c0d
parent 1577 a8851bce16c5
child 1738 9c85e9d8326b
permissions -rw-r--r--
value - itemValue
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
37
aeed5856f457 Initial revision
claus
parents:
diff changeset
     1
"
aeed5856f457 Initial revision
claus
parents:
diff changeset
     2
 COPYRIGHT (c) 1994 by Claus Gittinger
aeed5856f457 Initial revision
claus
parents:
diff changeset
     3
	      All Rights Reserved
aeed5856f457 Initial revision
claus
parents:
diff changeset
     4
aeed5856f457 Initial revision
claus
parents:
diff changeset
     5
 This software is furnished under a license and may be used
aeed5856f457 Initial revision
claus
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
aeed5856f457 Initial revision
claus
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
aeed5856f457 Initial revision
claus
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
aeed5856f457 Initial revision
claus
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
aeed5856f457 Initial revision
claus
parents:
diff changeset
    10
 hereby transferred.
aeed5856f457 Initial revision
claus
parents:
diff changeset
    11
"
aeed5856f457 Initial revision
claus
parents:
diff changeset
    12
1577
a8851bce16c5 isValidImageFile improved
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
    13
"{ Package: 'stx:libview2' }"
a8851bce16c5 isValidImageFile improved
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
    14
37
aeed5856f457 Initial revision
claus
parents:
diff changeset
    15
ImageReader subclass:#TargaReader
555
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
    16
	instanceVariableNames:'orientation'
210
5405de794686 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    17
	classVariableNames:''
5405de794686 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    18
	poolDictionaries:''
259
62b1bbafd9ba category change
Claus Gittinger <cg@exept.de>
parents: 234
diff changeset
    19
	category:'Graphics-Images-Support'
37
aeed5856f457 Initial revision
claus
parents:
diff changeset
    20
!
aeed5856f457 Initial revision
claus
parents:
diff changeset
    21
aeed5856f457 Initial revision
claus
parents:
diff changeset
    22
!TargaReader class methodsFor:'documentation'!
aeed5856f457 Initial revision
claus
parents:
diff changeset
    23
aeed5856f457 Initial revision
claus
parents:
diff changeset
    24
copyright
aeed5856f457 Initial revision
claus
parents:
diff changeset
    25
"
aeed5856f457 Initial revision
claus
parents:
diff changeset
    26
 COPYRIGHT (c) 1994 by Claus Gittinger
aeed5856f457 Initial revision
claus
parents:
diff changeset
    27
	      All Rights Reserved
aeed5856f457 Initial revision
claus
parents:
diff changeset
    28
aeed5856f457 Initial revision
claus
parents:
diff changeset
    29
 This software is furnished under a license and may be used
aeed5856f457 Initial revision
claus
parents:
diff changeset
    30
 only in accordance with the terms of that license and with the
aeed5856f457 Initial revision
claus
parents:
diff changeset
    31
 inclusion of the above copyright notice.   This software may not
aeed5856f457 Initial revision
claus
parents:
diff changeset
    32
 be provided or otherwise made available to, or used by, any
aeed5856f457 Initial revision
claus
parents:
diff changeset
    33
 other person.  No title to or ownership of the software is
aeed5856f457 Initial revision
claus
parents:
diff changeset
    34
 hereby transferred.
aeed5856f457 Initial revision
claus
parents:
diff changeset
    35
"
aeed5856f457 Initial revision
claus
parents:
diff changeset
    36
!
aeed5856f457 Initial revision
claus
parents:
diff changeset
    37
aeed5856f457 Initial revision
claus
parents:
diff changeset
    38
documentation
aeed5856f457 Initial revision
claus
parents:
diff changeset
    39
"
aeed5856f457 Initial revision
claus
parents:
diff changeset
    40
    this class provides methods for loading targa-file (tga) images.
556
a2d03470af59 documentation
Claus Gittinger <cg@exept.de>
parents: 555
diff changeset
    41
37
aeed5856f457 Initial revision
claus
parents:
diff changeset
    42
    Limitations: 
556
a2d03470af59 documentation
Claus Gittinger <cg@exept.de>
parents: 555
diff changeset
    43
        not fully tested (I only had a few targa files to check things)
a2d03470af59 documentation
Claus Gittinger <cg@exept.de>
parents: 555
diff changeset
    44
        only supports 8,24 and 32 bits/pixel formats; alpha channel is ignored
210
5405de794686 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    45
        Image saving not supported
37
aeed5856f457 Initial revision
claus
parents:
diff changeset
    46
aeed5856f457 Initial revision
claus
parents:
diff changeset
    47
    I had two tga files to test this code with - it may not work with
556
a2d03470af59 documentation
Claus Gittinger <cg@exept.de>
parents: 555
diff changeset
    48
    other targa files (it certainly does not work with 1/16 bit images).
299
23d89531904f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 259
diff changeset
    49
37
aeed5856f457 Initial revision
claus
parents:
diff changeset
    50
    Suggestions: adapt & use the pbmplus library here.
210
5405de794686 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    51
5405de794686 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    52
    [See also:]
234
b6352d13e792 xrefs in documentation
Claus Gittinger <cg@exept.de>
parents: 210
diff changeset
    53
        Image Form Icon
210
5405de794686 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    54
        BlitImageReader FaceReader GIFReader JPEGReader PBMReader PCXReader 
5405de794686 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    55
        ST80FormReader SunRasterReader TIFFReader WindowsIconReader 
5405de794686 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    56
        XBMReader XPMReader XWDReader
37
aeed5856f457 Initial revision
claus
parents:
diff changeset
    57
"
aeed5856f457 Initial revision
claus
parents:
diff changeset
    58
! !
aeed5856f457 Initial revision
claus
parents:
diff changeset
    59
aeed5856f457 Initial revision
claus
parents:
diff changeset
    60
!TargaReader class methodsFor:'initialization'!
aeed5856f457 Initial revision
claus
parents:
diff changeset
    61
aeed5856f457 Initial revision
claus
parents:
diff changeset
    62
initialize
210
5405de794686 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    63
    "tell Image-class, that a new fileReader is present
398
aef700d15416 new suffix-table
Claus Gittinger <cg@exept.de>
parents: 299
diff changeset
    64
     for the '.tga' extension."
210
5405de794686 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    65
647
6f26c76aa0c9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 630
diff changeset
    66
    MIMETypes defineImageType:'image/x-targa' suffix:'tga' reader:self.
37
aeed5856f457 Initial revision
claus
parents:
diff changeset
    67
630
48657c687a8b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 556
diff changeset
    68
    "Modified: 27.6.1997 / 18:39:43 / cg"
37
aeed5856f457 Initial revision
claus
parents:
diff changeset
    69
! !
aeed5856f457 Initial revision
claus
parents:
diff changeset
    70
aeed5856f457 Initial revision
claus
parents:
diff changeset
    71
!TargaReader class methodsFor:'testing'!
aeed5856f457 Initial revision
claus
parents:
diff changeset
    72
aeed5856f457 Initial revision
claus
parents:
diff changeset
    73
isValidImageFile:aFileName
aeed5856f457 Initial revision
claus
parents:
diff changeset
    74
    "return true, if aFileName contains a targa-file image"
aeed5856f457 Initial revision
claus
parents:
diff changeset
    75
1577
a8851bce16c5 isValidImageFile improved
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
    76
    |aStream w h depth flags imageType ok|
a8851bce16c5 isValidImageFile improved
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
    77
a8851bce16c5 isValidImageFile improved
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
    78
    ok := true.
37
aeed5856f457 Initial revision
claus
parents:
diff changeset
    79
43
e85c7d392833 *** empty log message ***
claus
parents: 37
diff changeset
    80
    aStream := self streamReadingFile:aFileName.
e85c7d392833 *** empty log message ***
claus
parents: 37
diff changeset
    81
    aStream isNil ifTrue:[^ false].
e85c7d392833 *** empty log message ***
claus
parents: 37
diff changeset
    82
    aStream binary.
1577
a8851bce16c5 isValidImageFile improved
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
    83
a8851bce16c5 isValidImageFile improved
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
    84
    aStream next.   "lenID"
a8851bce16c5 isValidImageFile improved
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
    85
    aStream next.   "hasColorMap"
a8851bce16c5 isValidImageFile improved
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
    86
    imageType := aStream next.  
a8851bce16c5 isValidImageFile improved
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
    87
    aStream skip:2. "cmapOffset"
a8851bce16c5 isValidImageFile improved
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
    88
    aStream skip:2. "cmapLength"
a8851bce16c5 isValidImageFile improved
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
    89
    aStream next.   "cmapEntrySize"
a8851bce16c5 isValidImageFile improved
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
    90
    aStream skip:2. "xOrg"
a8851bce16c5 isValidImageFile improved
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
    91
    aStream skip:2. "yOrg"
37
aeed5856f457 Initial revision
claus
parents:
diff changeset
    92
43
e85c7d392833 *** empty log message ***
claus
parents: 37
diff changeset
    93
    w := aStream nextShortMSB:false.
e85c7d392833 *** empty log message ***
claus
parents: 37
diff changeset
    94
    h := aStream nextShortMSB:false.
37
aeed5856f457 Initial revision
claus
parents:
diff changeset
    95
43
e85c7d392833 *** empty log message ***
claus
parents: 37
diff changeset
    96
    depth := aStream next.
e85c7d392833 *** empty log message ***
claus
parents: 37
diff changeset
    97
    flags := aStream next.
37
aeed5856f457 Initial revision
claus
parents:
diff changeset
    98
1577
a8851bce16c5 isValidImageFile improved
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
    99
    "/ MapRGB == 1
a8851bce16c5 isValidImageFile improved
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
   100
    "/ RawRGB == 2
a8851bce16c5 isValidImageFile improved
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
   101
    "/ RawMono == 3
a8851bce16c5 isValidImageFile improved
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
   102
    "/ MapEnCode == 9
a8851bce16c5 isValidImageFile improved
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
   103
    "/ RawEnCode == 10
a8851bce16c5 isValidImageFile improved
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
   104
a8851bce16c5 isValidImageFile improved
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
   105
    (#(1 2 3 9 10) includes:imageType) ifFalse:[
a8851bce16c5 isValidImageFile improved
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
   106
        "/ 'TargaReader [warning]: unsupported imageType: ' errorPrint. imageType errorPrintCR.
a8851bce16c5 isValidImageFile improved
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
   107
        ok := false
a8851bce16c5 isValidImageFile improved
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
   108
    ] ifTrue:[
a8851bce16c5 isValidImageFile improved
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
   109
        (#(8 "16" 24 32) includes:depth) ifFalse:[
a8851bce16c5 isValidImageFile improved
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
   110
            ok := false
a8851bce16c5 isValidImageFile improved
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
   111
        ].
37
aeed5856f457 Initial revision
claus
parents:
diff changeset
   112
    ].
43
e85c7d392833 *** empty log message ***
claus
parents: 37
diff changeset
   113
    aStream close. 
1577
a8851bce16c5 isValidImageFile improved
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
   114
    ^ ok
37
aeed5856f457 Initial revision
claus
parents:
diff changeset
   115
aeed5856f457 Initial revision
claus
parents:
diff changeset
   116
    "
aeed5856f457 Initial revision
claus
parents:
diff changeset
   117
     TargaReader isValidImageFile:'bitmaps/test.tga'    
aeed5856f457 Initial revision
claus
parents:
diff changeset
   118
     TargaReader isValidImageFile:'bitmaps/garfield.gif'  
555
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   119
    "
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   120
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   121
    "Modified: 21.4.1997 / 20:46:52 / cg"
37
aeed5856f457 Initial revision
claus
parents:
diff changeset
   122
! !
aeed5856f457 Initial revision
claus
parents:
diff changeset
   123
aeed5856f457 Initial revision
claus
parents:
diff changeset
   124
!TargaReader methodsFor:'reading from file'!
aeed5856f457 Initial revision
claus
parents:
diff changeset
   125
43
e85c7d392833 *** empty log message ***
claus
parents: 37
diff changeset
   126
fromStream:aStream
37
aeed5856f457 Initial revision
claus
parents:
diff changeset
   127
    "read a targa-image from aFileName. return the receiver (with all
aeed5856f457 Initial revision
claus
parents:
diff changeset
   128
     relevant instance variables set for the image) or nil on error"
aeed5856f457 Initial revision
claus
parents:
diff changeset
   129
918
64336276b146 unused local
tz
parents: 815
diff changeset
   130
    |depth flags lenID hasColorMap imageType 
299
23d89531904f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 259
diff changeset
   131
     cmapOffset cmapLength cmapEntrySize xOrg yOrg
918
64336276b146 unused local
tz
parents: 815
diff changeset
   132
     t bytesPerPixel bytesPerRow rowIdx startIdx endIdx rle|
37
aeed5856f457 Initial revision
claus
parents:
diff changeset
   133
43
e85c7d392833 *** empty log message ***
claus
parents: 37
diff changeset
   134
    inStream := aStream.
e85c7d392833 *** empty log message ***
claus
parents: 37
diff changeset
   135
    aStream binary.
e85c7d392833 *** empty log message ***
claus
parents: 37
diff changeset
   136
299
23d89531904f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 259
diff changeset
   137
    lenID := aStream next.
23d89531904f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 259
diff changeset
   138
    hasColorMap := aStream next.
23d89531904f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 259
diff changeset
   139
    imageType := aStream next.
23d89531904f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 259
diff changeset
   140
    cmapOffset := aStream nextShortMSB:false.
23d89531904f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 259
diff changeset
   141
    cmapLength := aStream nextShortMSB:false.
23d89531904f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 259
diff changeset
   142
    cmapEntrySize := aStream next.
23d89531904f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 259
diff changeset
   143
    xOrg := aStream nextShortMSB:false.
23d89531904f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 259
diff changeset
   144
    yOrg := aStream nextShortMSB:false.
23d89531904f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 259
diff changeset
   145
43
e85c7d392833 *** empty log message ***
claus
parents: 37
diff changeset
   146
    width := aStream nextShortMSB:false.
e85c7d392833 *** empty log message ***
claus
parents: 37
diff changeset
   147
    height := aStream nextShortMSB:false.
e85c7d392833 *** empty log message ***
claus
parents: 37
diff changeset
   148
    depth := aStream next.
555
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   149
    (#(8 "16" 24 32) includes:depth) ifFalse:[
815
5fe6cac83186 use common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   150
        ^ self fileFormatError:('unsupported depth: ', depth printString).
37
aeed5856f457 Initial revision
claus
parents:
diff changeset
   151
    ].
555
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   152
    depth == 32 ifTrue:[
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   153
        'TargaReader [info]: alpha channel ignored' infoPrintCR.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   154
    ] ifFalse:[
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   155
        'TargaReader [info]: depth: ' infoPrint. depth infoPrintCR.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   156
    ].
551
7e0fb2e4f214 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   157
7e0fb2e4f214 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   158
    "/ MapRGB == 1
7e0fb2e4f214 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   159
    "/ RawRGB == 2
7e0fb2e4f214 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   160
    "/ RawMono == 3
7e0fb2e4f214 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   161
    "/ MapEnCode == 9
7e0fb2e4f214 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   162
    "/ RawEnCode == 10
555
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   163
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   164
    (#(1 2 9 10) includes:imageType) ifFalse:[
1079
15ffea561117 raise fileFormatException if imageType is bad.
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   165
        "/ 'TargaReader [warning]: unsupported imageType: ' errorPrint. imageType errorPrintCR.
15ffea561117 raise fileFormatException if imageType is bad.
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   166
        ^ self fileFormatError:('unsupported imageType: ', imageType printString).
551
7e0fb2e4f214 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   167
    ].
7e0fb2e4f214 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   168
    'TargaReader [info]: imageType: ' infoPrint. imageType infoPrintCR.
299
23d89531904f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 259
diff changeset
   169
23d89531904f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 259
diff changeset
   170
    "/ flags:
23d89531904f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 259
diff changeset
   171
    "/    0000 xxxx  attribute-bits-per-pixel
555
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   172
    "/    0000 0001  greysc
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   173
    "/    0000 0010  colour
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   174
    "/    0000 0011  mapped
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   175
    "/    0000 0100  rleEncoded
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   176
    "/    0000 1000  interlaced
299
23d89531904f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 259
diff changeset
   177
    "/    00xx 0000  origin (0 -> lower-left / 1 -> l-r / 2 -> u-l / 3 -> u-r)
23d89531904f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 259
diff changeset
   178
    "/    xx00 0000  interleave (0 -> none / 1 -> odd/even / 2 ->4-fould / 3 reserved)
23d89531904f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 259
diff changeset
   179
    "/
43
e85c7d392833 *** empty log message ***
claus
parents: 37
diff changeset
   180
    flags := aStream next.
555
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   181
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   182
    (flags bitAnd:2r11000000) ~~ 0 ifTrue:[
815
5fe6cac83186 use common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   183
        ^ self fileFormatError:('unsupported interlace: ' , flags printString).
555
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   184
    ].
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   185
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   186
    rle := flags bitTest:2r000001000.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   187
    flags := flags bitAnd:2r111110111.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   188
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   189
    (flags bitAnd:2r00001111) ~~ 0 ifTrue:[
815
5fe6cac83186 use common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   190
        ^ self fileFormatError:('unsupported flags: ' , flags printString).
551
7e0fb2e4f214 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   191
    ].
555
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   192
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   193
    (flags bitAnd:2r00110000) == 16r20 ifTrue:[
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   194
        orientation := #topLeft
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   195
    ] ifFalse:[
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   196
        (flags bitAnd:2r00110000) == 16r30 ifTrue:[
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   197
            orientation := #topRight
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   198
        ] ifFalse:[
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   199
            (flags bitAnd:2r00110000) == 16r10 ifTrue:[
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   200
                orientation := #bottomRight
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   201
            ] ifFalse:[
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   202
                (flags bitAnd:2r00110000) == 0 ifTrue:[
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   203
                    orientation := #bottomLeft
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   204
                ]
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   205
            ]
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   206
        ]
299
23d89531904f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 259
diff changeset
   207
    ].
23d89531904f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 259
diff changeset
   208
23d89531904f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 259
diff changeset
   209
    lenID ~~ 0 ifTrue:[
23d89531904f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 259
diff changeset
   210
        aStream skip:lenID
37
aeed5856f457 Initial revision
claus
parents:
diff changeset
   211
    ].
aeed5856f457 Initial revision
claus
parents:
diff changeset
   212
555
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   213
    hasColorMap ~~ 0 ifTrue:[
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   214
        "/ read the colorMap
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   215
        colorMap := Array new:cmapLength.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   216
        1 to:cmapLength do:[:index |
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   217
            |r g b|
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   218
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   219
            b := aStream nextByte.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   220
            g := aStream nextByte.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   221
            r := aStream nextByte.
1065
32a68620ddab care for EOF while reading colorMap.
Claus Gittinger <cg@exept.de>
parents: 918
diff changeset
   222
            (r isNil or:[g isNil or:[b isNil]]) ifTrue:[
32a68620ddab care for EOF while reading colorMap.
Claus Gittinger <cg@exept.de>
parents: 918
diff changeset
   223
                ^ self fileFormatError:('short file - probably not targa format').
32a68620ddab care for EOF while reading colorMap.
Claus Gittinger <cg@exept.de>
parents: 918
diff changeset
   224
            ].
555
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   225
            colorMap at:index put:(Color redByte:r greenByte:g blueByte:b).
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   226
        ].
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   227
        'TargaReader [info]: has colorMap' infoPrintCR.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   228
    ].
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   229
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   230
    depth == 32 ifTrue:[
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   231
        imageType == 2 ifTrue:[
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   232
"/            rle ifTrue:[self halt].
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   233
            self read32.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   234
        ] ifFalse:[
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   235
"/            rle ifFalse:[self halt].
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   236
            self read32RLE.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   237
        ].
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   238
        bytesPerRow := width*3.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   239
        bytesPerPixel := 3.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   240
    ].
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   241
    depth == 24 ifTrue:[
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   242
        imageType == 2 ifTrue:[
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   243
"/            rle ifTrue:[self halt].
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   244
            self read24.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   245
        ] ifFalse:[
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   246
"/            rle ifFalse:[self halt].
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   247
            self read24RLE.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   248
        ].
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   249
        bytesPerRow := width*3.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   250
        bytesPerPixel := 3.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   251
    ].
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   252
    depth == 8 ifTrue:[
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   253
        imageType == 1 ifTrue:[
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   254
"/            rle ifTrue:[self halt].
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   255
            self read8.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   256
        ] ifFalse:[
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   257
"/            rle ifFalse:[self halt].
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   258
            self read8RLE
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   259
        ].
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   260
        bytesPerRow := width.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   261
        bytesPerPixel := 1.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   262
    ].
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   263
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   264
    orientation == #topLeft ifTrue:[
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   265
    ] ifFalse:[
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   266
        orientation == #topRight ifTrue:[
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   267
            "/ flip horizontal
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   268
            rowIdx := 1.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   269
            1 to:height do:[:row |
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   270
                startIdx := rowIdx.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   271
                endIdx := rowIdx + bytesPerRow - bytesPerPixel.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   272
                1 to:width//2 do:[:x |
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   273
                    0 to:bytesPerPixel-1 do:[:c |
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   274
                        t := data at:startIdx+c.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   275
                        data at:startIdx+c put:(data at:endIdx+c).
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   276
                        data at:endIdx+c put:t.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   277
                    ].
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   278
                    startIdx := startIdx + bytesPerPixel.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   279
                    endIdx := endIdx - bytesPerPixel.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   280
                ].
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   281
                rowIdx := rowIdx + width.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   282
            ].
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   283
        ] ifFalse:[
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   284
            orientation == #bottomLeft ifTrue:[
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   285
                "/ flip vertical
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   286
                startIdx := 1.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   287
                endIdx := 1 + ((height - 1) * bytesPerRow).
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   288
                t := ByteArray new:bytesPerRow.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   289
                1 to:height//2 do:[:row |
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   290
                    t replaceFrom:1 to:bytesPerRow with:data startingAt:startIdx.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   291
                    data replaceFrom:startIdx to:startIdx+bytesPerRow-1 with:data startingAt:endIdx.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   292
                    data replaceFrom:endIdx to:endIdx+bytesPerRow-1 with:t startingAt:1.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   293
                    startIdx := startIdx + bytesPerRow.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   294
                    endIdx := endIdx - bytesPerRow
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   295
                ].
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   296
            ] ifFalse:[
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   297
                'TargaReader [warning]: unsupported orientation: ' errorPrint. orientation errorPrintCR.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   298
            ]
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   299
        ]
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   300
    ].
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   301
    ^ self
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   302
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   303
    "
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   304
     TargaReader fromFile:'bitmaps/test.tga' 
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   305
    "
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   306
1065
32a68620ddab care for EOF while reading colorMap.
Claus Gittinger <cg@exept.de>
parents: 918
diff changeset
   307
    "Modified: / 7.9.1998 / 21:12:12 / cg"
1079
15ffea561117 raise fileFormatException if imageType is bad.
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
   308
    "Modified: / 13.10.1998 / 19:50:48 / ps"
555
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   309
!
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   310
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   311
read24
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   312
    "read a 24 bit/pixel targa-image"
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   313
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   314
    |nBytes ok dSize t|
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   315
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   316
    data := ByteArray new:(width * height * 3).
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   317
    inStream nextBytes:(dSize := data size) into:data.
299
23d89531904f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 259
diff changeset
   318
37
aeed5856f457 Initial revision
claus
parents:
diff changeset
   319
    "
299
23d89531904f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 259
diff changeset
   320
     mhmh - pixel-byte order is blue-green-red
23d89531904f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 259
diff changeset
   321
     swap blue & red bytes
37
aeed5856f457 Initial revision
claus
parents:
diff changeset
   322
    "
107
Claus Gittinger <cg@exept.de>
parents: 96
diff changeset
   323
    nBytes := data size.
Claus Gittinger <cg@exept.de>
parents: 96
diff changeset
   324
    ok := false.
Claus Gittinger <cg@exept.de>
parents: 96
diff changeset
   325
Claus Gittinger <cg@exept.de>
parents: 96
diff changeset
   326
%{  /* OPTIONAL */
Claus Gittinger <cg@exept.de>
parents: 96
diff changeset
   327
    if (__isByteArray(_INST(data))) {
299
23d89531904f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 259
diff changeset
   328
        int __lastIndex = __intVal(nBytes) - 2;
23d89531904f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 259
diff changeset
   329
        unsigned char *__cp = __ByteArrayInstPtr(_INST(data))->ba_element;
23d89531904f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 259
diff changeset
   330
        int __i;
23d89531904f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 259
diff changeset
   331
        unsigned char __t;
107
Claus Gittinger <cg@exept.de>
parents: 96
diff changeset
   332
299
23d89531904f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 259
diff changeset
   333
        for (__i=0; __i<__lastIndex; __i+=3, __cp+=3) {
23d89531904f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 259
diff changeset
   334
            __t = __cp[0];
23d89531904f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 259
diff changeset
   335
            __cp[0] = __cp[2];
23d89531904f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 259
diff changeset
   336
            __cp[2] = __t;
23d89531904f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 259
diff changeset
   337
        }
23d89531904f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 259
diff changeset
   338
        ok = true;
107
Claus Gittinger <cg@exept.de>
parents: 96
diff changeset
   339
    }
Claus Gittinger <cg@exept.de>
parents: 96
diff changeset
   340
%}.
Claus Gittinger <cg@exept.de>
parents: 96
diff changeset
   341
    ok ifFalse:[
299
23d89531904f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 259
diff changeset
   342
        1 to:(dSize - 2) by:3 do:[:i |
23d89531904f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 259
diff changeset
   343
            t := data at:i.
23d89531904f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 259
diff changeset
   344
            data at:i put:(data at:i+2).
23d89531904f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 259
diff changeset
   345
            data at:i+2 put:t
23d89531904f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 259
diff changeset
   346
        ]
37
aeed5856f457 Initial revision
claus
parents:
diff changeset
   347
    ].
aeed5856f457 Initial revision
claus
parents:
diff changeset
   348
aeed5856f457 Initial revision
claus
parents:
diff changeset
   349
    photometric := #rgb.
aeed5856f457 Initial revision
claus
parents:
diff changeset
   350
    samplesPerPixel := 3.
aeed5856f457 Initial revision
claus
parents:
diff changeset
   351
    bitsPerSample := #(8 8 8).
555
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   352
!
37
aeed5856f457 Initial revision
claus
parents:
diff changeset
   353
555
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   354
read24RLE
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   355
    "read an 8 bit/pixel rle encoded targa-image"
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   356
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   357
    |total count dstIndex code n r g b|
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   358
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   359
    data := ByteArray new:((total := width * height * 3)).
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   360
    count := 0.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   361
    dstIndex := 1.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   362
    [count < total] whileTrue:[
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   363
        code := inStream nextByte.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   364
        n := (code bitAnd:16r7F) + 1.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   365
        (code bitAnd:16r80) ~~ 0 ifTrue:[
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   366
            b := inStream nextByte.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   367
            g := inStream nextByte.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   368
            r := inStream nextByte.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   369
            n timesRepeat:[
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   370
                data at:dstIndex put:r.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   371
                data at:dstIndex+1 put:g.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   372
                data at:dstIndex+2 put:b.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   373
                dstIndex := dstIndex + 3
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   374
            ].
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   375
        ] ifFalse:[
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   376
            n timesRepeat:[
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   377
                b := inStream nextByte.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   378
                g := inStream nextByte.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   379
                r := inStream nextByte.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   380
                data at:dstIndex put:r.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   381
                data at:dstIndex+1 put:g.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   382
                data at:dstIndex+2 put:b.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   383
                dstIndex := dstIndex + 3
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   384
            ]
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   385
        ].
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   386
        count := count + (n * 3).
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   387
    ].
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   388
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   389
    photometric := #rgb.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   390
    samplesPerPixel := 3.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   391
    bitsPerSample := #(8 8 8).
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   392
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   393
    "Modified: 21.4.1997 / 20:21:12 / cg"
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   394
    "Created: 21.4.1997 / 20:43:23 / cg"
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   395
!
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   396
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   397
read32
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   398
    "read a 32 bit/pixel targa-image; skip alpha channel (for now)"
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   399
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   400
    |total dstIndex a r g b|
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   401
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   402
    data := ByteArray new:((total := width * height * 3)).
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   403
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   404
    dstIndex := 1.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   405
    [total > 0] whileTrue:[
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   406
        inStream nextByte.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   407
        a := inStream nextByte.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   408
        b := inStream nextByte.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   409
        g := inStream nextByte.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   410
        r := inStream nextByte.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   411
        data at:dstIndex put:r.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   412
        data at:dstIndex+1 put:g.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   413
        data at:dstIndex+2 put:b.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   414
        dstIndex := dstIndex + 3.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   415
        total := total - 3.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   416
    ].
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   417
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   418
    photometric := #rgb.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   419
    samplesPerPixel := 3.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   420
    bitsPerSample := #(8 8 8).
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   421
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   422
    "Modified: 21.4.1997 / 20:21:12 / cg"
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   423
    "Created: 21.4.1997 / 20:45:35 / cg"
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   424
!
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   425
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   426
read32RLE
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   427
    "read a 32 bit/pixel rle encoded targa-image; skip alpha channel (for now)"
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   428
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   429
    |total count dstIndex code n a r g b|
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   430
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   431
    data := ByteArray new:((total := width * height * 3)).
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   432
    count := 0.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   433
    dstIndex := 1.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   434
    [count < total] whileTrue:[
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   435
        code := inStream nextByte.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   436
        n := (code bitAnd:16r7F) + 1.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   437
        (code bitAnd:16r80) ~~ 0 ifTrue:[
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   438
            a := inStream nextByte.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   439
            b := inStream nextByte.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   440
            g := inStream nextByte.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   441
            r := inStream nextByte.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   442
            n timesRepeat:[
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   443
                data at:dstIndex put:r.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   444
                data at:dstIndex+1 put:g.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   445
                data at:dstIndex+2 put:b.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   446
                dstIndex := dstIndex + 3
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   447
            ].
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   448
        ] ifFalse:[
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   449
            n timesRepeat:[
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   450
                a := inStream nextByte.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   451
                b := inStream nextByte.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   452
                g := inStream nextByte.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   453
                r := inStream nextByte.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   454
                data at:dstIndex put:r.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   455
                data at:dstIndex+1 put:g.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   456
                data at:dstIndex+2 put:b.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   457
                dstIndex := dstIndex + 3
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   458
            ]
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   459
        ].
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   460
        count := count + (n * 3).
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   461
    ].
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   462
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   463
    photometric := #rgb.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   464
    samplesPerPixel := 3.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   465
    bitsPerSample := #(8 8 8).
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   466
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   467
    "Created: 21.4.1997 / 20:43:54 / cg"
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   468
    "Modified: 21.4.1997 / 20:45:49 / cg"
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   469
!
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   470
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   471
read8
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   472
    "read an 8 bit/pixel targa-image"
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   473
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   474
    data := ByteArray new:(width * height).
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   475
    inStream nextBytes:(data size) into:data.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   476
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   477
    colorMap isNil ifTrue:[
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   478
        photometric := #blackIs0.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   479
    ] ifFalse:[
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   480
        photometric := #palette.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   481
    ].
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   482
    samplesPerPixel := 1.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   483
    bitsPerSample := #(8).
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   484
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   485
    "Created: 21.4.1997 / 20:12:35 / cg"
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   486
    "Modified: 21.4.1997 / 20:39:02 / cg"
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   487
!
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   488
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   489
read8RLE
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   490
    "read an 8 bit/pixel rle encoded targa-image"
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   491
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   492
    |total count dstIndex code n byte|
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   493
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   494
    data := ByteArray new:((total := width * height)).
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   495
    count := 0.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   496
    dstIndex := 1.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   497
    [count < total] whileTrue:[
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   498
        code := inStream nextByte.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   499
        n := (code bitAnd:16r7F) + 1.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   500
        (code bitAnd:16r80) ~~ 0 ifTrue:[
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   501
            byte := inStream nextByte.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   502
            data from:dstIndex to:dstIndex+n-1 put:byte.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   503
        ] ifFalse:[
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   504
            inStream nextBytes:n into:data startingAt:dstIndex.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   505
        ].
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   506
        count := count + n.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   507
        dstIndex := dstIndex + n.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   508
    ].
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   509
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   510
    photometric := #palette.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   511
    samplesPerPixel := 1.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   512
    bitsPerSample := #(8).
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   513
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   514
    "Created: 21.4.1997 / 20:19:46 / cg"
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   515
    "Modified: 21.4.1997 / 20:21:12 / cg"
37
aeed5856f457 Initial revision
claus
parents:
diff changeset
   516
! !
aeed5856f457 Initial revision
claus
parents:
diff changeset
   517
210
5405de794686 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   518
!TargaReader class methodsFor:'documentation'!
5405de794686 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   519
5405de794686 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   520
version
1577
a8851bce16c5 isValidImageFile improved
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
   521
    ^ '$Header: /cvs/stx/stx/libview2/TargaReader.st,v 1.20 2002-07-17 10:56:36 cg Exp $'
210
5405de794686 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   522
! !
37
aeed5856f457 Initial revision
claus
parents:
diff changeset
   523
TargaReader initialize!