[etoys-dev] Etoys: CameraPlugin-kfr.5.mcz

Bert Freudenberg bert at freudenbergs.de
Mon Oct 10 05:44:12 EDT 2011


Okay. We should still rename it. CameraInterface for example. Otherwise, we could not load the real plugin class into the same image. For the same reason, we should remove the instance-side methods. They only make sense if this was a subclass of InterpreterPlugin.

- Bert -

On 10.10.2011, at 10:57, karl ramberg wrote:

> I changed CameraPlugin to be subclass of Object. InterpreterPlugin is
> not in the image.
> Added in category MorphicExtras-WebCam
> 
> Karl
> 
> On Sat, Oct 8, 2011 at 1:53 PM, Bert Freudenberg <bert at freudenbergs.de> wrote:
>> No. We only need the class-side methods. (you should be suspicious about anything deriving from ProtoObject - this needs to be an InterpreterPlugin subclass)
>> 
>> We should move the methods we need to another object. Maybe just the morph?
>> 
>> And instead of adding a new package for WebCamMorph I'd rather add it to MorphicExtras-Camera. Possibly name it simply CameraMorph?
>> 
>> - Bert -
>> 
>> On 08.10.2011, at 13:03, karl ramberg wrote:
>> 
>>> yes :-)
>>> 
>>> On Sat, Oct 8, 2011 at 12:43 PM, karl ramberg <karlramberg at gmail.com> wrote:
>>>> Hm
>>>> Is this needed???
>>>> 
>>>> 
>>>> 
>>>> On Sat, Oct 8, 2011 at 12:39 PM,  <commits at source.squeak.org> wrote:
>>>>> Karl Ramberg uploaded a new version of CameraPlugin to project Etoys:
>>>>> http://source.squeak.org/etoys/CameraPlugin-kfr.5.mcz
>>>>> 
>>>>> ==================== Summary ====================
>>>>> 
>>>>> Name: CameraPlugin-kfr.5
>>>>> Author: kfr
>>>>> Time: 8 October 2011, 12:39:38 pm
>>>>> UUID: 427b0466-d1c0-0c46-b523-15df30a8c4eb
>>>>> Ancestors: CameraPlugin-dmoc.4
>>>>> 
>>>>> Add CameraPlugin to Etoys
>>>>> 
>>>>> ==================== Snapshot ====================
>>>>> 
>>>>> SystemOrganization addCategory: #CameraPlugin!
>>>>> 
>>>>> ProtoObject subclass: #CameraPlugin
>>>>>        instanceVariableNames: ''
>>>>>        classVariableNames: ''
>>>>>        poolDictionaries: ''
>>>>>        category: 'CameraPlugin'!
>>>>> 
>>>>> !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.
>>>>> !
>>>>> 
>>>>> ----- 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
>>>>> !
>>>>> 
>>>>> ----- 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]
>>>>> !
>>>>> 
>>>>> ----- Method: CameraPlugin class>>cameraIsOpen: (in category 'camera ops') -----
>>>>> cameraIsOpen: cameraNum
>>>>>        "Answer true if the camera is open."
>>>>> 
>>>>>        ^ (self packedFrameExtent: cameraNum) > 0
>>>>> !
>>>>> 
>>>>> ----- 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
>>>>> !
>>>>> 
>>>>> ----- Method: CameraPlugin class>>closeCamera: (in category 'camera ops') -----
>>>>> closeCamera: cameraNum
>>>>>        "Close the camera. Do nothing if it was not open."
>>>>> 
>>>>>        <primitive: 'primCloseCamera' module: 'CameraPlugin'>
>>>>> !
>>>>> 
>>>>> ----- Method: CameraPlugin class>>declareCVarsIn: (in category 'translation') -----
>>>>> declareCVarsIn: aCCodeGenerator
>>>>>        "self translate"
>>>>> 
>>>>>        super declareCVarsIn: aCCodeGenerator.
>>>>>        aCCodeGenerator cExtras: '
>>>>> #include "cameraOps.h"
>>>>> #include <string.h>
>>>>> '.!
>>>>> 
>>>>> ----- 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) !
>>>>> 
>>>>> ----- 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!
>>>>> 
>>>>> ----- 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
>>>>> !
>>>>> 
>>>>> ----- 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
>>>>> !
>>>>> 
>>>>> ----- 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'!
>>>>> 
>>>>> ----- 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].!
>>>>> 
>>>>> ----- 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
>>>>> !
>>>>> 
>>>>> ----- 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
>>>>> !
>>>>> 
>>>>> ----- 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
>>>>> !
>>>>> 
>>>>> ----- 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
>>>>> 
>>>>> !
>>>>> 
>>>>> ----- 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
>>>>> !
>>>>> 
>>>>> ----- 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
>>>>> !
>>>>> 
>>>>> _______________________________________________
>>>>> etoys-dev mailing list
>>>>> etoys-dev at squeakland.org
>>>>> http://lists.squeakland.org/mailman/listinfo/etoys-dev
>>>>> 
>>>> 
>>> _______________________________________________
>>> etoys-dev mailing list
>>> etoys-dev at squeakland.org
>>> http://lists.squeakland.org/mailman/listinfo/etoys-dev
>> 
>> 
>> 



More information about the etoys-dev mailing list