Image.st
branchjv
changeset 7366 18c5cd709f5c
parent 7365 05f5fe42c919
parent 7363 778803c164cd
child 7377 3d54f2920bff
--- a/Image.st	Wed May 11 09:38:32 2016 +0200
+++ b/Image.st	Thu May 12 09:17:05 2016 +0200
@@ -3628,18 +3628,20 @@
      instances or by image readers. Calling for a change of an
      existing image may confuse later pixel interpretation."
 
-    "/ the following is a trick to get shared Immutable instances, at least for the
-    "/ most common cases. Prevents writers to do what is described above.
-    "/ Just an experiment...
-    aCollection = #( 8 8 8 ) ifTrue:[
-        bitsPerSample := #( 8 8 8 )
-    ] ifFalse:[
-        aCollection = #( 8 ) ifTrue:[
-            bitsPerSample := #( 8 )
-        ] ifFalse:[
-            bitsPerSample := aCollection
-        ].
-    ].
+    "/ the following is a trick to get both shared and immutable instances, 
+    "/ at least for the most common cases. 
+    "/ Prevents writers to do what is described above.
+    "/ Do not remove, as you might not understand it!!
+    bitsPerSample := 
+        #(
+            #[ 8 8 8 ]
+            #[ 4 4 4 ]
+            #[ 8 ]
+            #[ 4 ]
+            #[ 2 ]
+            #[ 1 ]
+        ) detect:[:bps | bps sameContentsAs:aCollection] ifNone:[aCollection asByteArray].    
+
     samplesPerPixel isNil ifTrue:[
         samplesPerPixel := bitsPerSample size.
     ].