Depth8Image.st
changeset 151 8123ec03c52f
parent 134 1a09a1d7d28d
child 154 871a750ba914
equal deleted inserted replaced
150:5d0b9d669832 151:8123ec03c52f
    19 
    19 
    20 Depth8Image comment:'
    20 Depth8Image comment:'
    21 COPYRIGHT (c) 1993 by Claus Gittinger
    21 COPYRIGHT (c) 1993 by Claus Gittinger
    22 	      All Rights Reserved
    22 	      All Rights Reserved
    23 
    23 
    24 $Header: /cvs/stx/stx/libview/Depth8Image.st,v 1.21 1995-05-03 00:01:53 claus Exp $
    24 $Header: /cvs/stx/stx/libview/Depth8Image.st,v 1.22 1995-06-06 04:05:24 claus Exp $
    25 '!
    25 '!
    26 
    26 
    27 !Depth8Image class methodsFor:'documentation'!
    27 !Depth8Image class methodsFor:'documentation'!
    28 
    28 
    29 copyright
    29 copyright
    40 "
    40 "
    41 !
    41 !
    42 
    42 
    43 version
    43 version
    44 "
    44 "
    45 $Header: /cvs/stx/stx/libview/Depth8Image.st,v 1.21 1995-05-03 00:01:53 claus Exp $
    45 $Header: /cvs/stx/stx/libview/Depth8Image.st,v 1.22 1995-06-06 04:05:24 claus Exp $
    46 "
    46 "
    47 !
    47 !
    48 
    48 
    49 documentation
    49 documentation
    50 "
    50 "
   732 	    ]
   732 	    ]
   733 	]
   733 	]
   734     ].
   734     ].
   735     has8BitImage ifFalse:[^ nil].
   735     has8BitImage ifFalse:[^ nil].
   736 
   736 
   737     'D8IMAGE: dithering ...' errorPrintNL.
   737     'D8IMAGE: dithering ...' infoPrintNL.
   738 
   738 
   739     "
   739     "
   740      collect color components as integer values
   740      collect color components as integer values
   741      (code below uses components percent * 2.55 asInteger everywhere, to avoid
   741      (code below uses components percent * 2.55 asInteger everywhere, to avoid
   742       float arithmetic, rounding etc. Thus, the range is 0..255 here)
   742       float arithmetic, rounding etc. Thus, the range is 0..255 here)
   957     Color fixColors notNil ifTrue:[
   957     Color fixColors notNil ifTrue:[
   958 	f := self paletteImageAsDitheredPseudoFormOn:aDevice.
   958 	f := self paletteImageAsDitheredPseudoFormOn:aDevice.
   959 	f notNil ifTrue:[^ f].
   959 	f notNil ifTrue:[^ f].
   960     ].
   960     ].
   961 
   961 
   962     'D8IMAGE: allocating colors ...' errorPrintNL.
   962     'D8IMAGE: allocating colors ...' infoPrintNL.
   963 
   963 
   964     "find used colors"
   964     "find used colors"
   965 
   965 
   966     usedColors := bytes usedValues.         "gets us an array filled with used values"
   966     usedColors := bytes usedValues.         "gets us an array filled with used values"
   967 					   "(could use bytes asBag)"
   967 					   "(could use bytes asBag)"
  1019 			devColor := color exactOn:aDevice.
  1019 			devColor := color exactOn:aDevice.
  1020 			gcRound := 1
  1020 			gcRound := 1
  1021 		    ].
  1021 		    ].
  1022 		    devColor isNil ifTrue:[
  1022 		    devColor isNil ifTrue:[
  1023 			gcRound == 1 ifTrue:[
  1023 			gcRound == 1 ifTrue:[
  1024 			    'D8IMAGE: force GC for possible color reclamation.' errorPrintNL.
  1024 			    'D8IMAGE: force GC for possible color reclamation.' infoPrintNL.
  1025 			    ObjectMemory incrementalGC; finalize.
  1025 			    ObjectMemory incrementalGC; finalize.
  1026 			    devColor := color exactOn:aDevice.
  1026 			    devColor := color exactOn:aDevice.
  1027 			    gcRound := 2
  1027 			    gcRound := 2
  1028 			]
  1028 			]
  1029 		    ]
  1029 		    ]
  1084 				devColor := color nearestOn:aDevice error:error.
  1084 				devColor := color nearestOn:aDevice error:error.
  1085 				gcRound := 1
  1085 				gcRound := 1
  1086 			    ].
  1086 			    ].
  1087 			    devColor isNil ifTrue:[
  1087 			    devColor isNil ifTrue:[
  1088 				gcRound == 1 ifTrue:[
  1088 				gcRound == 1 ifTrue:[
  1089 				    'D8IMAGE: force GC for possible color reclamation.' errorPrintNL.
  1089 				    'D8IMAGE: force GC for possible color reclamation.' infoPrintNL.
  1090 				    ObjectMemory incrementalGC; finalize.
  1090 				    ObjectMemory incrementalGC; finalize.
  1091 				    devColor := color nearestOn:aDevice error:error.
  1091 				    devColor := color nearestOn:aDevice error:error.
  1092 				    gcRound := 2
  1092 				    gcRound := 2
  1093 				]
  1093 				]
  1094 			    ]
  1094 			    ]
  1105 	    error := error * 2.
  1105 	    error := error * 2.
  1106 	    error > 1000 ifTrue:[
  1106 	    error > 1000 ifTrue:[
  1107 		"
  1107 		"
  1108 		 break out, if the error becomes too big.
  1108 		 break out, if the error becomes too big.
  1109 		"
  1109 		"
  1110 		'D8IMAGE: hard color allocation problem - revert to b&w' errorPrintNL.
  1110 		'D8IMAGE: hard color allocation problem - revert to b&w' infoPrintNL.
  1111 		"
  1111 		"
  1112 		 map to b&w as a last fallback.
  1112 		 map to b&w as a last fallback.
  1113 		 (should really do a dither here)
  1113 		 (should really do a dither here)
  1114 		"
  1114 		"
  1115 		usedColors from:(lastOK+1) to:(usedColors size) do:[:aColorIndex |
  1115 		usedColors from:(lastOK+1) to:(usedColors size) do:[:aColorIndex |
  1127 		fit := true.
  1127 		fit := true.
  1128 	    ]
  1128 	    ]
  1129 	].
  1129 	].
  1130 
  1130 
  1131 	error > 100 ifTrue:[
  1131 	error > 100 ifTrue:[
  1132 	    'D8IMAGE: not enough colors for a reasonable image' errorPrintNL
  1132 	    'D8IMAGE: not enough colors for a reasonable image' infoPrintNL
  1133 	] ifFalse:[
  1133 	] ifFalse:[
  1134 	    'D8IMAGE: not enough colors for exact picture' errorPrintNL.
  1134 	    'D8IMAGE: not enough colors for exact picture' infoPrintNL.
  1135 	]
  1135 	]
  1136     ].
  1136     ].
  1137 
  1137 
  1138     "
  1138     "
  1139      create translation map (from image colors to allocated colorIds)
  1139      create translation map (from image colors to allocated colorIds)