#BUGFIX by cg
class: TargaReader
class definition
changed: #readImage
byte order and logging
--- a/TargaReader.st Mon Sep 18 09:09:00 2017 +0200
+++ b/TargaReader.st Mon Sep 18 09:10:16 2017 +0200
@@ -15,7 +15,7 @@
ImageReader subclass:#TargaReader
instanceVariableNames:'orientation bytesPerRow bytesPerPixel imageType'
- classVariableNames:''
+ classVariableNames:'Verbose'
poolDictionaries:''
category:'Graphics-Images-Readers'
!
@@ -227,7 +227,8 @@
!
read16
- "read a 16 bit/pixel targa-image"
+ "read a 16 bit/pixel targa-image.
+ Notice, that the channels are in bgr order; not rgb"
|totalBytes remainingBytes dstIndex b1 b2|
@@ -237,19 +238,22 @@
dstIndex := 1.
remainingBytes := totalBytes.
[remainingBytes > 0] whileTrue:[
+ b2 := inStream nextByte.
b1 := inStream nextByte.
- b2 := inStream nextByte.
data at:dstIndex put:b1.
data at:dstIndex+1 put:b2.
+
dstIndex := dstIndex + 2.
remainingBytes := remainingBytes - 2.
].
"Created: / 29-08-2017 / 23:38:30 / cg"
+ "Modified: / 17-09-2017 / 13:35:21 / cg"
!
read16RLE
- "read a 16 bit/pixel rle encoded targa-image"
+ "read a 16 bit/pixel rle encoded targa-image.
+ Notice, that the channels are in bgr order; not rgb"
|total count dstIndex code n b1 b2|
@@ -260,8 +264,8 @@
code := inStream nextByte.
n := (code bitAnd:16r7F) + 1.
(code bitAnd:16r80) ~~ 0 ifTrue:[
+ b2 := inStream nextByte.
b1 := inStream nextByte.
- b2 := inStream nextByte.
n timesRepeat:[
data at:dstIndex put:b1.
data at:dstIndex+1 put:b2.
@@ -269,8 +273,8 @@
].
] ifFalse:[
n timesRepeat:[
+ b2 := inStream nextByte.
b1 := inStream nextByte.
- b2 := inStream nextByte.
data at:dstIndex put:b1.
data at:dstIndex+1 put:b2.
dstIndex := dstIndex + 2
@@ -280,10 +284,12 @@
].
"Created: / 29-08-2017 / 23:39:19 / cg"
+ "Modified (comment): / 17-09-2017 / 13:35:59 / cg"
!
read24
- "read a 24 bit/pixel targa-image"
+ "read a 24 bit/pixel targa-image.
+ Notice, that the channels are in bgr order; not rgb"
|totalBytes|
@@ -292,16 +298,17 @@
inStream nextBytes:totalBytes into:data.
"
- mhmh - pixel-byte order is blue-green-red
- swap blue & red bytes
+ mhmh - pixel-byte order is blue-green-red; swap blue & red bytes
"
self class swap:totalBytes bytesFromRGB_to_BGR_in:data.
"Modified: / 29-08-2017 / 23:06:02 / cg"
+ "Modified (comment): / 17-09-2017 / 13:37:53 / cg"
!
read24RLE
- "read an 8 bit/pixel rle encoded targa-image"
+ "read an 8 bit/pixel rle encoded targa-image.
+ Notice, that the channels are in bgr order; not rgb"
|total count dstIndex code n r g b|
@@ -337,10 +344,12 @@
"Created: / 21-04-1997 / 20:43:23 / cg"
"Modified: / 29-08-2017 / 23:06:35 / cg"
+ "Modified (comment): / 17-09-2017 / 13:37:58 / cg"
!
read32
- "read a 32 bit/pixel targa-image"
+ "read a 32 bit/pixel targa-image.
+ Notice, that the channels are in bgra order; not rgba"
|totalBytes remainingBytes dstIndex a r g b|
@@ -369,10 +378,12 @@
"
"Modified: / 29-08-2017 / 23:09:42 / cg"
+ "Modified (comment): / 17-09-2017 / 13:37:26 / cg"
!
read32RLE
- "read a 32 bit/pixel rle encoded targa-image; skip alpha channel (for now)"
+ "read a 32 bit/pixel rle encoded targa-image; skip alpha channel (for now).
+ Notice, that the channels are in bgra order; not rgba"
|total count dstIndex code n a r g b|
@@ -412,6 +423,7 @@
"Created: / 21-04-1997 / 20:43:54 / cg"
"Modified: / 29-08-2017 / 23:35:48 / cg"
+ "Modified (comment): / 17-09-2017 / 13:37:37 / cg"
!
read8
@@ -492,9 +504,9 @@
^ self fileFormatError:'unsupported depth: %1' with:depth printString.
].
depth == 32 ifTrue:[
- 'TargaReader [info]: alpha channel ignored' infoPrintCR.
+ Logger warning: 'TargaReader [info]: alpha channel ignored'.
] ifFalse:[
- 'TargaReader [info]: depth: ' infoPrint. depth infoPrintCR.
+ Verbose == true ifTrue:[ Logger info:'TargaReader [info]: depth: %1' with:depth ].
].
"/ MapRGB == 1
@@ -507,7 +519,7 @@
"/ 'TargaReader [warning]: unsupported imageType: ' errorPrint. imageType errorPrintCR.
^ self fileFormatError:'unsupported imageType: %1' with:imageType printString.
].
- 'TargaReader [info]: imageType: ' infoPrint. imageType infoPrintCR.
+ Verbose == true ifTrue:[ Logger info:'TargaReader [info]: imageType: %1' with:imageType].
self reportDimension.
@@ -639,7 +651,7 @@
"
"Modified: / 13-10-1998 / 19:50:48 / ps"
- "Modified: / 29-08-2017 / 23:41:12 / cg"
+ "Modified: / 18-09-2017 / 08:56:24 / cg"
! !
!TargaReader class methodsFor:'documentation'!