PICTReader.st
changeset 1849 e3c78a95e9f2
parent 1843 fef27ba933ff
child 1850 67d2c8b18c60
--- a/PICTReader.st	Wed Nov 19 16:38:53 2003 +0100
+++ b/PICTReader.st	Wed Nov 19 20:18:30 2003 +0100
@@ -22,6 +22,13 @@
 	category:'Graphics-Images-Readers'
 !
 
+Object subclass:#PICTFrame
+	instanceVariableNames:'image sourceRectangle destinationRectangle mode maskRegion'
+	classVariableNames:''
+	poolDictionaries:''
+	privateIn:PICTReader
+!
+
 !PICTReader class methodsFor:'documentation'!
 
 copyright
@@ -57,9 +64,17 @@
 
 examples
 "
-  PICTReader fromFile:'/usr/lib/qt/examples/picture/car_orig.pic'
-  PICTReader fromFile:'/usr/lib/qt-2.3.2/examples/picture/car_orig.pic'
-
+  PICTReader fromFile:'/unsaved2/stefan/nil/home/stefan/dos/winword/shared/ms.pct'
+  PICTReader fromFile:'/phys/exept/tmp/pict/BLK.PCT'
+  PICTReader fromFile:'/phys/exept/tmp/pict/BLU.PCT'
+  PICTReader fromFile:'/phys/exept/tmp/pict/GRN.PCT'
+  PICTReader fromFile:'/phys/exept/tmp/pict/RED.PCT'
+  PICTReader fromFile:'/phys/exept/tmp/pict/WHT.PCT'
+  PICTReader fromFile:'/phys/exept/tmp/pict/YEL.PCT'
+  PICTReader fromFile:'/phys/exept/tmp/pict/FLAG_B24.PCT'
+  PICTReader fromFile:'/phys/exept/tmp/pict/MARBLES.PCT'
+  PICTReader fromFile:'/phys/exept/tmp/pict/TRU256.PCT'
+  PICTReader fromFile:'/phys/exept/tmp/pict/VENUS.PCT'
 
 
   example7 --- Version 2 PICTure ---
@@ -744,12 +759,22 @@
                                 pad: pad.
 
         " self debug: [anImage displayOn: ScheduledControllers activeController view graphicsContext]. "
-        anArray := Array
-                    with: anImage
-                    with: srcRect
-                    with: dstRect
-                    with: mode.
-        isMaskRgn = true ifTrue: [anArray := anArray , (Array with: maskRgn)].
+"/ OLD
+"/        anArray := Array
+"/                    with: anImage
+"/                    with: srcRect
+"/                    with: dstRect
+"/                    with: mode.
+"/        isMaskRgn = true ifTrue: [anArray := anArray , (Array with: maskRgn)].
+"/ NEW:
+        anArray := PICTFrame new
+                    image:anImage 
+                    sourceRectangle:srcRect 
+                    destinationRectangle:dstRect 
+                    mode:mode.
+        isMaskRgn = true ifTrue: [
+            anArray maskRegion:maskRgn
+        ].
         ^anArray
 !
 
@@ -809,13 +834,13 @@
 
 readDirectPixData4
         | palette image row scalingValue color index r g b |
-        palette := FixedPalette
-                                redShift: 16
-                                redMask: 255
-                                greenShift: 8
-                                greenMask: 255
-                                blueShift: 0
-                                blueMask: 255.
+"/        palette := FixedPalette
+"/                                redShift: 16
+"/                                redMask: 255
+"/                                greenShift: 8
+"/                                greenMask: 255
+"/                                blueShift: 0
+"/                                blueMask: 255.
         image := Image
                                 extent: bounds width @ bounds height
                                 depth: 24
@@ -832,27 +857,34 @@
                         b := row size // 3 * 2 + 1.
                         row size // 3
                                 timesRepeat: 
-                                        [scalingValue := ColorValue scalingValue.
-                                        color := ColorValue
-                                                                scaledRed: (self
-                                                                                convertValue: ((row at: r)
-                                                                                                bitAnd: 255)
-                                                                                from: 255
-                                                                                to: scalingValue)
-                                                                scaledGreen: (self
-                                                                                convertValue: ((row at: g)
-                                                                                                bitAnd: 255)
-                                                                                from: 255
-                                                                                to: scalingValue)
-                                                                scaledBlue: (self
-                                                                                convertValue: (row at: b)
-                                                                                from: 255
-                                                                                to: scalingValue).
-                                        index := palette indexOfPaintNearest: color.
-                                        image
-                                                atX: x
-                                                y: y
-                                                put: index.
+                                        [
+                                        "/ ST/X
+                                        image pixelAtX:x y:y put:( ((((row at: r) bitShift:8)
+                                                                    bitOr:(row at: g)) bitShift:8)
+                                                                   bitOr:(row at: b)).
+
+                                        "/ VW
+"/                                        scalingValue := ColorValue scalingValue.
+"/                                        color := ColorValue
+"/                                                                scaledRed: (self
+"/                                                                                convertValue: ((row at: r)
+"/                                                                                                bitAnd: 255)
+"/                                                                                from: 255
+"/                                                                                to: scalingValue)
+"/                                                                scaledGreen: (self
+"/                                                                                convertValue: ((row at: g)
+"/                                                                                                bitAnd: 255)
+"/                                                                                from: 255
+"/                                                                                to: scalingValue)
+"/                                                                scaledBlue: (self
+"/                                                                                convertValue: (row at: b)
+"/                                                                                from: 255
+"/                                                                                to: scalingValue).
+"/                                        index := palette indexOfPaintNearest: color.
+"/                                        image
+"/                                                atX: x
+"/                                                y: y
+"/                                                put: index.
                                         r := r + 1.
                                         g := g + 1.
                                         b := b + 1.
@@ -885,12 +917,25 @@
         isMaskRgn = true ifTrue: [maskRgn := self readRegion].
         anImage := self readDirectPixData.
         " self debug: [anImage displayOn: ScheduledControllers activeController view graphicsContext]. "
-        anArray := Array
-                                with: anImage
-                                with: srcRect
-                                with: dstRect
-                                with: mode.
-        isMaskRgn = true ifTrue: [anArray := anArray , (Array with: maskRgn)].
+"/ OLD:
+"/        anArray := Array
+"/                                with: anImage
+"/                                with: srcRect
+"/                                with: dstRect
+"/                                with: mode.
+"/        isMaskRgn = true ifTrue: [
+"/            anArray := anArray , (Array with: maskRgn)
+"/        ].
+
+"/ NEW:
+        anArray := PICTFrame new
+                    image:anImage 
+                    sourceRectangle:srcRect 
+                    destinationRectangle:dstRect 
+                    mode:mode.
+        isMaskRgn = true ifTrue: [
+            anArray maskRegion:maskRgn
+        ].
         ^anArray
 !
 
@@ -983,12 +1028,22 @@
                                 bits: pixData
                                 pad: pad.
         " self debug: [anImage displayOn: ScheduledControllers activeController view graphicsContext]. "
-        anArray := Array
-                                with: anImage
-                                with: srcRect
-                                with: dstRect
-                                with: mode.
-        isMaskRgn = true ifTrue: [anArray := anArray , (Array with: maskRgn)].
+"/ OLD:
+"/        anArray := Array
+"/                                with: anImage
+"/                                with: srcRect
+"/                                with: dstRect
+"/                                with: mode.
+"/        isMaskRgn = true ifTrue: [anArray := anArray , (Array with: maskRgn)].
+"/ NEW:
+        anArray := PICTFrame new
+                    image:anImage 
+                    sourceRectangle:srcRect 
+                    destinationRectangle:dstRect 
+                    mode:mode.
+        isMaskRgn = true ifTrue: [
+            anArray maskRegion:maskRgn
+        ].
         ^anArray
 !
 
@@ -1438,22 +1493,28 @@
 
 colorValueFrom: rgbInteger 
         | scalingValue |
-        scalingValue := ColorValue scalingValue.
-        ^ColorValue
-                scaledRed: (self
-                                convertValue: ((rgbInteger bitShift: -32)
-                                                bitAnd: 65535)
-                                from: 65535
-                                to: scalingValue)
-                scaledGreen: (self
-                                convertValue: ((rgbInteger bitShift: -16)
-                                                bitAnd: 65535)
-                                from: 65535
-                                to: scalingValue)
-                scaledBlue: (self
-                                convertValue: (rgbInteger bitAnd: 65535)
-                                from: 65535
-                                to: scalingValue)
+
+        ^ Color 
+            redShort:((rgbInteger bitShift: -32) bitAnd: 65535)
+            greenShort:((rgbInteger bitShift: -16) bitAnd: 65535) 
+            blueShort:(rgbInteger bitAnd: 65535)
+
+"/        scalingValue := ColorValue scalingValue.
+"/        ^ColorValue
+"/                scaledRed: (self
+"/                                convertValue: ((rgbInteger bitShift: -32)
+"/                                                bitAnd: 65535)
+"/                                from: 65535
+"/                                to: scalingValue)
+"/                scaledGreen: (self
+"/                                convertValue: ((rgbInteger bitShift: -16)
+"/                                                bitAnd: 65535)
+"/                                from: 65535
+"/                                to: scalingValue)
+"/                scaledBlue: (self
+"/                                convertValue: (rgbInteger bitAnd: 65535)
+"/                                from: 65535
+"/                                to: scalingValue)
 !
 
 errorSorryNotSupported
@@ -1621,6 +1682,10 @@
         ^packStream contents
 !
 
+progress:fraction
+    self reportProgress:fraction
+!
+
 rgbIntegerFrom: aColorValue 
         | scalingValue |
         scalingValue := ColorValue scalingValue.
@@ -1674,18 +1739,21 @@
     currentOpcode := nil.
     imageSequence := OrderedCollection new.
     self readHeader.
+    self reportDimension.
     endOpcode := 16r00FF.
     [currentOpcode = endOpcode] whileFalse: [self nextOpcode].
 
     imageSequence isEmpty ifTrue: [^nil].
     imageSequence size = 1 ifTrue: [
-        ^ imageSequence first first
+        "/ OLD:
+        "/ ^ imageSequence first first
+        "/ NEW:
+        ^ imageSequence first image
     ].
     ^ self mergeImages
 
     "
-     PICTReader fromFile:'/usr/lib/qt/examples/picture/car_orig.pic'
-     PICTReader fromFile:'/usr/lib/qt-2.3.2/examples/picture/car_orig.pic'
+     PICTReader fromFile:'/unsaved2/stefan/nil/home/stefan/dos/winword/shared/ms.pct'
     "
 ! !
 
@@ -1804,10 +1872,45 @@
 "/        ^anImage
 ! !
 
+!PICTReader::PICTFrame methodsFor:'accessing'!
+
+destinationRectangle
+    ^ destinationRectangle
+!
+
+image
+    ^ image
+!
+
+image:imageArg sourceRectangle:sourceRectangleArg destinationRectangle:destinationRectangleArg mode:modeArg 
+    "set instance variables (automatically generated)"
+
+    image := imageArg.
+    sourceRectangle := sourceRectangleArg.
+    destinationRectangle := destinationRectangleArg.
+    mode := modeArg.
+!
+
+maskRegion
+    ^ maskRegion
+!
+
+maskRegion:something
+    maskRegion := something.
+!
+
+mode
+    ^ mode
+!
+
+sourceRectangle
+    ^ sourceRectangle
+! !
+
 !PICTReader class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libview2/PICTReader.st,v 1.6 2003-11-19 13:20:37 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libview2/PICTReader.st,v 1.7 2003-11-19 19:18:30 cg Exp $'
 ! !
 
 PICTReader initialize!