Karl Ramberg uploaded a new version of MorphicExtras to project Etoys:
http://source.squeak.org/etoys/MorphicExtras-kfr.31.mcz ==================== Summary ==================== Name: MorphicExtras-kfr.31 Author: kfr Time: 10 October 2011, 9:14:34 pm UUID: 84611ed5-7bea-d046-a5f9-58f48d6ae7b9 Ancestors: MorphicExtras-kfr.30 Renamed CameraPlugin to CameraInterface =============== Diff against MorphicExtras-kfr.30 =============== Item was added: + Object subclass: #CameraInterface + instanceVariableNames: '' + classVariableNames: '' + poolDictionaries: '' + category: 'MorphicExtras-WebCam'! + + !CameraInterface commentStamp: '<historical>' prior: 0! + CameraInterface: Simple cross-platform webcam access interface from MIT Scratch. Small changes made so that different cameras can be tested when more than one is connected. The "CameraPlugin" binary should soon be included in the VM. On Linux the plugin is designed to take advantage of libv4l2 (if found) to support a wide range of cameras. + + Copyright (c) 2009 Massachusetts Institute of Technology + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ! Item was added: + ----- Method: CameraInterface class>>camera:getParam: (in category 'camera ops') ----- + camera: cameraNum getParam: paramNum + "Answer the given parameter for the given camera." + + <primitive: 'primGetParam' module: 'CameraPlugin'> + ^ nil + ! Item was added: + ----- Method: CameraInterface class>>cameraIsAvailable (in category 'camera ops') ----- + cameraIsAvailable + "Answer true if at least one camera is available." + + | enableCamera | + enableCamera := false. + ^ enableCamera and: [(self cameraName: 1) notNil] + ! Item was added: + ----- Method: CameraInterface class>>cameraIsOpen: (in category 'camera ops') ----- + cameraIsOpen: cameraNum + "Answer true if the camera is open." + + ^ (self packedFrameExtent: cameraNum) > 0 + ! Item was added: + ----- Method: CameraInterface class>>cameraName: (in category 'camera ops') ----- + cameraName: cameraNum + "Answer the name of the given camera. Answer nil if there is no camera with the given number." + + <primitive: 'primCameraName' module: 'CameraPlugin'> + ^ nil + ! Item was added: + ----- Method: CameraInterface class>>closeCamera: (in category 'camera ops') ----- + closeCamera: cameraNum + "Close the camera. Do nothing if it was not open." + + <primitive: 'primCloseCamera' module: 'CameraPlugin'> + ! Item was added: + ----- Method: CameraInterface class>>declareCVarsIn: (in category 'translation') ----- + declareCVarsIn: aCCodeGenerator + "self translate" + + super declareCVarsIn: aCCodeGenerator. + aCCodeGenerator cExtras: ' + #include "cameraOps.h" + #include <string.h> + '.! Item was added: + ----- Method: CameraInterface class>>frameExtent: (in category 'camera ops') ----- + frameExtent: cameraNum + "Answer the frame extent of the currently open camera, or zero if the camera isn't open." + + | packedExtent | + packedExtent := self packedFrameExtent: cameraNum. + ^ (packedExtent bitShift: -16) @ (packedExtent bitAnd: 16rFFFF) ! Item was added: + ----- Method: CameraInterface class>>getFrameForCamera:into: (in category 'camera ops') ----- + getFrameForCamera: cameraNum into: aBitmap + "Copy a camera frame into the given Bitmap. The Bitmap should be a Form of depth 32 that is the same width and height as the current camera frame. Fail if the camera is not open or if the bitmap is not the right size. If successful, answer the number of frames received from the camera since the last call. If this is zero, then there has been no change." + + <primitive: 'primGetFrame' module: 'CameraPlugin'> + ^ 0! Item was added: + ----- Method: CameraInterface class>>openCamera:width:height: (in category 'camera ops') ----- + openCamera: cameraNum width: frameWidth height: frameHeight + "Open the given camera requesting the given frame dimensions. The camera number is usually 1 since you typically have only one camera plugged in. If the camera does not support the exact frame dimensions, an available frame size with width >= the requested width is selected." + + <primitive: 'primOpenCamera' module: 'CameraPlugin'> + ^ nil + ! Item was added: + ----- Method: CameraInterface class>>packedFrameExtent: (in category 'camera ops') ----- + packedFrameExtent: cameraNum + "Answer the extent of the currently open camera packed in an integer. The top 16 bits are the width, the low 16 bits are the height. Answer zero if the camera isn't open." + + <primitive: 'primFrameExtent' module: 'CameraPlugin'> + ^ 0 + ! Item was added: + ----- Method: CameraInterface class>>videoTest: (in category 'test') ----- + videoTest: camNum + "A quick test of video input. Displays video on the screen until the mouse is pressed." + "self videoTest: 1" + "self videoTest: 2" + + | f n startTime frameCount msecs fps | + (CameraInterface openCamera: camNum width: 320 height: 240) ifNil: [^ self inform: 'no camera']. + self waitForCameraStart: camNum. + (self frameExtent: camNum) x = 0 ifTrue: [^ self inform: 'no camera']. + f := Form extent: (CameraInterface frameExtent: camNum) depth: 32. + frameCount := 0. + startTime := nil. + [Sensor anyButtonPressed] whileFalse: [ + n := CameraInterface getFrameForCamera: camNum into: f bits. + n > 0 ifTrue: [ + startTime ifNil: [startTime := Time millisecondClockValue]. + frameCount := frameCount + 1. + f display]]. + Sensor waitNoButton. + msecs := Time millisecondClockValue - startTime. + CameraInterface closeCamera: camNum. + fps := (frameCount * 1000) // msecs. + ^ frameCount printString, ' frames at ', fps printString, ' frames/sec'! Item was added: + ----- Method: CameraInterface class>>waitForCameraStart: (in category 'camera ops') ----- + waitForCameraStart: camNum + "Wait for the camera to get it's first frame (indicated by a non-zero frame extent. Timeout after a few seconds." + "self waitForCameraStart" + + | startTime | + startTime := Time millisecondClockValue. + [(Time millisecondClockValue - startTime) < 2000] whileTrue: [ + (self packedFrameExtent: camNum) > 0 ifTrue: [^ self]. + (Delay forMilliseconds: 50) wait].! Item was added: + ----- Method: CameraInterface>>primCameraName (in category 'primitives') ----- + primCameraName + "Get the name for the camera with the given number. Fail if the camera number is greater than the number of available cameras." + + | cameraNum nameStr count resultOop dst | + self export: true. + self var: 'nameStr' declareC: 'char* nameStr'. + self var: 'dst' declareC: 'char* dst'. + + cameraNum := interpreterProxy stackIntegerValue: 0. + interpreterProxy failed ifTrue: [^ 0]. + + nameStr := self cCode: 'CameraName(cameraNum)'. + nameStr = nil ifTrue: [ + interpreterProxy success: false. + ^ 0]. + + count := self cCode: '(int) strlen(nameStr)'. + resultOop := interpreterProxy instantiateClass: interpreterProxy classString indexableSize: count. + dst := self cCoerce: (interpreterProxy firstIndexableField: resultOop) to: 'char *'. + 0 to: count - 1 do: [:i | dst at: i put: (nameStr at: i)]. + + interpreterProxy pop: 2 thenPush: resultOop. "pop arg and rcvr, push result" + ^ 0 + ! Item was added: + ----- Method: CameraInterface>>primCloseCamera (in category 'primitives') ----- + primCloseCamera + "Close the camera. Do nothing if it was not open." + + | cameraNum | + self export: true. + cameraNum := interpreterProxy stackIntegerValue: 0. + interpreterProxy failed ifTrue: [^ 0]. + + self cCode: 'CameraClose(cameraNum)'. + + interpreterProxy pop: 1. "pop arg, leave rcvr on stack" + ^ 0 + ! Item was added: + ----- Method: CameraInterface>>primFrameExtent (in category 'primitives') ----- + primFrameExtent + "Answer the frame extent of the given camera, or zero if the camera is not open. The extent is 16 bits of width and height packed into a single integer." + + | cameraNum e | + self export: true. + cameraNum := interpreterProxy stackIntegerValue: 0. + interpreterProxy failed ifTrue: [^ 0]. + + e := self cCode: 'CameraExtent(cameraNum)'. + + interpreterProxy pop: 2 thenPush: (interpreterProxy integerObjectOf: e). "pop rcvr & arg, push int result" + ^ 0 + ! Item was added: + ----- Method: CameraInterface>>primGetFrame (in category 'primitives') ----- + primGetFrame + "Copy a camera frame into the given Bitmap. The Bitmap should be for a Form of depth 32 that is the same width and height as the current camera frame. Fail if the camera is not open or if the bitmap is not the right size. If successful, answer the number of frames received from the camera since the last call. If this is zero, then there has been no change." + + | cameraNum bitmapOop bitmap pixCount result | + self export: true. + self var: 'bitmap' declareC: 'unsigned char *bitmap'. + + cameraNum := interpreterProxy stackIntegerValue: 1. + bitmapOop := interpreterProxy stackValue: 0. + ((interpreterProxy isIntegerObject: bitmapOop) or: + [(interpreterProxy isWords: bitmapOop) not]) ifTrue: [ + interpreterProxy success: false. + ^ 0]. + bitmap := self cCoerce: (interpreterProxy firstIndexableField: bitmapOop) to: 'unsigned char *'. + pixCount := interpreterProxy stSizeOf: bitmapOop. + + result := self cCode: 'CameraGetFrame(cameraNum, bitmap, pixCount)'. + result < 0 ifTrue: [ + interpreterProxy success: false. + ^ 0]. + + interpreterProxy pop: 3 thenPush: (interpreterProxy integerObjectOf: result). "pop rcvr & args, push int result" + ^ 0 + + ! Item was added: + ----- Method: CameraInterface>>primGetParam (in category 'primitives') ----- + primGetParam + "Answer the given integer parameter of the given camera." + + | cameraNum paramNum result | + self export: true. + cameraNum := interpreterProxy stackIntegerValue: 1. + paramNum := interpreterProxy stackIntegerValue: 0. + interpreterProxy failed ifTrue: [^ 0]. + + result := self cCode: 'CameraGetParam(cameraNum, paramNum)'. + + interpreterProxy pop: 3 thenPush: (interpreterProxy integerObjectOf: result). "pop rcvr & args, push int result" + ^ 0 + ! Item was added: + ----- Method: CameraInterface>>primOpenCamera (in category 'primitives') ----- + primOpenCamera + "Open a camera. Takes one argument, the index of the device to open." + + | cameraNum desiredFrameWidth desiredFrameHeight ok | + self export: true. + + cameraNum := interpreterProxy stackIntegerValue: 2. + desiredFrameWidth := interpreterProxy stackIntegerValue: 1. + desiredFrameHeight := interpreterProxy stackIntegerValue: 0. + interpreterProxy failed ifTrue: [^ 0]. + + ok := self cCode: 'CameraOpen(cameraNum, desiredFrameWidth, desiredFrameHeight)'. + ok = 0 ifTrue: [ + interpreterProxy success: false. + ^ 0]. + + interpreterProxy pop: 3. "pop args, leave rcvr on stack" + ^ 0 + ! Item was removed: - Object subclass: #CameraPlugin - instanceVariableNames: '' - classVariableNames: '' - poolDictionaries: '' - category: 'MorphicExtras-WebCam'! - - !CameraPlugin commentStamp: '<historical>' prior: 0! - CameraPlugin: Simple cross-platform webcam access interface from MIT Scratch. Small changes made so that different cameras can be tested when more than one is connected. The "CameraPlugin" binary should soon be included in the VM. On Linux the plugin is designed to take advantage of libv4l2 (if found) to support a wide range of cameras. - - Copyright (c) 2009 Massachusetts Institute of Technology - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. - ! Item was removed: - ----- Method: CameraPlugin class>>camera:getParam: (in category 'camera ops') ----- - camera: cameraNum getParam: paramNum - "Answer the given parameter for the given camera." - - <primitive: 'primGetParam' module: 'CameraPlugin'> - ^ nil - ! Item was removed: - ----- Method: CameraPlugin class>>cameraIsAvailable (in category 'camera ops') ----- - cameraIsAvailable - "Answer true if at least one camera is available." - - | enableCamera | - enableCamera := false. - ^ enableCamera and: [(self cameraName: 1) notNil] - ! Item was removed: - ----- Method: CameraPlugin class>>cameraIsOpen: (in category 'camera ops') ----- - cameraIsOpen: cameraNum - "Answer true if the camera is open." - - ^ (self packedFrameExtent: cameraNum) > 0 - ! Item was removed: - ----- Method: CameraPlugin class>>cameraName: (in category 'camera ops') ----- - cameraName: cameraNum - "Answer the name of the given camera. Answer nil if there is no camera with the given number." - - <primitive: 'primCameraName' module: 'CameraPlugin'> - ^ nil - ! Item was removed: - ----- Method: CameraPlugin class>>closeCamera: (in category 'camera ops') ----- - closeCamera: cameraNum - "Close the camera. Do nothing if it was not open." - - <primitive: 'primCloseCamera' module: 'CameraPlugin'> - ! Item was removed: - ----- Method: CameraPlugin class>>declareCVarsIn: (in category 'translation') ----- - declareCVarsIn: aCCodeGenerator - "self translate" - - super declareCVarsIn: aCCodeGenerator. - aCCodeGenerator cExtras: ' - #include "cameraOps.h" - #include <string.h> - '.! Item was removed: - ----- Method: CameraPlugin class>>frameExtent: (in category 'camera ops') ----- - frameExtent: cameraNum - "Answer the frame extent of the currently open camera, or zero if the camera isn't open." - - | packedExtent | - packedExtent := self packedFrameExtent: cameraNum. - ^ (packedExtent bitShift: -16) @ (packedExtent bitAnd: 16rFFFF) ! Item was removed: - ----- Method: CameraPlugin class>>getFrameForCamera:into: (in category 'camera ops') ----- - getFrameForCamera: cameraNum into: aBitmap - "Copy a camera frame into the given Bitmap. The Bitmap should be a Form of depth 32 that is the same width and height as the current camera frame. Fail if the camera is not open or if the bitmap is not the right size. If successful, answer the number of frames received from the camera since the last call. If this is zero, then there has been no change." - - <primitive: 'primGetFrame' module: 'CameraPlugin'> - ^ 0! Item was removed: - ----- Method: CameraPlugin class>>openCamera:width:height: (in category 'camera ops') ----- - openCamera: cameraNum width: frameWidth height: frameHeight - "Open the given camera requesting the given frame dimensions. The camera number is usually 1 since you typically have only one camera plugged in. If the camera does not support the exact frame dimensions, an available frame size with width >= the requested width is selected." - - <primitive: 'primOpenCamera' module: 'CameraPlugin'> - ^ nil - ! Item was removed: - ----- Method: CameraPlugin class>>packedFrameExtent: (in category 'camera ops') ----- - packedFrameExtent: cameraNum - "Answer the extent of the currently open camera packed in an integer. The top 16 bits are the width, the low 16 bits are the height. Answer zero if the camera isn't open." - - <primitive: 'primFrameExtent' module: 'CameraPlugin'> - ^ 0 - ! Item was removed: - ----- Method: CameraPlugin class>>videoTest: (in category 'test') ----- - videoTest: camNum - "A quick test of video input. Displays video on the screen until the mouse is pressed." - "self videoTest: 1" - "self videoTest: 2" - - | f n startTime frameCount msecs fps | - (CameraPlugin openCamera: camNum width: 320 height: 240) ifNil: [^ self inform: 'no camera']. - self waitForCameraStart: camNum. - (self frameExtent: camNum) x = 0 ifTrue: [^ self inform: 'no camera']. - f := Form extent: (CameraPlugin frameExtent: camNum) depth: 32. - frameCount := 0. - startTime := nil. - [Sensor anyButtonPressed] whileFalse: [ - n := CameraPlugin getFrameForCamera: camNum into: f bits. - n > 0 ifTrue: [ - startTime ifNil: [startTime := Time millisecondClockValue]. - frameCount := frameCount + 1. - f display]]. - Sensor waitNoButton. - msecs := Time millisecondClockValue - startTime. - CameraPlugin closeCamera: camNum. - fps := (frameCount * 1000) // msecs. - ^ frameCount printString, ' frames at ', fps printString, ' frames/sec'! Item was removed: - ----- Method: CameraPlugin class>>waitForCameraStart: (in category 'camera ops') ----- - waitForCameraStart: camNum - "Wait for the camera to get it's first frame (indicated by a non-zero frame extent. Timeout after a few seconds." - "self waitForCameraStart" - - | startTime | - startTime := Time millisecondClockValue. - [(Time millisecondClockValue - startTime) < 2000] whileTrue: [ - (self packedFrameExtent: camNum) > 0 ifTrue: [^ self]. - (Delay forMilliseconds: 50) wait].! Item was removed: - ----- Method: CameraPlugin>>primCameraName (in category 'primitives') ----- - primCameraName - "Get the name for the camera with the given number. Fail if the camera number is greater than the number of available cameras." - - | cameraNum nameStr count resultOop dst | - self export: true. - self var: 'nameStr' declareC: 'char* nameStr'. - self var: 'dst' declareC: 'char* dst'. - - cameraNum := interpreterProxy stackIntegerValue: 0. - interpreterProxy failed ifTrue: [^ 0]. - - nameStr := self cCode: 'CameraName(cameraNum)'. - nameStr = nil ifTrue: [ - interpreterProxy success: false. - ^ 0]. - - count := self cCode: '(int) strlen(nameStr)'. - resultOop := interpreterProxy instantiateClass: interpreterProxy classString indexableSize: count. - dst := self cCoerce: (interpreterProxy firstIndexableField: resultOop) to: 'char *'. - 0 to: count - 1 do: [:i | dst at: i put: (nameStr at: i)]. - - interpreterProxy pop: 2 thenPush: resultOop. "pop arg and rcvr, push result" - ^ 0 - ! Item was removed: - ----- Method: CameraPlugin>>primCloseCamera (in category 'primitives') ----- - primCloseCamera - "Close the camera. Do nothing if it was not open." - - | cameraNum | - self export: true. - cameraNum := interpreterProxy stackIntegerValue: 0. - interpreterProxy failed ifTrue: [^ 0]. - - self cCode: 'CameraClose(cameraNum)'. - - interpreterProxy pop: 1. "pop arg, leave rcvr on stack" - ^ 0 - ! Item was removed: - ----- Method: CameraPlugin>>primFrameExtent (in category 'primitives') ----- - primFrameExtent - "Answer the frame extent of the given camera, or zero if the camera is not open. The extent is 16 bits of width and height packed into a single integer." - - | cameraNum e | - self export: true. - cameraNum := interpreterProxy stackIntegerValue: 0. - interpreterProxy failed ifTrue: [^ 0]. - - e := self cCode: 'CameraExtent(cameraNum)'. - - interpreterProxy pop: 2 thenPush: (interpreterProxy integerObjectOf: e). "pop rcvr & arg, push int result" - ^ 0 - ! Item was removed: - ----- Method: CameraPlugin>>primGetFrame (in category 'primitives') ----- - primGetFrame - "Copy a camera frame into the given Bitmap. The Bitmap should be for a Form of depth 32 that is the same width and height as the current camera frame. Fail if the camera is not open or if the bitmap is not the right size. If successful, answer the number of frames received from the camera since the last call. If this is zero, then there has been no change." - - | cameraNum bitmapOop bitmap pixCount result | - self export: true. - self var: 'bitmap' declareC: 'unsigned char *bitmap'. - - cameraNum := interpreterProxy stackIntegerValue: 1. - bitmapOop := interpreterProxy stackValue: 0. - ((interpreterProxy isIntegerObject: bitmapOop) or: - [(interpreterProxy isWords: bitmapOop) not]) ifTrue: [ - interpreterProxy success: false. - ^ 0]. - bitmap := self cCoerce: (interpreterProxy firstIndexableField: bitmapOop) to: 'unsigned char *'. - pixCount := interpreterProxy stSizeOf: bitmapOop. - - result := self cCode: 'CameraGetFrame(cameraNum, bitmap, pixCount)'. - result < 0 ifTrue: [ - interpreterProxy success: false. - ^ 0]. - - interpreterProxy pop: 3 thenPush: (interpreterProxy integerObjectOf: result). "pop rcvr & args, push int result" - ^ 0 - - ! Item was removed: - ----- Method: CameraPlugin>>primGetParam (in category 'primitives') ----- - primGetParam - "Answer the given integer parameter of the given camera." - - | cameraNum paramNum result | - self export: true. - cameraNum := interpreterProxy stackIntegerValue: 1. - paramNum := interpreterProxy stackIntegerValue: 0. - interpreterProxy failed ifTrue: [^ 0]. - - result := self cCode: 'CameraGetParam(cameraNum, paramNum)'. - - interpreterProxy pop: 3 thenPush: (interpreterProxy integerObjectOf: result). "pop rcvr & args, push int result" - ^ 0 - ! Item was removed: - ----- Method: CameraPlugin>>primOpenCamera (in category 'primitives') ----- - primOpenCamera - "Open a camera. Takes one argument, the index of the device to open." - - | cameraNum desiredFrameWidth desiredFrameHeight ok | - self export: true. - - cameraNum := interpreterProxy stackIntegerValue: 2. - desiredFrameWidth := interpreterProxy stackIntegerValue: 1. - desiredFrameHeight := interpreterProxy stackIntegerValue: 0. - interpreterProxy failed ifTrue: [^ 0]. - - ok := self cCode: 'CameraOpen(cameraNum, desiredFrameWidth, desiredFrameHeight)'. - ok = 0 ifTrue: [ - interpreterProxy success: false. - ^ 0]. - - interpreterProxy pop: 3. "pop args, leave rcvr on stack" - ^ 0 - ! Item was changed: ----- Method: WebCamMorph>>captureFrameAutoMode: (in category 'private') ----- captureFrameAutoMode: autoMode | wasOn gotFrame nFrames | captureForm bits class == ByteArray ifTrue: [captureForm unhibernate]. ">>>>>>>>>>>>>>>>>>>>>>>>>>" "STEPPING TRIGGERED CAPTURE >>>" autoMode ifTrue: [ manualCapture ifTrue: [^ nil]. self getWebCamIsOn ifFalse: [^ nil]. captureDelayMs := (captureDelayMs - 1) max: minCaptureDelayMs. + (CameraInterface getFrameForCamera: camNum into: captureForm bits) > 0 - (CameraPlugin getFrameForCamera: camNum into: captureForm bits) > 0 ifFalse: [ captureDelayMs := (captureDelayMs + 2) min: 500. ^ nil. ]. self captureStubWithFx: true withDisplayUpdate: true. ^ captureForm. ]. ">>>>>>>>>>>>>>>>>>>>>>>>>>" "MANUAL/SCRIPT TRIGGERED CAPTURE >>>" (wasOn := camIsOn) ifTrue: [ manualCapture ifFalse: [^ nil]. ]. (self on) ifFalse: [^ nil]. gotFrame := false. nFrames := skipFrames + 1. [nFrames > 0] whileTrue: [ + (CameraInterface getFrameForCamera: camNum into: captureForm bits) > 0 - (CameraPlugin getFrameForCamera: camNum into: captureForm bits) > 0 ifTrue: [gotFrame := gotFrame | true]. nFrames := nFrames - 1. ]. gotFrame ifFalse: [^ nil]. self captureStubWithFx: false withDisplayUpdate: false. wasOn ifFalse: [self off]. ^ captureForm. ! Item was changed: ----- Method: WebCamMorph>>off (in category 'accessing') ----- off + CameraInterface closeCamera: camNum. - CameraPlugin closeCamera: camNum. camIsOn := false. ! Item was changed: ----- Method: WebCamMorph>>on (in category 'accessing') ----- on camIsOn ifTrue: [^ true]. "Avoid more than one WebCamMorph per Camera" + (CameraInterface cameraIsOpen: camNum) ifTrue: [^ false]. - (CameraPlugin cameraIsOpen: camNum) ifTrue: [^ false]. + (CameraInterface openCamera: camNum - (CameraPlugin openCamera: camNum width: (frameExtent x) height: (frameExtent y) ) ifNil: [^ false]. (Delay forSeconds: startupDelay) wait. + frameExtent := CameraInterface frameExtent: camNum. + captureForm := Form extent: (CameraInterface frameExtent: camNum) depth: 32. - frameExtent := CameraPlugin frameExtent: camNum. - captureForm := Form extent: (CameraPlugin frameExtent: camNum) depth: 32. self resetFrameCount. lastTime := nil. captureDelayMs := 20. camIsOn := true. lastCaptureTime := Time millisecondClockValue. self startStepping. ^ true ! _______________________________________________ etoys-dev mailing list [hidden email] http://lists.squeakland.org/mailman/listinfo/etoys-dev |
Free forum by Nabble | Edit this page |