Image.st
changeset 401 f163a93a0987
parent 399 0b6e43843204
child 518 f76da6242336
equal deleted inserted replaced
400:47fa508fd78b 401:f163a93a0987
   583 
   583 
   584     |display|
   584     |display|
   585 
   585 
   586     display := Screen current.
   586     display := Screen current.
   587     ^ self fromScreen:(0@0 corner:(display width @ display height))
   587     ^ self fromScreen:(0@0 corner:(display width @ display height))
       
   588 
       
   589     "
       
   590      Image fromScreen
       
   591     "
   588 !
   592 !
   589 
   593 
   590 fromScreen:aRectangle
   594 fromScreen:aRectangle
   591     "return an image of a part of the screen"
   595     "return an image of a part of the screen"
   592 
   596 
   593     ^ self fromScreen:aRectangle on:Screen current 
   597     ^ self fromScreen:aRectangle on:Screen current 
   594 
   598 
   595     "Image fromScreen:(0@0 corner:100@100)"
   599     "
       
   600      Image fromScreen:(0@0 corner:100@100)
       
   601     "
   596 !
   602 !
   597 
   603 
   598 fromScreen:aRectangle on:aDisplay
   604 fromScreen:aRectangle on:aDisplay
   599     "return an image of a part of the screen, which may be on
   605     "return an image of a part of the screen, which may be on
   600      another Display."
   606      another Display."
   601 
   607 
   602     |depth img|
   608     |depth vis img|
   603 
   609 
   604     depth := aDisplay depth.
   610     depth := aDisplay depth.
       
   611 
       
   612     "/
       
   613     "/ for truecolor displays, return a Depth24Image
       
   614     "/ (must do this for depth15 & depth16 displays, since
       
   615     "/  Depth16Image has no way to specify r/g/b masks ...)
       
   616     "/
       
   617     vis := aDisplay visualType.
       
   618     (vis == #TrueColor or:[vis == #DirectColor]) ifTrue:[
       
   619 	depth > 8 ifTrue:[
       
   620 	    depth := 24.
       
   621 	]
       
   622     ].
       
   623 
   605     img := (self implementorForDepth: depth) new.
   624     img := (self implementorForDepth: depth) new.
   606     ^ img fromScreen:aRectangle on:aDisplay
   625     ^ img fromScreen:aRectangle on:aDisplay
   607 
   626 
   608     "Image fromScreen:(0@0 corner:100@100)"
   627     "
       
   628      Image fromScreen:(0@0 corner:100@100)
       
   629     "
   609 !
   630 !
   610 
   631 
   611 fromScreenArea
   632 fromScreenArea
   612     "return an image of a part of the screen; 
   633     "return an image of a part of the screen; 
   613      let user specify screen area."
   634      let user specify screen area."
   614 
   635 
   615     ^ self fromScreen:(Rectangle fromUser)
   636     ^ self fromScreen:(Rectangle fromUser)
   616 
   637 
   617     "Image fromScreenArea"
   638     "
       
   639      Image fromScreenArea
       
   640     "
   618 !
   641 !
   619 
   642 
   620 fromUser
   643 fromUser
   621     "return an image of a part of the screen; let user specify screen area.
   644     "return an image of a part of the screen; let user specify screen area.
   622      Same as fromScreenArea, for ST-80 compatibility"
   645      Same as fromScreenArea, for ST-80 compatibility"
   623 
   646 
   624     ^ self fromScreenArea
   647     ^ self fromScreenArea
   625 
   648 
   626     "Image fromUser"
   649     "
       
   650      Image fromUser
       
   651     "
   627 !
   652 !
   628 
   653 
   629 fromView:aView
   654 fromView:aView
   630     "return an image taken from a views contents as currently
   655     "return an image taken from a views contents as currently
   631      on the screen. The returned image has the same depth and photometric
   656      on the screen. The returned image has the same depth and photometric
   640 			 from:(aView id)
   665 			 from:(aView id)
   641 			   to:dev rootWindowId "(DisplayRootView on:dev) id".
   666 			   to:dev rootWindowId "(DisplayRootView on:dev) id".
   642     ^ self fromScreen:(org extent:aView extent) on:dev
   667     ^ self fromScreen:(org extent:aView extent) on:dev
   643 
   668 
   644     "
   669     "
   645      Image fromView:(Launcher allInstances first topView)
   670      Image fromView:(NewLauncher allInstances first topView)
   646      Image fromView:(SystemBrowser allInstances first topView)
   671      Image fromView:(SystemBrowser allInstances first topView)
   647     "
   672     "
   648 ! !
   673 ! !
   649 
   674 
   650 !Image methodsFor:'accessing'!
   675 !Image methodsFor:'accessing'!
  3088      maskG "{ Class: SmallInteger }"
  3113      maskG "{ Class: SmallInteger }"
  3089      maskB "{ Class: SmallInteger }"
  3114      maskB "{ Class: SmallInteger }"
  3090      shR "{ Class: SmallInteger }"
  3115      shR "{ Class: SmallInteger }"
  3091      shG "{ Class: SmallInteger }"
  3116      shG "{ Class: SmallInteger }"
  3092      shB "{ Class: SmallInteger }"
  3117      shB "{ Class: SmallInteger }"
       
  3118      shR2 "{ Class: SmallInteger }"
       
  3119      shG2 "{ Class: SmallInteger }"
       
  3120      shB2 "{ Class: SmallInteger }"
  3093      r "{ Class: SmallInteger }"
  3121      r "{ Class: SmallInteger }"
  3094      g "{ Class: SmallInteger }"
  3122      g "{ Class: SmallInteger }"
  3095      b "{ Class: SmallInteger }"
  3123      b "{ Class: SmallInteger }"
  3096      word|
  3124      word|
  3097 
  3125 
  3130 	    bitsPerSample := Array with:bitsPerPixel.
  3158 	    bitsPerSample := Array with:bitsPerPixel.
  3131 	] ifFalse:[
  3159 	] ifFalse:[
  3132 	    ((visType == #TrueColor) or:[visType == #DirectColor]) ifTrue:[
  3160 	    ((visType == #TrueColor) or:[visType == #DirectColor]) ifTrue:[
  3133 		photometric := #rgb.
  3161 		photometric := #rgb.
  3134 		samplesPerPixel := 3.
  3162 		samplesPerPixel := 3.
  3135 		bitsPerPixel := depth.
  3163 "/                bitsPerPixel := depth.
  3136 		bitsPerSample := Array with:aDevice bitsRed
  3164 "/                bitsPerSample := Array with:aDevice bitsRed
  3137 				       with:aDevice bitsGreen
  3165 "/                                       with:aDevice bitsGreen
  3138 				       with:aDevice bitsBlue
  3166 "/                                       with:aDevice bitsBlue
       
  3167 		bitsPerPixel := 24.
       
  3168 		bitsPerSample := #(8 8 8).
  3139 	    ] ifFalse:[
  3169 	    ] ifFalse:[
  3140 		self error:'screen visual not supported'.
  3170 		self error:'screen visual not supported'.
  3141 		^ nil
  3171 		^ nil
  3142 	    ]
  3172 	    ]
  3143 	]
  3173 	]
  3215 	srcRow := 1.
  3245 	srcRow := 1.
  3216 	dstRow := 1.
  3246 	dstRow := 1.
  3217 
  3247 
  3218 	bitsPerPixelIn ~~ bitsPerPixel ifTrue:[
  3248 	bitsPerPixelIn ~~ bitsPerPixel ifTrue:[
  3219 	    "/ for now, only 32 -> 24 is supported
  3249 	    "/ for now, only 32 -> 24 is supported
  3220 	    ((bitsPerPixelIn ~~ 32)
  3250 
  3221 	    or:[bitsPerPixel ~~ 24]) ifTrue:[
  3251 	    maskR := (1 bitShift:aDevice bitsRed) - 1.
  3222 		'unsupported depth combination' errorPrintNL.
  3252 	    maskG := (1 bitShift:aDevice bitsGreen) - 1.
  3223 		^ nil
  3253 	    maskB := (1 bitShift:aDevice bitsBlue) - 1.
       
  3254 	    shR := aDevice shiftRed negated.
       
  3255 	    shG := aDevice shiftGreen negated.
       
  3256 	    shB := aDevice shiftBlue negated.
       
  3257 	    shR2 := (8 - aDevice bitsRed).
       
  3258 	    shG2 := (8 - aDevice bitsGreen).
       
  3259 	    shB2 := (8 - aDevice bitsBlue).
       
  3260 
       
  3261 	    ((bitsPerPixelIn == 32) and:[bitsPerPixel == 24]) ifTrue:[
       
  3262 		"/ 'reformatting 32->24...' printNL.
       
  3263 		1 to:h do:[:hi |
       
  3264 		    srcIndex := srcRow.
       
  3265 		    dstIndex := dstRow.
       
  3266 
       
  3267 		    1 to:w do:[:wi |
       
  3268 			word := tmpData doubleWordAt:srcIndex MSB:true.
       
  3269 			r := (word bitShift:shR) bitAnd:maskR.
       
  3270 			g := (word bitShift:shG) bitAnd:maskG.
       
  3271 			b := (word bitShift:shB) bitAnd:maskB.
       
  3272 
       
  3273 			inData at:dstIndex   put:r.
       
  3274 			inData at:dstIndex+1 put:g.
       
  3275 			inData at:dstIndex+2 put:b.
       
  3276 			srcIndex := srcIndex + 4.
       
  3277 			dstIndex := dstIndex + 3.
       
  3278 		    ].
       
  3279 		    dstRow := dstRow + bytesPerLine.
       
  3280 		    srcRow := srcRow + bytesPerLineIn
       
  3281 		]
       
  3282 	    ] ifFalse:[
       
  3283 		((bitsPerPixelIn == 16) and:[bitsPerPixel == 24]) ifTrue:[
       
  3284 		    "/ 'reformatting 16->24...' printNL.
       
  3285 		    1 to:h do:[:hi |
       
  3286 			srcIndex := srcRow.
       
  3287 			dstIndex := dstRow.
       
  3288 
       
  3289 			1 to:w do:[:wi |
       
  3290 			    word := tmpData wordAt:srcIndex MSB:true.
       
  3291 			    r := (word bitShift:shR) bitAnd:maskR.
       
  3292 			    g := (word bitShift:shG) bitAnd:maskG.
       
  3293 			    b := (word bitShift:shB) bitAnd:maskB.
       
  3294 
       
  3295 			    inData at:dstIndex   put:(r bitShift:shR2).
       
  3296 			    inData at:dstIndex+1 put:(g bitShift:shG2).
       
  3297 			    inData at:dstIndex+2 put:(b bitShift:shB2).
       
  3298 			    srcIndex := srcIndex + 2.
       
  3299 			    dstIndex := dstIndex + 3.
       
  3300 			].
       
  3301 			dstRow := dstRow + bytesPerLine.
       
  3302 			srcRow := srcRow + bytesPerLineIn
       
  3303 		    ]
       
  3304 		] ifFalse:[
       
  3305 		    ('unsupported depth combination: ' , bitsPerPixelIn printString , ' -> ' ,
       
  3306 							bitsPerPixel printString) errorPrintNL.
       
  3307 		    ^ nil
       
  3308 		]
  3224 	    ].
  3309 	    ].
  3225 
       
  3226 	    'reformatting ...' printNL.
       
  3227 	    1 to:h do:[:hi |
       
  3228 		srcIndex := srcRow.
       
  3229 		dstIndex := dstRow.
       
  3230 		maskR := (1 bitShift:aDevice bitsRed) - 1.
       
  3231 		maskG := (1 bitShift:aDevice bitsGreen) - 1.
       
  3232 		maskB := (1 bitShift:aDevice bitsBlue) - 1.
       
  3233 		shR := aDevice shiftRed negated.
       
  3234 		shG := aDevice shiftGreen negated.
       
  3235 		shB := aDevice shiftBlue negated.
       
  3236 
       
  3237 		1 to:w do:[:wi |
       
  3238 		    word := tmpData doubleWordAt:srcIndex MSB:true.
       
  3239 		    r := (word bitShift:shR) bitAnd:maskR.
       
  3240 		    g := (word bitShift:shG) bitAnd:maskG.
       
  3241 		    b := (word bitShift:shB) bitAnd:maskB.
       
  3242 
       
  3243 		    inData at:dstIndex   put:r.
       
  3244 		    inData at:dstIndex+1 put:g.
       
  3245 		    inData at:dstIndex+2 put:b.
       
  3246 		    srcIndex := srcIndex + 4.
       
  3247 		    dstIndex := dstIndex + 3.
       
  3248 		].
       
  3249 		dstRow := dstRow + bytesPerLine.
       
  3250 		srcRow := srcRow + bytesPerLineIn
       
  3251 	    ]
       
  3252 	] ifFalse:[
  3310 	] ifFalse:[
  3253 	    "
  3311 	    "
  3254 	     repad in the buffer
  3312 	     repad in the buffer
  3255 	    "
  3313 	    "
  3256 	    1 to:h do:[:hi |
  3314 	    1 to:h do:[:hi |
  3302 
  3360 
  3303     "
  3361     "
  3304      (Image new) fromScreen:((0 @ 0) corner:(100 @ 100)) on:Display
  3362      (Image new) fromScreen:((0 @ 0) corner:(100 @ 100)) on:Display
  3305      (Image new) fromScreen:((0 @ 0) corner:(500 @ 500)) on:Display
  3363      (Image new) fromScreen:((0 @ 0) corner:(500 @ 500)) on:Display
  3306     "
  3364     "
       
  3365 
       
  3366     "Modified: 5.2.1996 / 01:10:48 / cg"
  3307 ! !
  3367 ! !
  3308 
  3368 
  3309 !Image class methodsFor:'documentation'!
  3369 !Image class methodsFor:'documentation'!
  3310 
  3370 
  3311 version
  3371 version
  3312     ^ '$Header: /cvs/stx/stx/libview/Image.st,v 1.59 1996-02-04 17:13:46 cg Exp $'! !
  3372     ^ '$Header: /cvs/stx/stx/libview/Image.st,v 1.60 1996-02-05 00:48:12 cg Exp $'! !
  3313 Image initialize!
  3373 Image initialize!