TargaReader.st
author Patrik Svestka <patrik.svestka@gmail.com>
Wed, 14 Nov 2018 12:13:31 +0100
branchjv
changeset 4213 8127ef0ff47d
parent 3855 1db7742d33ad
permissions -rw-r--r--
Issue #239: Fix all Smalltak/X source files to be in unicode (UTF8 without BOM) and prefixed by "{ Encoding: utf8 }" when any unicode character is present - All source *.st files are now Unicode UTF8 without BOM Files are in two groups (fileOut works this way in Smalltalk/X): - containing a unicode character have "{ Encoding: utf8 }" at the header - ASCII only are without the header
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
"
3855
1db7742d33ad Win32: Build libjpeg in its own directory, out-of-source-tree.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1848
diff changeset
    12
"{ Package: 'stx:libview2' }"
37
aeed5856f457 Initial revision
claus
parents:
diff changeset
    13
3855
1db7742d33ad Win32: Build libjpeg in its own directory, out-of-source-tree.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1848
diff changeset
    14
"{ NameSpace: Smalltalk }"
1577
a8851bce16c5 isValidImageFile improved
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
    15
37
aeed5856f457 Initial revision
claus
parents:
diff changeset
    16
ImageReader subclass:#TargaReader
1738
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
    17
	instanceVariableNames:'orientation bytesPerRow bytesPerPixel'
210
5405de794686 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    18
	classVariableNames:''
5405de794686 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    19
	poolDictionaries:''
1745
4fa0fad2a463 code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents: 1738
diff changeset
    20
	category:'Graphics-Images-Readers'
37
aeed5856f457 Initial revision
claus
parents:
diff changeset
    21
!
aeed5856f457 Initial revision
claus
parents:
diff changeset
    22
aeed5856f457 Initial revision
claus
parents:
diff changeset
    23
!TargaReader class methodsFor:'documentation'!
aeed5856f457 Initial revision
claus
parents:
diff changeset
    24
aeed5856f457 Initial revision
claus
parents:
diff changeset
    25
copyright
aeed5856f457 Initial revision
claus
parents:
diff changeset
    26
"
aeed5856f457 Initial revision
claus
parents:
diff changeset
    27
 COPYRIGHT (c) 1994 by Claus Gittinger
aeed5856f457 Initial revision
claus
parents:
diff changeset
    28
	      All Rights Reserved
aeed5856f457 Initial revision
claus
parents:
diff changeset
    29
aeed5856f457 Initial revision
claus
parents:
diff changeset
    30
 This software is furnished under a license and may be used
aeed5856f457 Initial revision
claus
parents:
diff changeset
    31
 only in accordance with the terms of that license and with the
aeed5856f457 Initial revision
claus
parents:
diff changeset
    32
 inclusion of the above copyright notice.   This software may not
aeed5856f457 Initial revision
claus
parents:
diff changeset
    33
 be provided or otherwise made available to, or used by, any
aeed5856f457 Initial revision
claus
parents:
diff changeset
    34
 other person.  No title to or ownership of the software is
aeed5856f457 Initial revision
claus
parents:
diff changeset
    35
 hereby transferred.
aeed5856f457 Initial revision
claus
parents:
diff changeset
    36
"
aeed5856f457 Initial revision
claus
parents:
diff changeset
    37
!
aeed5856f457 Initial revision
claus
parents:
diff changeset
    38
aeed5856f457 Initial revision
claus
parents:
diff changeset
    39
documentation
aeed5856f457 Initial revision
claus
parents:
diff changeset
    40
"
aeed5856f457 Initial revision
claus
parents:
diff changeset
    41
    this class provides methods for loading targa-file (tga) images.
556
a2d03470af59 documentation
Claus Gittinger <cg@exept.de>
parents: 555
diff changeset
    42
37
aeed5856f457 Initial revision
claus
parents:
diff changeset
    43
    Limitations: 
556
a2d03470af59 documentation
Claus Gittinger <cg@exept.de>
parents: 555
diff changeset
    44
        not fully tested (I only had a few targa files to check things)
a2d03470af59 documentation
Claus Gittinger <cg@exept.de>
parents: 555
diff changeset
    45
        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
    46
        Image saving not supported
37
aeed5856f457 Initial revision
claus
parents:
diff changeset
    47
aeed5856f457 Initial revision
claus
parents:
diff changeset
    48
    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
    49
    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
    50
37
aeed5856f457 Initial revision
claus
parents:
diff changeset
    51
    Suggestions: adapt & use the pbmplus library here.
210
5405de794686 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    52
5405de794686 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    53
    [See also:]
234
b6352d13e792 xrefs in documentation
Claus Gittinger <cg@exept.de>
parents: 210
diff changeset
    54
        Image Form Icon
210
5405de794686 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    55
        BlitImageReader FaceReader GIFReader JPEGReader PBMReader PCXReader 
5405de794686 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    56
        ST80FormReader SunRasterReader TIFFReader WindowsIconReader 
5405de794686 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    57
        XBMReader XPMReader XWDReader
37
aeed5856f457 Initial revision
claus
parents:
diff changeset
    58
"
1738
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
    59
!
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
    60
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
    61
format
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
    62
"
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
    63
    Shorts etc. are lsb.
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
    64
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
    65
    offset:
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
    66
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
    67
        1       lenID           byte
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
    68
        2       hasColorMap     byte
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
    69
        3       imageType       byte
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
    70
                         1   MapRGB  
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
    71
                         2   RawRGB   
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
    72
                         3   RawMono   
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
    73
                         9   MapEnCode 
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
    74
                         10  RawEnCode 
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
    75
        4, 5    cmapOffset      short
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
    76
        6, 7    cmapLength      short
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
    77
        8       cmapEntrySize   short
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
    78
        9,10    xOrg            short
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
    79
        11,12   yOrg            short
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
    80
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
    81
        13,14   width 
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
    82
        15,16   height 
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
    83
        17      depth 
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
    84
        18      flags
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
    85
                        0000 xxxx  attribute-bits-per-pixel
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
    86
                        0000 0001  greysc
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
    87
                        0000 0010  colour
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
    88
                        0000 0011  mapped
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
    89
                        0000 0100  rleEncoded
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
    90
                        0000 1000  interlaced
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
    91
                        00xx 0000  origin (0 -> lower-left / 1 -> l-r / 2 -> u-l / 3 -> u-r)
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
    92
                        xx00 0000  interleave (0 -> none / 1 -> odd/even / 2 ->4-fould / 3 reserved)
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
    93
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
    94
        19..    len             lenID-bytes
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
    95
        ..      colorMap        cmapLength*3 bytes iff hasColorMap ~~ 0
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
    96
"
37
aeed5856f457 Initial revision
claus
parents:
diff changeset
    97
! !
aeed5856f457 Initial revision
claus
parents:
diff changeset
    98
aeed5856f457 Initial revision
claus
parents:
diff changeset
    99
!TargaReader class methodsFor:'initialization'!
aeed5856f457 Initial revision
claus
parents:
diff changeset
   100
aeed5856f457 Initial revision
claus
parents:
diff changeset
   101
initialize
210
5405de794686 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   102
    "tell Image-class, that a new fileReader is present
398
aef700d15416 new suffix-table
Claus Gittinger <cg@exept.de>
parents: 299
diff changeset
   103
     for the '.tga' extension."
210
5405de794686 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   104
647
6f26c76aa0c9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 630
diff changeset
   105
    MIMETypes defineImageType:'image/x-targa' suffix:'tga' reader:self.
37
aeed5856f457 Initial revision
claus
parents:
diff changeset
   106
630
48657c687a8b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 556
diff changeset
   107
    "Modified: 27.6.1997 / 18:39:43 / cg"
37
aeed5856f457 Initial revision
claus
parents:
diff changeset
   108
! !
aeed5856f457 Initial revision
claus
parents:
diff changeset
   109
aeed5856f457 Initial revision
claus
parents:
diff changeset
   110
!TargaReader class methodsFor:'testing'!
aeed5856f457 Initial revision
claus
parents:
diff changeset
   111
aeed5856f457 Initial revision
claus
parents:
diff changeset
   112
isValidImageFile:aFileName
aeed5856f457 Initial revision
claus
parents:
diff changeset
   113
    "return true, if aFileName contains a targa-file image"
aeed5856f457 Initial revision
claus
parents:
diff changeset
   114
1577
a8851bce16c5 isValidImageFile improved
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
   115
    |aStream w h depth flags imageType ok|
a8851bce16c5 isValidImageFile improved
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
   116
a8851bce16c5 isValidImageFile improved
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
   117
    ok := true.
37
aeed5856f457 Initial revision
claus
parents:
diff changeset
   118
43
e85c7d392833 *** empty log message ***
claus
parents: 37
diff changeset
   119
    aStream := self streamReadingFile:aFileName.
e85c7d392833 *** empty log message ***
claus
parents: 37
diff changeset
   120
    aStream isNil ifTrue:[^ false].
e85c7d392833 *** empty log message ***
claus
parents: 37
diff changeset
   121
    aStream binary.
1577
a8851bce16c5 isValidImageFile improved
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
   122
a8851bce16c5 isValidImageFile improved
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
   123
    aStream next.   "lenID"
a8851bce16c5 isValidImageFile improved
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
   124
    aStream next.   "hasColorMap"
a8851bce16c5 isValidImageFile improved
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
   125
    imageType := aStream next.  
a8851bce16c5 isValidImageFile improved
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
   126
    aStream skip:2. "cmapOffset"
a8851bce16c5 isValidImageFile improved
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
   127
    aStream skip:2. "cmapLength"
a8851bce16c5 isValidImageFile improved
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
   128
    aStream next.   "cmapEntrySize"
a8851bce16c5 isValidImageFile improved
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
   129
    aStream skip:2. "xOrg"
a8851bce16c5 isValidImageFile improved
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
   130
    aStream skip:2. "yOrg"
37
aeed5856f457 Initial revision
claus
parents:
diff changeset
   131
43
e85c7d392833 *** empty log message ***
claus
parents: 37
diff changeset
   132
    w := aStream nextShortMSB:false.
e85c7d392833 *** empty log message ***
claus
parents: 37
diff changeset
   133
    h := aStream nextShortMSB:false.
37
aeed5856f457 Initial revision
claus
parents:
diff changeset
   134
43
e85c7d392833 *** empty log message ***
claus
parents: 37
diff changeset
   135
    depth := aStream next.
e85c7d392833 *** empty log message ***
claus
parents: 37
diff changeset
   136
    flags := aStream next.
37
aeed5856f457 Initial revision
claus
parents:
diff changeset
   137
1577
a8851bce16c5 isValidImageFile improved
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
   138
    "/ MapRGB == 1
a8851bce16c5 isValidImageFile improved
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
   139
    "/ RawRGB == 2
a8851bce16c5 isValidImageFile improved
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
   140
    "/ RawMono == 3
a8851bce16c5 isValidImageFile improved
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
   141
    "/ MapEnCode == 9
a8851bce16c5 isValidImageFile improved
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
   142
    "/ RawEnCode == 10
a8851bce16c5 isValidImageFile improved
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
   143
a8851bce16c5 isValidImageFile improved
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
   144
    (#(1 2 3 9 10) includes:imageType) ifFalse:[
a8851bce16c5 isValidImageFile improved
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
   145
        "/ 'TargaReader [warning]: unsupported imageType: ' errorPrint. imageType errorPrintCR.
a8851bce16c5 isValidImageFile improved
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
   146
        ok := false
a8851bce16c5 isValidImageFile improved
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
   147
    ] ifTrue:[
a8851bce16c5 isValidImageFile improved
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
   148
        (#(8 "16" 24 32) includes:depth) ifFalse:[
a8851bce16c5 isValidImageFile improved
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
   149
            ok := false
a8851bce16c5 isValidImageFile improved
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
   150
        ].
37
aeed5856f457 Initial revision
claus
parents:
diff changeset
   151
    ].
43
e85c7d392833 *** empty log message ***
claus
parents: 37
diff changeset
   152
    aStream close. 
1577
a8851bce16c5 isValidImageFile improved
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
   153
    ^ ok
37
aeed5856f457 Initial revision
claus
parents:
diff changeset
   154
aeed5856f457 Initial revision
claus
parents:
diff changeset
   155
    "
aeed5856f457 Initial revision
claus
parents:
diff changeset
   156
     TargaReader isValidImageFile:'bitmaps/test.tga'    
aeed5856f457 Initial revision
claus
parents:
diff changeset
   157
     TargaReader isValidImageFile:'bitmaps/garfield.gif'  
555
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   158
    "
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   159
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   160
    "Modified: 21.4.1997 / 20:46:52 / cg"
37
aeed5856f457 Initial revision
claus
parents:
diff changeset
   161
! !
aeed5856f457 Initial revision
claus
parents:
diff changeset
   162
1848
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   163
!TargaReader methodsFor:'private-reading'!
37
aeed5856f457 Initial revision
claus
parents:
diff changeset
   164
1738
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   165
handleImageOrientation
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   166
    |rowIdx startIdx endIdx t|
555
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   167
1738
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   168
    orientation == #topLeft ifTrue:[
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   169
        ^ self.
37
aeed5856f457 Initial revision
claus
parents:
diff changeset
   170
    ].
aeed5856f457 Initial revision
claus
parents:
diff changeset
   171
1738
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   172
    orientation == #topRight ifTrue:[
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   173
        "/ flip horizontal
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   174
        rowIdx := 1.
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   175
        1 to:height do:[:row |
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   176
            startIdx := rowIdx.
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   177
            endIdx := rowIdx + bytesPerRow - bytesPerPixel.
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   178
            1 to:width//2 do:[:x |
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   179
                0 to:bytesPerPixel-1 do:[:c |
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   180
                    t := data at:startIdx+c.
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   181
                    data at:startIdx+c put:(data at:endIdx+c).
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   182
                    data at:endIdx+c put:t.
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   183
                ].
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   184
                startIdx := startIdx + bytesPerPixel.
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   185
                endIdx := endIdx - bytesPerPixel.
1065
32a68620ddab care for EOF while reading colorMap.
Claus Gittinger <cg@exept.de>
parents: 918
diff changeset
   186
            ].
1738
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   187
            rowIdx := rowIdx + width.
555
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   188
        ].
1738
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   189
        ^ self.
555
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   190
    ].
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   191
1738
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   192
    orientation == #bottomLeft ifTrue:[
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   193
        "/ flip vertical
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   194
        startIdx := 1.
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   195
        endIdx := 1 + ((height - 1) * bytesPerRow).
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   196
        t := ByteArray new:bytesPerRow.
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   197
        1 to:height//2 do:[:row |
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   198
            t replaceFrom:1 to:bytesPerRow with:data startingAt:startIdx.
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   199
            data replaceFrom:startIdx to:startIdx+bytesPerRow-1 with:data startingAt:endIdx.
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   200
            data replaceFrom:endIdx to:endIdx+bytesPerRow-1 with:t startingAt:1.
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   201
            startIdx := startIdx + bytesPerRow.
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   202
            endIdx := endIdx - bytesPerRow
555
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   203
        ].
1738
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   204
        ^ self.
555
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
1738
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   207
    'TargaReader [warning]: unsupported orientation: ' errorPrint. orientation errorPrintCR.
555
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   208
!
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   209
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   210
read24
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   211
    "read a 24 bit/pixel targa-image"
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   212
1738
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   213
    |totalBytes|
555
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   214
1738
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   215
    totalBytes := width * height * 3.
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   216
    data := ByteArray new:totalBytes.
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   217
    inStream nextBytes:totalBytes into:data.
299
23d89531904f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 259
diff changeset
   218
37
aeed5856f457 Initial revision
claus
parents:
diff changeset
   219
    "
299
23d89531904f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 259
diff changeset
   220
     mhmh - pixel-byte order is blue-green-red
23d89531904f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 259
diff changeset
   221
     swap blue & red bytes
37
aeed5856f457 Initial revision
claus
parents:
diff changeset
   222
    "
1738
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   223
    self class swap:totalBytes bytesFromRGB_to_BGR_in:data.
37
aeed5856f457 Initial revision
claus
parents:
diff changeset
   224
aeed5856f457 Initial revision
claus
parents:
diff changeset
   225
    photometric := #rgb.
aeed5856f457 Initial revision
claus
parents:
diff changeset
   226
    samplesPerPixel := 3.
aeed5856f457 Initial revision
claus
parents:
diff changeset
   227
    bitsPerSample := #(8 8 8).
555
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   228
!
37
aeed5856f457 Initial revision
claus
parents:
diff changeset
   229
555
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   230
read24RLE
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   231
    "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
   232
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   233
    |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
   234
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   235
    data := ByteArray new:((total := width * height * 3)).
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   236
    count := 0.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   237
    dstIndex := 1.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   238
    [count < total] whileTrue:[
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   239
        code := inStream nextByte.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   240
        n := (code bitAnd:16r7F) + 1.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   241
        (code bitAnd:16r80) ~~ 0 ifTrue:[
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   242
            b := inStream nextByte.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   243
            g := inStream nextByte.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   244
            r := inStream nextByte.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   245
            n timesRepeat:[
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   246
                data at:dstIndex put:r.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   247
                data at:dstIndex+1 put:g.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   248
                data at:dstIndex+2 put:b.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   249
                dstIndex := dstIndex + 3
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   250
            ].
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   251
        ] ifFalse:[
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   252
            n timesRepeat:[
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   253
                b := inStream nextByte.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   254
                g := inStream nextByte.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   255
                r := inStream nextByte.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   256
                data at:dstIndex put:r.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   257
                data at:dstIndex+1 put:g.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   258
                data at:dstIndex+2 put:b.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   259
                dstIndex := dstIndex + 3
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   260
            ]
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   261
        ].
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   262
        count := count + (n * 3).
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
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   265
    photometric := #rgb.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   266
    samplesPerPixel := 3.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   267
    bitsPerSample := #(8 8 8).
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   268
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   269
    "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
   270
    "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
   271
!
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   272
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   273
read32
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   274
    "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
   275
1738
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   276
    |totalBytes remainingBytes dstIndex a r g b|
555
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   277
1738
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   278
    totalBytes := width * height * 3.
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   279
    data := ByteArray new:totalBytes.
555
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
    dstIndex := 1.
1738
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   282
    remainingBytes := totalBytes.
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   283
    [remainingBytes > 0] whileTrue:[
555
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   284
        b := inStream nextByte.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   285
        g := inStream nextByte.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   286
        r := inStream nextByte.
1738
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   287
        a := inStream nextByte.   "/ alpha - skipped
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   288
        data at:dstIndex   put:r.
555
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   289
        data at:dstIndex+1 put:g.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   290
        data at:dstIndex+2 put:b.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   291
        dstIndex := dstIndex + 3.
1738
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   292
        remainingBytes := remainingBytes - 3.
555
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   293
    ].
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   294
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   295
    photometric := #rgb.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   296
    samplesPerPixel := 3.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   297
    bitsPerSample := #(8 8 8).
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   298
1738
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   299
    "
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   300
     TargaReader fromFile:'/phys/exept//unsaved1/pd_stuff/graphic/3d_engines/crystal_space/CS/plugins/video/canvas/sdl/img/move.tga'
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   301
     TargaReader fromFile:'/phys/exept/unsaved2/smalltalk/Squeak/croquet/Croquet/Content/Cisco/2520/Textures/2520caseback.tga'
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   302
     TargaReader fromFile:'/phys/exept/unsaved2/smalltalk/Squeak/croquet/Croquet/Content/Cisco/2520/Textures/2520dimm1front.tga'
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   303
    "
555
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   304
!
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
read32RLE
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   307
    "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
   308
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   309
    |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
   310
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   311
    data := ByteArray new:((total := width * height * 3)).
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   312
    count := 0.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   313
    dstIndex := 1.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   314
    [count < total] whileTrue:[
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   315
        code := inStream nextByte.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   316
        n := (code bitAnd:16r7F) + 1.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   317
        (code bitAnd:16r80) ~~ 0 ifTrue:[
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   318
            b := inStream nextByte.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   319
            g := inStream nextByte.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   320
            r := inStream nextByte.
1738
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   321
            a := inStream nextByte.             "/ alpha - skipped
555
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   322
            n timesRepeat:[
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   323
                data at:dstIndex put:r.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   324
                data at:dstIndex+1 put:g.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   325
                data at:dstIndex+2 put:b.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   326
                dstIndex := dstIndex + 3
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   327
            ].
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   328
        ] ifFalse:[
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   329
            n timesRepeat:[
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   330
                b := inStream nextByte.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   331
                g := inStream nextByte.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   332
                r := inStream nextByte.
1738
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   333
                a := inStream nextByte.         "/ alpha - skipped
555
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   334
                data at:dstIndex put:r.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   335
                data at:dstIndex+1 put:g.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   336
                data at:dstIndex+2 put:b.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   337
                dstIndex := dstIndex + 3
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   338
            ]
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   339
        ].
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   340
        count := count + (n * 3).
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   341
    ].
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   342
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   343
    photometric := #rgb.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   344
    samplesPerPixel := 3.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   345
    bitsPerSample := #(8 8 8).
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   346
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   347
    "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
   348
    "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
   349
!
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   350
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   351
read8
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   352
    "read an 8 bit/pixel targa-image"
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   353
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   354
    data := ByteArray new:(width * height).
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   355
    inStream nextBytes:(data size) into:data.
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
    colorMap isNil ifTrue:[
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   358
        photometric := #blackIs0.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   359
    ] ifFalse:[
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   360
        photometric := #palette.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   361
    ].
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   362
    samplesPerPixel := 1.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   363
    bitsPerSample := #(8).
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   364
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   365
    "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
   366
    "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
   367
!
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   368
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   369
read8RLE
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   370
    "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
   371
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   372
    |total count dstIndex code n byte|
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   373
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   374
    data := ByteArray new:((total := width * height)).
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   375
    count := 0.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   376
    dstIndex := 1.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   377
    [count < total] whileTrue:[
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   378
        code := inStream nextByte.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   379
        n := (code bitAnd:16r7F) + 1.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   380
        (code bitAnd:16r80) ~~ 0 ifTrue:[
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   381
            byte := inStream nextByte.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   382
            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
   383
        ] ifFalse:[
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   384
            inStream nextBytes:n into:data startingAt:dstIndex.
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.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   387
        dstIndex := dstIndex + n.
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
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   390
    photometric := #palette.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   391
    samplesPerPixel := 1.
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   392
    bitsPerSample := #(8).
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   393
f51ec2cc4482 support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
   394
    "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
   395
    "Modified: 21.4.1997 / 20:21:12 / cg"
1738
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   396
!
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   397
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   398
readColorMap:cmapLength
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   399
    colorMap := Array new:cmapLength.
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   400
    1 to:cmapLength do:[:index |
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   401
        |r g b|
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   402
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   403
        b := inStream nextByte.
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   404
        g := inStream nextByte.
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   405
        r := inStream nextByte.
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   406
        (r isNil or:[g isNil or:[b isNil]]) ifTrue:[
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   407
            ^ self fileFormatError:('short file - probably not targa format').
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   408
        ].
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   409
        colorMap at:index put:(Color redByte:r greenByte:g blueByte:b).
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   410
    ].
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   411
    ^ colorMap
37
aeed5856f457 Initial revision
claus
parents:
diff changeset
   412
! !
aeed5856f457 Initial revision
claus
parents:
diff changeset
   413
1848
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   414
!TargaReader methodsFor:'reading'!
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   415
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   416
readImage
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   417
    "read a targa-image from aFileName. return the receiver (with all
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   418
     relevant instance variables set for the image) or nil on error"
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   419
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   420
    |depth flags lenID hasColorMap imageType 
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   421
     cmapOffset cmapLength cmapEntrySize xOrg yOrg rle|
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   422
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   423
    inStream binary.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   424
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   425
    lenID := inStream next.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   426
    hasColorMap := inStream next.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   427
    imageType := inStream next.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   428
    cmapOffset := inStream nextShortMSB:false.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   429
    cmapLength := inStream nextShortMSB:false.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   430
    cmapEntrySize := inStream next.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   431
    xOrg := inStream nextShortMSB:false.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   432
    yOrg := inStream nextShortMSB:false.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   433
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   434
    width := inStream nextShortMSB:false.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   435
    height := inStream nextShortMSB:false.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   436
    depth := inStream next.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   437
    (#(8 "16" 24 32) includes:depth) ifFalse:[
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   438
        ^ self fileFormatError:('unsupported depth: ', depth printString).
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   439
    ].
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   440
    depth == 32 ifTrue:[
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   441
        'TargaReader [info]: alpha channel ignored' infoPrintCR.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   442
    ] ifFalse:[
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   443
        'TargaReader [info]: depth: ' infoPrint. depth infoPrintCR.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   444
    ].
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   445
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   446
    "/ MapRGB == 1
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   447
    "/ RawRGB == 2
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   448
    "/ RawMono == 3
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   449
    "/ MapEnCode == 9
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   450
    "/ RawEnCode == 10
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   451
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   452
    (#(1 2 9 10) includes:imageType) ifFalse:[
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   453
        "/ 'TargaReader [warning]: unsupported imageType: ' errorPrint. imageType errorPrintCR.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   454
        ^ self fileFormatError:('unsupported imageType: ', imageType printString).
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   455
    ].
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   456
    'TargaReader [info]: imageType: ' infoPrint. imageType infoPrintCR.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   457
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   458
    self reportDimension.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   459
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   460
    "/ flags:
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   461
    "/    0000 xxxx  attribute-bits-per-pixel
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   462
    "/    0000 0001  greysc
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   463
    "/    0000 0010  colour
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   464
    "/    0000 0011  mapped
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   465
    "/    0000 0100  rleEncoded
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   466
    "/    0000 1000  interlaced
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   467
    "/    00xx 0000  origin (0 -> lower-left / 1 -> l-r / 2 -> u-l / 3 -> u-r)
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   468
    "/    xx00 0000  interleave (0 -> none / 1 -> odd/even / 2 ->4-fould / 3 reserved)
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   469
    "/
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   470
    flags := inStream next.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   471
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   472
    (flags bitAnd:2r11000000) ~~ 0 ifTrue:[
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   473
        ^ self fileFormatError:('unsupported interlace: ' , flags printString).
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   474
    ].
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   475
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   476
    rle := flags bitTest:2r000001000.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   477
    flags := flags bitAnd:2r111110111.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   478
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   479
    (flags bitAnd:2r00001111) ~~ 0 ifTrue:[
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   480
        ^ self fileFormatError:('unsupported flags: ' , flags printString).
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   481
    ].
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   482
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   483
    (flags bitAnd:2r00110000) == 16r20 ifTrue:[
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   484
        orientation := #topLeft
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   485
    ] ifFalse:[
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   486
        (flags bitAnd:2r00110000) == 16r30 ifTrue:[
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   487
            orientation := #topRight
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   488
        ] ifFalse:[
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   489
            (flags bitAnd:2r00110000) == 16r10 ifTrue:[
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   490
                orientation := #bottomRight
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   491
            ] ifFalse:[
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   492
                (flags bitAnd:2r00110000) == 0 ifTrue:[
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   493
                    orientation := #bottomLeft
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   494
                ]
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   495
            ]
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   496
        ]
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   497
    ].
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   498
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   499
    lenID ~~ 0 ifTrue:[
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   500
        inStream skip:lenID
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   501
    ].
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   502
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   503
    hasColorMap ~~ 0 ifTrue:[
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   504
        "/ read the colorMap
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   505
        colorMap := self readColorMap:cmapLength.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   506
        'TargaReader [info]: has colorMap' infoPrintCR.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   507
    ].
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   508
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   509
    depth == 32 ifTrue:[
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   510
        imageType == 2 ifTrue:[
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   511
"/            rle ifTrue:[self halt:'oops - should not happen'].
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   512
            self read32.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   513
        ] ifFalse:[
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   514
"/            rle ifFalse:[self halt:'oops - should not happen'].
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   515
            self read32RLE.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   516
        ].
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   517
        bytesPerRow := width*3.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   518
        bytesPerPixel := 3.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   519
    ].
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   520
    depth == 24 ifTrue:[
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   521
        imageType == 2 ifTrue:[
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   522
"/            rle ifTrue:[self halt:'oops - should not happen'].
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   523
            self read24.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   524
        ] ifFalse:[
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   525
"/            rle ifFalse:[self halt:'oops - should not happen'].
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   526
            self read24RLE.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   527
        ].
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   528
        bytesPerRow := width*3.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   529
        bytesPerPixel := 3.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   530
    ].
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   531
    depth == 8 ifTrue:[
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   532
        imageType == 1 ifTrue:[
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   533
"/            rle ifTrue:[self halt:'oops - should not happen'].
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   534
            self read8.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   535
        ] ifFalse:[
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   536
"/            rle ifFalse:[self halt:'oops - should not happen'].
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   537
            self read8RLE
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   538
        ].
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   539
        bytesPerRow := width.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   540
        bytesPerPixel := 1.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   541
    ].
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   542
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   543
    self handleImageOrientation.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   544
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   545
    "
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   546
     TargaReader fromFile:'bitmaps/test.tga' 
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   547
    "
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   548
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   549
    "Modified: / 7.9.1998 / 21:12:12 / cg"
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   550
    "Modified: / 13.10.1998 / 19:50:48 / ps"
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   551
! !
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   552
210
5405de794686 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   553
!TargaReader class methodsFor:'documentation'!
5405de794686 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   554
5405de794686 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   555
version
1848
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   556
    ^ '$Header: /cvs/stx/stx/libview2/TargaReader.st,v 1.25 2003-11-19 15:38:53 cg Exp $'
210
5405de794686 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   557
! !
1738
9c85e9d8326b refactorings
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   558
3855
1db7742d33ad Win32: Build libjpeg in its own directory, out-of-source-tree.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1848
diff changeset
   559
37
aeed5856f457 Initial revision
claus
parents:
diff changeset
   560
TargaReader initialize!