W3C

Mediastream Image Capture

W3C Editor's Draft 15 February 2013

This version:
http://gmandyam.github.com/image-capture
Latest published version:
http://www.w3.org/TR/picture-settings/
Latest editor's draft:
http://gmandyam.github.com/image-capture
Editor:
Giridhar Mandyam, Qualcomm Innovation Center, Inc

Abstract

This document specific the takePhoto() method and corresponding camera settings or use with MediaStreams as defined in Media Capture and Streams [GETUSERMEDIA].

Status of This Document

This section describes the status of this document at the time of its publication. Other documents may supersede this document. A list of current W3C publications and the latest revision of this technical report can be found in the W3C technical reports index at http://www.w3.org/TR/.

Comments on this document are welcomed.

This document was published by the Media Capture Task Force as an Editor's Draft. If you wish to make comments regarding this document, please send them to public-media-capture@w3.org (subscribe, archives). All feedback is welcome.

Publication as an Editor's Draft does not imply endorsement by the W3C Membership. This is a draft document and may be updated, replaced or obsoleted by other documents at any time. It is inappropriate to cite this document as other than work in progress.

This document was produced by a group operating under the 5 February 2004 W3C Patent Policy. W3C maintains a public list of any patent disclosures made in connection with the deliverables of the group; that page also includes instructions for disclosing a patent. An individual who has actual knowledge of a patent which the individual believes contains Essential Claim(s) must disclose the information in accordance with section 6 of the W3C Patent Policy.

Table of Contents

1. Introduction

The API defined in this document taks a valid MediaStream and returns an encoded image in the form of a Blob (as defined in [FILE-API]). The image is provided by the capture device that provides the MediaStream. Moreover, picture-specific settings can be optionally provided as arguments that can be applied to the image being captured.

2. Image Capture API

interface ImageCapture : EventTarget {
    readonly attribute PhotoSettingsOptions photoSettingsOptions;
             attribute MediaStream          stream;
             attribute EventHandler         onphoto;
             attribute EventHandler         onphotoerror;
             attribute EventHandler         onphotosettingschange;
             attribute EventHandler         onphotosettingserror;
    void setPhotoSettings (PhotoSettings photoSettings);
    void takePhoto (optional DOMString trackID);
};

2.1 Attributes

onphoto of type EventHandler
Register/unregister for photo events. The handler should expect to get a PhotoEvent object as its first parameter.
onphotoerror of type EventHandler
Register/unregister for photo error events. The handler should expect to get a PhotoError object as its first parameter.
onphotosettingschange of type EventHandler
Register/unregister for photo settings change events.
onphotosettingserror of type EventHandler
Register/unregister for photo settings error events.
photoSettingsOptions of type PhotoSettingsOptions, readonly
Describes current photo settings
stream of type MediaStream
The MediaStream passed into the constructor

2.2 Methods

setPhotoSettings
When the setPhotoSettings() method of an ImageCapture object is invoked, then then a valid PhotoSettings object must be passed in the method to the UA. If the UA can successfully apply the settings, then the UA must invoke the onphotosettingschange (if specified). If the UA cannot successfully apply the settings, then the UA must invoke the onphotosettingserror event handler (if specified).
ParameterTypeNullableOptionalDescription
photoSettingsPhotoSettings
Return type: void
takePhoto
When the takePhoto() method of an ImageCapture object is invoked, then if a trackID is provided and it is not the id of a Track object in stream's videoTrackList whose readyState is "live", the UA must invoke the onphotoerror event handler (if specified) with a new PhotoError object whose code is set to INVALID_TRACK_ID. If a trackID is not provided then the UA may select a default track in the stream to apply the takePhoto() method. If the UA is unable to select a track, then the UA must invoke the onphotoerror event handler (if specified) with a new PhotoError object whose code is set to PHOTO_ERROR. Otherwise it must queue a task, using the DOM manipulation task source, that runs the following steps:
  1. Gather data from the Track into a Blob containing a single still image. The method of doing this will depend on the underlying device. Some devices may just do a frame grab, while others may temporarily stop streaming data, reconfigure themselves with the appropriate photo settings, take the photo, and then resume streaming. In this case, the stopping and restarting of streaming should cause mute and unmute events to fire on the Track in question.
  2. Raise a PhotoEvent event containing the Blob.
ParameterTypeNullableOptionalDescription
trackIDDOMString
Return type: void

3. PhotoEvent

interface PhotoEvent : Event {
    readonly attribute Blob data;
};

3.1 Attributes

data of type Blob, readonly
Returns a Blob object whose type attribute indicates the encoding of the blob data. An implementation must return a Blob in a format that is capable of being viewed in an HTML <img> tag.

4. MediaSettingsRange

interface MediaSettingsRange {
    readonly attribute unsigned long max;
    readonly attribute unsigned long min;
    readonly attribute unsigned long initial;
};

4.1 Attributes

initial of type unsigned long, readonly
The current value of this setting
max of type unsigned long, readonly
The maximum value of this setting
min of type unsigned long, readonly
The minimum value of this setting

5. MediaSettingsItem

The MediaSettingsItem interface is now defined, which allows for a single setting to be managed.

interface MediaSettingsItem {
    readonly attribute any value;
};

5.1 Attributes

value of type any, readonly
Value of current setting.

6. PhotoSettingsOptions

The PhotoSettingsOptions attribute of the ImageCapture object provides the photo-specific settings options and current settings values.

interface PhotoSettingsOptions {
             attribute MediaSettingsItem  whiteBalanceMode;
             attribute MediaSettingsItem  autoExposureMode;
             attribute MediaSettingsRange exposureCompensation;
             attribute MediaSettingsRange iso;
             attribute MediaSettingsItem  redEyeReduction;
             attribute MediaSettingsRange brightness;
             attribute MediaSettingsRange constrast;
             attribute MediaSettingsRange saturation;
             attribute MediaSettingsRange sharpness;
             attribute MediaSettingsRange imageHeight;
             attribute MediaSettingsRange imageWidth;
};

6.1 Attributes

autoExposureMode of type MediaSettingsItem
This reflects the current auto exposure mode setting. Values are of type ExposureModeEnum.
brightness of type MediaSettingsRange
This reflects the current brightness setting of the camera and permitted range. Values are numeric.
constrast of type MediaSettingsRange
This reflects the current contrast setting of the camera and permitted range. Values are numeric.
exposureCompensation of type MediaSettingsRange
This reflects the current exposure compensation setting and permitted range. Values are numeric.
imageHeight of type MediaSettingsRange
This reflects the image height range supported by the UA and the current height setting.
imageWidth of type MediaSettingsRange
This reflects the image width range supported by the UA and the current width setting.
iso of type MediaSettingsRange
This reflects the current camera ISO setting and permitted range. Values are numeric.
redEyeReduction of type MediaSettingsItem
This reflects whether camera red eye reduction is on or off, and is boolean - on is true
saturation of type MediaSettingsRange
This reflects the current saturation setting of the camera and permitted range. Values are numeric.
sharpness of type MediaSettingsRange
This reflects the current sharpness setting of the camera and permitted range. Values are numeric.
whiteBalanceMode of type MediaSettingsItem
This reflects the current white balance mode setting. Values are of type WhiteBalanceModeEnum.

7. WhiteBalanceModeEnum

enum WhiteBalanceModeEnum {
    "auto",
    "incandescent",
    "fluorescent",
    "warm-fluorescent",
    "daylight",
    "cloudy-daylight",
    "twilight",
    "shade"
};
Enumeration description
autoauto
incandescent2500-3500 Kelvin
fluorescent4000-5000 Kelvin
warm-fluorescent5000-5500 Kelvin
daylight5000-6500 Kelvin
cloudy-daylight6500-8000 Kelvin
twilight8000-9000 Kelvin
shade9000-10000 Kelvin

8. ExposureModeEnum

enum ExposureModeEnum {
    "frame-average",
    "center-weighted",
    "spot-metering"
};
Enumeration description
frame-averageAverage of light information from entire scene
center-weightedSensitivity concentrated towards center of viewfinder
spot-meteringSpot-centered weighting

9. PhotoSettings

The PhotoSettings object is optionally passed into the ImageCapture.setPhotoSettings() method in order to modify capture device settings specific to still imagery. Each of the attributes in this object are optional.

interface PhotoSettings {
             attribute any           whiteBalanceModeSetting;
             attribute any           autoExposureModeSetting;
             attribute unsigned long exposureCompensationSetting;
             attribute unsigned long isoSetting;
             attribute boolean       redEyeReductionSetting;
             attribute unsigned long brightnessSetting;
             attribute unsigned long constrastSetting;
             attribute unsigned long saturationSetting;
             attribute unsigned long sharpnessSetting;
             attribute unsigned long imageHeightSetting;
             attribute unsigned long imageWidthSetting;
};

9.1 Attributes

autoExposureModeSetting of type any
This reflects the desired auto exposure mode setting. Acceptable values are of type ExposureModeEnum.
brightnessSetting of type unsigned long
This reflects the desired brightness setting of the camera.
constrastSetting of type unsigned long
This reflects the desired contrast setting of the camera.
exposureCompensationSetting of type unsigned long
This reflects the desired exposure compensation setting.
imageHeightSetting of type unsigned long
This reflects the desired image height. The UA must select the closest height value this setting if it supports a discrete set of height options.
imageWidthSetting of type unsigned long
This reflects the desired image width. The UA must select the closest width value this setting if it supports a discrete set of width options.
isoSetting of type unsigned long
This reflects the desired camera ISO setting.
redEyeReductionSetting of type boolean
This reflects whether camera red eye reduction is desired
saturationSetting of type unsigned long
This reflects the desired saturation setting of the camera.
sharpnessSetting of type unsigned long
This reflects the desired sharpness setting of the camera.
whiteBalanceModeSetting of type any
This reflects the desired white balance mode setting. Acceptable values are of type WhiteBalanceModeEnum.

10. PhotoError

The PhotoError object is passed to an onphotoerror event handler of an ImageCapture object if an error occurred when the takePhoto() method was invoked.

interface PhotoError {
    readonly attribute unsigned short code;
    const unsigned short PHOTO_ERROR = 0;
    const unsigned short DEVICE_UNAVAILABLE = 1;
};

10.1 Attributes

code of type unsigned short, readonly
Returns appropriate error code derived from list of pre-defined constants

10.2 Constants

DEVICE_UNAVAILABLE of type unsigned short
value of code for when image capture device is unavailable
PHOTO_ERROR of type unsigned short
value of code for when an error occurred while capturing the image

11. Example: Taking a picture if Red Eye Reduction is activated

Example 1
navigator.getUserMedia({video: true}, gotMedia, failedToGetMedia);

function gotMedia(mediastream) {
   var videoDevice = mediastream.videoTracks[0];
   // Check if this device supports a picture mode...
   var pictureDevice = new ImageCapture();
   if (pictureDevice) {
         pictureDevice.onphoto = showPicture;
         if (pictureDevice.photoSettingsOptions.redEyeReduction) {
            pictureDevice.setPhotoSettings({redEyeReductionSetting:true});
            }
         else
            console.log('No red eye reduction');
         pictureDevice.onphotosettingschange = function(){
            currentRedEye = new Boolean;
            currentRedEye = false;
            if (pictureDevice.photoSettingsOptions.redEyeReduction)
                currentRedEye = pictureDevice.photoSettingsOptions.redEyeReduction.value;
            if (currentRedEye == true)
                pictureDevice.takePhoto();
            }
         }
     }

 function showPicture(e) {
    var img = document.querySelector("img");
    img.src = URL.createObjectURL(e.data);
    }

 function failedToGetMedia{
    console.log('Stream failure');
    }

A. References

A.1 Normative references

[FILE-API]
Arun Ranganathan; Jonas Sicking. File API. 20 October 2011. W3C Working Draft. (Work in progress.) URL: http://www.w3.org/TR/2011/WD-FileAPI-20111020/
[GETUSERMEDIA]
D. Burnett, A. Narayanan. getusermedia: Getting access to local devices that can generate multimedia streams 22 December 2011. W3C Editors draft (Work in progress.) URL: http://dev.w3.org/2011/webrtc/editor/getusermedia.html