Image.st
branchjv
changeset 7170 e5374bb05083
parent 7157 9c370b5a2596
child 7177 03d926bea344
--- a/Image.st	Fri Feb 26 16:42:00 2016 +0000
+++ b/Image.st	Sun Feb 28 14:47:05 2016 +0000
@@ -23,7 +23,8 @@
 		ImageNotFoundQuerySignal BadImageFormatQuerySignal
 		ImageSaveErrorSignal ImageLoadErrorSignal FileCreationErrorSignal
 		CannotRepresentImageSignal InformationLostQuerySignal
-		UnrepresentableColorSignal'
+		UnrepresentableColorSignal ARGB_A_OFFSET_MACHINE
+		ARGB_R_OFFSET_MACHINE ARGB_G_OFFSET_MACHINE ARGB_B_OFFSET_MACHINE'
 	poolDictionaries:''
 	category:'Graphics-Images'
 !
@@ -799,63 +800,75 @@
 
     "setup tracker of known pictures"
     Lobby isNil ifTrue:[
-	Lobby := Registry new.
-	ObjectMemory addDependent:self.
-
-	"/ define the algorithm to use for dithering -
-	"/ supported values are:
-	"/      #threshold
-	"/      #ordered
-	"/      #floydSteinberg
-	"/      #burkes
-
-	DitherAlgorithm := #floydSteinberg.
-
-	(Display notNil and:[Display hasGrayscales]) ifFalse:[
-	    NumberOfDitherColors := 64
-	] ifTrue:[
-	    "as far as I remember, this is about the number of grey values, the eye can distinguish"
-	    NumberOfDitherColors := 100
-	].
-
-	"define reader classes"
-	self initializeFileFormatTable.
-	self initializeMIMETable.
-
-	CollectGarbageWhenRunningOutOfColors := false.
-
-	ImageErrorSignal := Error newSignalMayProceed:true.
-	ImageErrorSignal nameClass:self message:#imageErrorSignal.
-
-	ImageSaveErrorSignal := ImageErrorSignal newSignalMayProceed:true.
-	ImageSaveErrorSignal nameClass:self message:#imageSaveErrorSignal.
-
-	FileCreationErrorSignal := ImageSaveErrorSignal newSignalMayProceed:true.
-	FileCreationErrorSignal nameClass:self message:#fileCreationErrorSignal.
-
-	CannotRepresentImageSignal := ImageSaveErrorSignal newSignalMayProceed:true.
-	CannotRepresentImageSignal nameClass:self message:#cannotRepresentImageSignal.
-
-	ImageLoadErrorSignal := QuerySignal new.
-	ImageLoadErrorSignal nameClass:self message:#imageLoadErrorSignal.
-
-	ImageNotFoundQuerySignal := QuerySignal new.
-	ImageNotFoundQuerySignal nameClass:self message:#imageNotFoundQuerySignal.
-	ImageNotFoundQuerySignal parent:ImageLoadErrorSignal.
-
-	InformationLostQuerySignal := QuerySignal new.
-	InformationLostQuerySignal nameClass:self message:#informationLostQuerySignal.
-	InformationLostQuerySignal parent:ImageLoadErrorSignal.
-
-	BadImageFormatQuerySignal := QuerySignal new.
-	BadImageFormatQuerySignal nameClass:self message:#badImageFormatQuerySignal.
-	BadImageFormatQuerySignal parent:ImageLoadErrorSignal.
-
-	UnrepresentableColorSignal := ImageErrorSignal newSignalMayProceed:true.
-	UnrepresentableColorSignal nameClass:self message:#unrepresentableColorSignal.
-    ]
-
-    "Modified: / 18.5.1999 / 15:50:03 / cg"
+        Lobby := Registry new.
+        ObjectMemory addDependent:self.
+
+        "/ define the algorithm to use for dithering -
+        "/ supported values are:
+        "/      #threshold
+        "/      #ordered
+        "/      #floydSteinberg
+        "/      #burkes
+
+        DitherAlgorithm := #floydSteinberg.
+
+        (Display notNil and:[Display hasGrayscales]) ifFalse:[
+            NumberOfDitherColors := 64
+        ] ifTrue:[
+            "as far as I remember, this is about the number of grey values, the eye can distinguish"
+            NumberOfDitherColors := 100
+        ].
+
+        "define reader classes"
+        self initializeFileFormatTable.
+        self initializeMIMETable.
+
+        CollectGarbageWhenRunningOutOfColors := false.
+
+        ImageErrorSignal := Error newSignalMayProceed:true.
+        ImageErrorSignal nameClass:self message:#imageErrorSignal.
+
+        ImageSaveErrorSignal := ImageErrorSignal newSignalMayProceed:true.
+        ImageSaveErrorSignal nameClass:self message:#imageSaveErrorSignal.
+
+        FileCreationErrorSignal := ImageSaveErrorSignal newSignalMayProceed:true.
+        FileCreationErrorSignal nameClass:self message:#fileCreationErrorSignal.
+
+        CannotRepresentImageSignal := ImageSaveErrorSignal newSignalMayProceed:true.
+        CannotRepresentImageSignal nameClass:self message:#cannotRepresentImageSignal.
+
+        ImageLoadErrorSignal := QuerySignal new.
+        ImageLoadErrorSignal nameClass:self message:#imageLoadErrorSignal.
+
+        ImageNotFoundQuerySignal := QuerySignal new.
+        ImageNotFoundQuerySignal nameClass:self message:#imageNotFoundQuerySignal.
+        ImageNotFoundQuerySignal parent:ImageLoadErrorSignal.
+
+        InformationLostQuerySignal := QuerySignal new.
+        InformationLostQuerySignal nameClass:self message:#informationLostQuerySignal.
+        InformationLostQuerySignal parent:ImageLoadErrorSignal.
+
+        BadImageFormatQuerySignal := QuerySignal new.
+        BadImageFormatQuerySignal nameClass:self message:#badImageFormatQuerySignal.
+        BadImageFormatQuerySignal parent:ImageLoadErrorSignal.
+
+        UnrepresentableColorSignal := ImageErrorSignal newSignalMayProceed:true.
+        UnrepresentableColorSignal nameClass:self message:#unrepresentableColorSignal.
+    ].
+    UninterpretedBytes isBigEndian ifTrue:[
+        ARGB_A_OFFSET_MACHINE := 1.
+        ARGB_R_OFFSET_MACHINE := 2.
+        ARGB_G_OFFSET_MACHINE := 3.
+        ARGB_B_OFFSET_MACHINE := 4.
+    ] ifFalse:[ 
+        ARGB_A_OFFSET_MACHINE := 4.
+        ARGB_R_OFFSET_MACHINE := 3.
+        ARGB_G_OFFSET_MACHINE := 2.
+        ARGB_B_OFFSET_MACHINE := 1.
+    ].
+
+    "Modified: / 18-05-1999 / 15:50:03 / cg"
+    "Modified: / 28-02-2016 / 14:36:23 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 initializeFileFormatTable
@@ -2608,19 +2621,11 @@
 !
 
 bitsARGB32Into: buffer startingAt: first stride: stride
-    | aOffset rOffset gOffset bOffset |
-
-    UninterpretedBytes isBigEndian ifTrue:[
-        aOffset := 1.
-        rOffset := 2.
-        gOffset := 3.
-        bOffset := 4.
-    ] ifFalse:[ 
-        aOffset := 4.
-        rOffset := 3.
-        gOffset := 2.
-        bOffset := 1.
-    ].
+    "Store each pixel is a 32-bit quantity, with alpha in the upper 
+     8 bits, then red, then green, then blue. The 32-bit quantities are 
+     stored native-endian. Pre-multiplied alpha is used. (That is, 50% 
+     transparent red is 0x80800000, not 0x80ff0000.)"
+
     mask isNil ifTrue:[ 
         0 to: height - 1 do:[:y |  
             | base |
@@ -2631,10 +2636,10 @@
                 offset := base + (x * 4).    
                 pixel := self pixelAtX: x y: y.
                 color := self colorFromValue: pixel.
-                buffer at: (offset + rOffset) put: color redByte.  
-                buffer at: (offset + gOffset) put: color greenByte.  
-                buffer at: (offset + bOffset) put: color blueByte.  
-                buffer at: (offset + aOffset) put: 16rFF.   
+                buffer at: (offset + ARGB_R_OFFSET_MACHINE) put: color redByte.  
+                buffer at: (offset + ARGB_G_OFFSET_MACHINE) put: color greenByte.  
+                buffer at: (offset + ARGB_B_OFFSET_MACHINE) put: color blueByte.  
+                buffer at: (offset + ARGB_A_OFFSET_MACHINE) put: 16rFF.   
             ]
         ]
     ] ifFalse:[ 
@@ -2650,15 +2655,15 @@
                 (mask pixelAtX: x y:y) ifTrue:[ 
                     pixel := self pixelAtX: x y: y.
                     color := self colorFromValue: pixel.
-                    buffer at: (offset + rOffset) put: color redByte.  
-                    buffer at: (offset + gOffset) put: color greenByte.  
-                    buffer at: (offset + bOffset) put: color blueByte.  
-                    buffer at: (offset + aOffset) put: 16rFF.
+                    buffer at: (offset + ARGB_R_OFFSET_MACHINE) put: color redByte.  
+                    buffer at: (offset + ARGB_G_OFFSET_MACHINE) put: color greenByte.  
+                    buffer at: (offset + ARGB_B_OFFSET_MACHINE) put: color blueByte.  
+                    buffer at: (offset + ARGB_A_OFFSET_MACHINE) put: 16rFF.
                 ] ifFalse:[ 
-                    buffer at: (offset + rOffset) put: 0.  
-                    buffer at: (offset + gOffset) put: 0.  
-                    buffer at: (offset + bOffset) put: 0.  
-                    buffer at: (offset + aOffset) put: 0.
+                    buffer at: (offset + ARGB_R_OFFSET_MACHINE) put: 0.  
+                    buffer at: (offset + ARGB_G_OFFSET_MACHINE) put: 0.  
+                    buffer at: (offset + ARGB_B_OFFSET_MACHINE) put: 0.  
+                    buffer at: (offset + ARGB_A_OFFSET_MACHINE) put: 0.
                 ].
             ]
         ]
@@ -2669,20 +2674,22 @@
 
             base := (first - 1) + (y * stride).
             0 to: width - 1 do:[:x |  
-                | pixel color offset |
+                | pixel color offset alpha |
 
                 offset := base + (x * 4).
                 pixel := self pixelAtX: x y: y.
                 color := self colorFromValue: pixel.
-                buffer at: (offset + rOffset) put: color redByte.  
-                buffer at: (offset + gOffset) put: color greenByte.  
-                buffer at: (offset + bOffset) put: color blueByte.  
-                buffer at: (offset + aOffset) put: (mask pixelAtX: x y:y)
+                alpha := mask pixelAtX: x y:y.
+                buffer at: (offset + ARGB_R_OFFSET_MACHINE) put: (color redByte * alpha) // 16rFF.  
+                buffer at: (offset + ARGB_G_OFFSET_MACHINE) put: (color greenByte * alpha) // 16rFF.  
+                buffer at: (offset + ARGB_B_OFFSET_MACHINE) put: (color blueByte * alpha) // 16rFF.  
+                buffer at: (offset + ARGB_A_OFFSET_MACHINE) put: alpha
             ]
         ]
     ]]].
 
     "Created: / 01-09-2015 / 17:16:59 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 28-02-2016 / 14:38:23 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 bitsPerSample