forked from w3c/mediacapture-worker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
1555 lines (1482 loc) · 61.2 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html>
<head>
<title>Media Capture Stream with Worker</title>
<meta charset='utf-8'>
<script src='https://www.w3.org/Tools/respec/respec-w3c-common'
async class='remove'></script>
<script class='remove'>
var respecConfig = {
// specification status (e.g. WD, LCWD, WG-NOTE, etc.). If in doubt use ED.
specStatus: "ED",
// the specification's short name, as in http://www.w3.org/TR/short-name/
shortName: "mediacapture-worker",
// if your specification has a subtitle that goes below the main
// formal title, define it here
// subtitle : "an excellent document",
// if you wish the publication date to be other than the last modification, set this
// publishDate: "2009-08-06",
// if the specification's copyright date is a range of years, specify
// the start date here:
// copyrightStart: "2005"
// if there is a previously published draft, uncomment this and set its YYYY-MM-DD date
// and its maturity status
// previousPublishDate: "1977-03-15",
// previousMaturity: "WD",
// if there a publicly available Editor's Draft, this is the link
edDraftURI: "https://w3c.github.io/mediacapture-worker/",
// if this is a LCWD, uncomment and set the end of its review period
// lcEnd: "2009-08-05",
// editors, add as many as you like
// only "name" is required
editors: [
{
name: "Chia-hung Tai"
// , url: "http://example.org/"
, mailto: "ctai@mozilla.com"
, company: "Mozilla"
, companyURL: "https://www.mozilla.org/en-US/foundation/moco/"
},
{
name: "Robert O'Callahan"
// , url: "http://example.org/"
, company: "Mozilla"
, companyURL: "https://www.mozilla.org/en-US/foundation/moco/"
},
{
name: "Tzuhao Kuo"
// , url: "http://example.org/"
, mailto: "tkuo@mozilla.com"
, company: "Mozilla"
, companyURL: "https://www.mozilla.org/en-US/foundation/moco/"
},
{
name: "Anssi Kostiainen",
company: "Intel",
companyURL: "http://www.intel.com/"
},
],
// name of the WG
wg: [
"Web Real-Time Communication Working Group",
"Device APIs Working Group"
],
// URI of the public WG page
wgURI: [ "http://www.w3.org/2011/04/webrtc/",
"http://www.w3.org/2009/dap/"
],
// name (without the @w3c.org) of the public mailing to which comments are due
wgPublicList: "public-media-capture",
// URI of the patent status for this WG, for Rec-track documents
// !!!! IMPORTANT !!!!
// This is important for Rec-track documents, do not copy a patent URI from a random
// document unless you know what you're doing. If in doubt ask your friendly neighbourhood
// Team Contact.
wgPatentURI: "",
// !!!! IMPORTANT !!!! MAKE THE ABOVE BLINK IN YOUR HEAD
};
</script>
</head>
<body>
<section id='abstract'>
<p>
This specification extends the <em>Media Capture and Streams</em>
specification [[!GETUSERMEDIA]] to allow JavaScript developers to
process video frame data in workers on the web applications.
</p>
</section>
<section id='sotd'>
<p><strong>
This document is not complete and is subject to change. Early
experimentations are encouraged to allow the Media Capture Task Force
to evolve the specification based on technical discussions within the
Task Force, implementation experience gained from early
implementations, and feedback from other groups and
individuals.
</strong></p>
<p><strong>
This specification is started in the Media Capture Task Force to get it
under way in anticipation of the <a href=
"http://www.w3.org/2015/07/timed-media-wg.html">Timed Media Working
Group</a> creation. The intention is to transfer this specification to
the Timed Media Working Group when the group is formed.
</strong></p>
<p><strong>
This specification will use the <a href=
"http://www.w3.org/Consortium/Legal/2015/copyright-software-and-document.html">
W3C Software and Document license</a> to be consistent with the
<a href="http://www.w3.org/2015/07/timed-media-wg.html#licensing">
licensing terms</a> of the proposed Timed Media Working Group.
</strong></p>
</section>
<section>
<h2>Introduction</h2>
<p>
The <em>Media Capture and Streams</em> specification provides a way to
access to the video camera. But how to process the video frame data in
JavaScript is not covered. By associating a worker with
<a><code>MediaStreamTrack</code></a>s
(<code>MediaStreamTrack.kind</code> must be "video"), the framework can
dispatch a
<a><code>VideoMonitorEvent</code></a>/<a><code>VideoProcessorEvent</code></a>
to the worker frame by frame. Then JavaScript developer can write a
video processing script which enables processing, analyzing of video
data directly using JavaScript in a Worker thread.
</p>
<p>
<img alt= "The relationship between Worker and MediaStreamTrack"
src= "images/Worker - FLOW.png" style="width:60%">
</p>
<p>
The design principle of this specification is to provide a push-like
mechanism for video processing. This design gives the Web developers no
worry about any platform capability to full utilize the CPU usage. The
Web developer no longer need to decide the FPS rate to grab the input
video frame. The User Agent only dispatch the
<a><code>VideoMonitorEvent</code></a>/<a><code>VideoProcessorEvent</code></a>
when a new video frame arriving.
</p>
</section>
<section>
<h2>Use cases and requirements</h2>
<p>
This specification attempts to address the
<a href="https://wiki.mozilla.org/Project_FoxEye#Use_Cases">Use Cases
and Requirements </a>for expanding the Web potentials to image
processing and computer vision area.
</p>
</section>
<section>
<h2>Conformance</h2>
<p>
This specification defines conformance criteria that apply to a single
product: the <dfn>user agent</dfn> that implements the interfaces that
it contains.
</p>
<p>
Implementations that use ECMAScript to implement the APIs defined in
this specification must implement them in a manner consistent with the
ECMAScript Bindings defined in the Web IDL specification [[!WEBIDL]],
as this specification uses that specification and terminology.
</p>
<p>
The key words "MUST", "MUST NOT", "REQUIRED", "SHOULD", "SHOULD NOT",
"RECOMMENDED", "MAY", and "OPTIONAL" in the normative parts of this
document are to be interpreted as described in RFC2119. For readability,
these words do not appear in all uppercase letters in this
specification. [[!RFC2119]]
</p>
</section>
<section>
<h2>Dependencies</h2>
<p>
The <code><a href=
"http://w3c.github.io/mediacapture-main/getusermedia.html#idl-def-MediaStreamTrack">
<dfn>MediaStreamTrack</dfn></a></code> and <code><a href=
"http://w3c.github.io/mediacapture-main/getusermedia.html#idl-def-MediaStream">
<dfn>MediaStream</dfn></a></code> interfaces this specification extends
are defined in [[!GETUSERMEDIA]].
</p>
<p>
The <code><a href=
"http://www.w3.org/TR/html51/webappapis.html#imagebitmap">
<dfn>ImageBitmap</dfn></a></code> interface
and <code><a href=
"http://www.w3.org/TR/html51/webappapis.html#imagebitmapfactories">
<dfn>ImageBitmapFactories</dfn></a></code> interface this specification
extends are defined in [[!HTML51]].
</p>
<p>
The <code><a href=
"http://www.w3.org/TR/WebIDL-1/#common-BufferSource">
<dfn>BufferSource</dfn></a></code> is defined in [[!WebIDL]]
</p>
</section>
<section>
<h2>Extensions</h2>
<section>
<h2>
<code>DedicatedWorkerGlobalScope</code> interface
</h2>
<p>
By extending <code>DedicatedWorkerGlobalScope</code> object
with a event handler, <code>onvideoprocess</code>, it is
enabled the generating, processing, and analyzing of video data
directly using JavaScript in a Worker thread.
</p>
<p>
The <code><a>DedicatedWorkerGlobalScope</a></code> is the "inside" of a
<code>Worker</code>. It must not exist if the interface's
relevant namespace object is not a
<code><a>DedicatedWorkerGlobalScope</a></code> object.
</p>
<dl class="idl" title="partial interface DedicatedWorkerGlobalScope">
<dt>
attribute EventHandler onvideoprocess
</dt>
<dd>
<p>
A property used to set the EventHandler (described in [[!HTML]])
for the <a><code>VideoMonitorEvent</code></a>/
<a><code>VideoProcessorEvent</code></a> that is dispatched
to <code><a>DedicatedWorkerGlobalScope</a></code> to process video
while the associated <code><a>MediaStreamTrack</a></code> are
connected. When a new input video frame is sent to corresponding
<code>MediaStreamTrack</code>, User Agent will create a
<code><a>VideoProcessEventThe</a></code> and dispatch it. Then the event
handler, of type <code><a>videoprocess</a></code>,
is executed .
</p>
</dd>
</dl>
</section>
<section>
<h2>
<code id = event-videomonitorevent>VideoMonitorEvent</code> interface
</h2>
<p>
This is an <code>Event</code> object which is dispatched to
<a><code>DedicatedWorkerGlobalScope</code></a> objects to perform
processing.
</p>
<p>
When the <code>MediaStreamTrack</code> comes a new video frame data,
the User Agent will dispatch a <code><a>VideoMonitorEvent</a></code> to the
associated Workers when the association is connected by
<code>addVideoMonitor</code>. The event handlers of those Workers
process video from the input by accessing the video data from the
<code>inputImageBitmap</code> attribute in the
<code>VideoMonitorEvent</code>.
</p>
<p>
Ideally the <code>MediaStreamTrack</code> should dispatch each
video frame through <code><a>VideoMonitorEvent</a></code>. But sometimes the
worker thread could not process the frame in time. So the
implementation could skip the frame to avoid high memory footprint.
In such case, we might not be able to process every frame in a real
time <code>MediaStream</code>.
</p>
<dl class="idl" data-merge="VideoMonitorEventInit"
title="[Exposed=Worker] interface VideoMonitorEvent : Event">
<dt>
Constructor(DOMString type, VideoMonitorEventInit eventInitDict)
</dt>
<dd>
Constructs a new VideoMonitorEvent.
</dd>
<dt>
readonly attribute DOMString trackId
</dt>
<dd>
The <code>MediaStreamTrack.id</code> of corresponding
<code>MediaStreamTrack</code>.
</dd>
<dt>
readonly attribute double playbackTime
</dt>
<dd>
The elapsed time of the <code>MediaStreamTrack</code> from the
<code>MediaStream</code> starting.
</dd>
<dt>
readonly attribute ImageBitmap inputImageBitmap
</dt>
<dd>
The input video frame comes from the corresponding
<code>MediaStreamTrack</code>.
</dd>
</dl>
<dl class="idl" title="dictionary VideoMonitorEventInit : EventInit">
<dt>required DOMString trackId</dt>
<dt>required double playbackTime</dt>
<dt>required ImageBitmap inputImageBitmap</dt>
</dl>
</section>
<section>
<h2>
<code id = event-videoprocessorevent>VideoProcessorEvent</code> interface
</h2>
<p>
This event is inherited from <code><a>VideoMonitorEvent</a></code>.
When the <code>MediaStreamTrack</code> comes a new video frame data,
the User Agent will dispatch a <code>VideoProcessorEvent</code> to the
associated Workers when the association is connected by
<code>addVideoProcessor</code>. The event handlers of those Workers
process video from the input by accessing the video data from the
<code>inputImageBitmap</code> attribute in the
<code>VideoProcessorEvent</code>. The processed video data which is
the result of the processing is then placed into the
<code>outputImageBitmap</code>. The User Agent will append the
<code>outputImageBitmap</code> into the new created
<code>MediaStreamTrack</code>.
</p>
<p>
Ideally the <code>MediaStreamTrack</code> should dispatch each
video frame through <a>VideoProcessorEvent</a>. But sometimes the
worker thread could not process the frame in time. So the
implementation could skip the frame to avoid high memory footprint.
In such case, we might not be able to process every frame in a real
time <code>MediaStream</code>.
</p>
<dl class="idl" data-merge="VideoProcessorEventInit"
title="[Exposed=Worker] interface VideoProcessorEvent : VideoMonitorEvent">
<dt>
Constructor(DOMString type, VideoProcessorEventInit eventInitDict)
</dt>
<dd>
Constructs a new VideoProcessorEvent.
</dd>
<dt>
attribute ImageBitmap? outputImageBitmap
</dt>
<dd>
The output video frame comes to the corresponding
<code>MediaStreamTrack</code>. It is default to be null. The Web
developer need to create a new <code>ImageBitmap</code> for output
frame and assign it to <code>outputImageBitmap</code>.
</dd>
</dl>
<dl class="idl" title="dictionary VideoProcessorEventInit : VideoMonitorEventInit">
<dt>ImageBitmap? outputImageBitmap</dt>
</dl>
</section>
<section>
<h2>
<code>MediaStreamTrack</code> interface
</h2>
<dl class="idl" title="partial interface MediaStreamTrack">
<dt>
void addVideoMonitor(Worker worker)
</dt>
<dd>
Associate the <code>worker</code> with the <code>MediaStreamTrack</code>.
You can add the same <code>worker</code> to any other
<code>MediaStreamTrack</code>.
</dd>
<dt>
void removeVideoMonitor(Worker worker)
</dt>
<dd>
Remove a particular <code>Worker</code> from the
<code>MediaStreamTrack</code>. User Agent should throw exception
when the <code>Worker</code> is not exist in the
<code>MediaStreamTrack</code>.
</dd>
<dt>
MediaStreamTrack addVideoProcessor(Worker worker)
</dt>
<dd>
This method will create a new <code>MediaStreamTrack</code> and
take the original <code>MediaStreamTrack</code> as the input
source. Then associate the <code>Worker</code> with new created
<code>MediaStreamTrack</code>. The developers can build a
processed pipeline by this method.
</dd>
<dt>
void removeVideoProcessor()
</dt>
<dd>
Remove the added <code>Worker</code> from current
<code>MediaStreamTrack</code>. User Agent should throw exception
when the <code>Worker</code> is not exist in the
<code>MediaStreamTrack</code>. A <code>MediaStreamTrack</code>
owns at most one Worker processor in any time.
</dd>
</dl>
</section>
</section>
<section id='imagebitmap-extensions'>
<h2>ImageBitmap extensions</h2>
<div class="note">
<p>
The <a>ImageBitmap</a> interface is originally designed as
a pure opaque handler to an image data buffer inside a browser so that
how the browser stores the buffer is uknown to users and optimized to
platforms. In this specification, we chooses <a>ImageBitmap</a>
(instead of <code>ImageData</code>) as the container of video frames
because the decoded video frame data might exist in either CPU or GPU
memory which perfectly matches the nature of
<a><code>ImageBitmap</code></a> as an opaque handler.
</p>
</div>
<p>
Considering how would developers process video frames, there are two
possible approaches, via pure JavaScript(/asm.js) code or via WebGL.
<ol>
<li>
If developers use JavaScript(/asm.js) to process the frames, then
the <a>ImageBitmap</a> interface needs to be extended with APIs for
developers to access its underlying data and there should also be a
way for developers to create an <a>ImageBitmap</a> from the
processed data.
</li>
<li>
If developers use WebGL, then WebGL needs to be extended so that
developers can pass an <a>ImageBitmap</a> into the WebGL context and
the browser will handle how to upload the raw image data into the
GPU memory. Possiblely, the data is already in the GPU memory so
that the operation could be very efficient.
</li>
</ol>
</p>
<p>
In this specification, the original <a>ImageBitmap</a> interface is
extended with three methods to let developers read data from an
<a>ImageBitmap</a> object into a given <a>BufferSource</a> in a set of
supported <a>ImageFormat</a>s and two interfaces,
<a>ImageFormatPixelLayout</a> and <a>ChannelPixelLayout</a>, are
proposed to work with the extend <a>ImageBitmap</a> methods to describe
how the accessed image data is arranged in memory. Also,
the <a>ImageBitmapFactories</a> interface is extended to let developers
create an <a>ImageBitmap</a> object from a given <a>BufferSource</a>.
</p>
<section id='imageformat'>
<h2>ImageFormat</h2>
<p>
An image or a video frame is conceptually a two-dimentional array of
data and each element in the array is called a <dfn>pixel</dfn>.
However, the pixels are usually stored in a one-dimentional array and
could be arranged in a variety of <a>ImageFormat</a>s.
Developers need to know how the pixels are formatted so that they are
able to process it.
An <a>ImageFormat</a> describes how pixels in an image are arranged
and all pixels in one single image are arranged in the same way.
A single pixel has at least one, but usually multiple
<dfn>pixel value</dfn>s.
The range of a pixel value varies, which means different
<a>ImageFormat</a>s use different <dfn>data type</dfn>s to store a
single pixel value.
The most frequently used data type is 8-bit unsigned interger whose
range is from 0 to 255, others could be 16-bit interger or 32-bit
folating points and so forth.
The number of pixle values of a single pixel is called the number of
<dfn>channel</dfn>s of the <a>ImageFormat</a>.
Multiple pixel valuse of a pixel are used together to describe the
captured property which could be color or depth information.
For example, if the data is a color image in RGB color space, then it
is a three-channel <a>ImageFormat</a> and a pixel is described by R, G
and B three pixel values with range from 0 to 255.
Another example, if the data is a gray image, then it is a
single-channel <a>ImageFormat</a> with 8-bit unsigned interger data
type and the pixel value describes the gray scale.
For depth data, it is a single channel <a>ImageFormat</a> too, but the
data type is 16-bit unsigned interger and the pixel value is the depth
level.
For those <a>ImageFormat</a>s whose pixels contain multiple pixel
values, the pixel values might be arranged in a planar way or
interleaving way:
<ol>
<li>
<dfn>Planar pixel layout</dfn>: each channel has its pixel values
stored consecutively in separated buffers (a.k.a. planes) and then
all channel buffers are stored consecutively in memory.
(Ex: RRRRRR......GGGGGG......BBBBBB......)
</li>
<li>
<dfn>Interleaving pixel layout</dfn>: each pixel has its pixel
values from all channels stored together and interleaves all
channels.
(Ex: RGBRGBRGBRGBRGB......)
</li>
</ol>
<div class="note">
<p>
<a>ImageFormat</a>s belong to the same color space might have
different pixel layouts.
</p>
</div>
</p>
<section id='imageformat-enumaration'>
<h2><code>ImageFormat</code> enumeration</h2>
<p>
An enumeration <a>ImageFormat</a> defines a list of image formats
which are supported by the browser and exposed to users. The extend
APIs in this specification use this enumeration to negotiate the
format while accessing the underlying data of <a>ImageBitmap</a> and
creating a new <a>ImageBitmap</a>.
</p>
<div class="note">
<p>
We need to elaborate this list for standardization.
</p>
</div>
<dl id="enum-basic" class="idl" title="enum ImageFormat">
<dt>RGBA32</dt>
<dd>
<p>Channel order: R, G, B, A</p>
<p>Channel size: full rgba-chennels</p>
<p>Pixel layout: interleaving rgba-channels</p>
<p>Data type: 8-bit unsigned integer</p>
</dd>
<dt>BGRA32</dt>
<dd>
<p>Channel order: B, G, R, A</p>
<p>Channel size: full bgra-channels</p>
<p>Pixel layout: interleaving bgra-channels</p>
<p>Data type: 8-bit unsigned integer</p>
</dd>
<dt>RGB24</dt>
<dd>
<p>Channel order: R, G, B</p>
<p>Channel size: full rgb-channels</p>
<p>Pixel layout: interleaving rgb-channels</p>
<p>Data type: 8-bit unsigned integer</p>
</dd>
<dt>BGR24</dt>
<dd>
<p>Channel order: B, G, R</p>
<p>Channel size: full bgr-channels</p>
<p>Pixel layout: interleaving bgr-channels</p>
<p>Data type: 8-bit unsigned integer</p>
</dd>
<dt>GRAY8</dt>
<dd>
<p>Channel order: GRAY</p>
<p>Channel size: full gray-channel</p>
<p>Pixel layout: planar gray-channel</p>
<p>Data type: 8-bit unsigned integer</p>
</dd>
<dt>YUV444P</dt>
<dd>
<p>Channel order: Y, U, V</p>
<p>Channel size: full yuv-channels</p>
<p>Pixel layout: planar yuv-channels</p>
<p>Data type: 8-bit unsigned integer</p>
</dd>
<dt>YUV422P</dt>
<dd>
<p>Channel order: Y, U, V</p>
<p>Channel size: full y-channel, half uv-channels</p>
<p>Pixel layout: planar yuv-channels</p>
<p>Data type: 8-bit unsigned integer</p>
</dd>
<dt>YUV420P</dt>
<dd>
<p>Channel order: Y, U, V</p>
<p>Channel size: full y-channel, quarter uv-channels</p>
<p>Pixel layout: planar yuv-channels</p>
<p>Data type: 8-bit unsigned integer</p>
</dd>
<dt>YUV420SP_NV12</dt>
<dd>
<p>Channel order: Y, U, V</p>
<p>Channel size: full y-channel, quarter uv-channels</p>
<p>Pixel layout: planar y-channel, interleaving uv-channels</p>
<p>Data type: 8-bit unsigned integer</p>
</dd>
<dt>YUV420SP_NV21</dt>
<dd>
<p>Channel order: Y, V, U</p>
<p>Channel size: full y-channel, quarter uv-channels</p>
<p>Pixel layout: planar y-channel, interleaving vu-channels</p>
<p>Data type: 8-bit unsigned integer</p>
</dd>
<dt>HSV</dt>
<dd>
<p>Channel order: H, S, V</p>
<p>Channel size: full hsv-channels</p>
<p>Pixel layout: interleaving hsv-channels</p>
<p>Data type: 8-bit unsigned integer</p>
</dd>
<dt>Lab</dt>
<dd>
<p>Channel order: l, a, b</p>
<p>Channel size: full lab-channels</p>
<p>Pixel layout: interleaving lab-channels</p>
<p>Data type: 8-bit unsigned integer</p>
</dd>
<dt>DEPTH</dt>
<dd>
<p>Channel order: DEPTH</p>
<p>Channel size: full depth-channel</p>
<p>Pixel layout: planar depth-channel</p>
<p>Data type: 16-bit unsigned integer</p>
</dd>
</dl>
</section>
<section id='datatype-enumeration'>
<h2><code>DataType</code> enumeration</h2>
<p>
An enumeration <a>DataType</a> defines a list of data types that is
used to store a single <a>pixel value</a>.
</p>
<dl id="enum-basic" class="idl" title="enum DataType">
<dt>uint8</dt>
<dd>
8-bit unsigned integer.
</dd>
<dt>int8</dt>
<dd>
8-bit integer.
</dd>
<dt>uint16</dt>
<dd>
16-bit unsigned integer.
</dd>
<dt>int16</dt>
<dd>
16-bit integer.
</dd>
<dt>uint32</dt>
<dd>
32-bit unsigned integer.
</dd>
<dt>int32</dt>
<dd>
32-bit integer.
</dd>
<dt>float32</dt>
<dd>
32-bit IEEE floating point number.
</dd>
<dt>float64</dt>
<dd>
64-bit IEEE floating point number.
</dd>
</dl>
</section>
</section>
<section id='pixellayout'>
<h2>PixelLayout</h2>
<p>
Two interfaces, <a>ImageFormatPixelLayout</a> and
<a>ChannelPixelLayout</a>, help together to generalize the variety of
pixel layouts among image formats.
</p>
<p>
The <a>ImageFormatPixelLayout</a> represents the pixel layout of a
certain image format and since a image format is composed by at least
one <a>channel</a> so an <a>ImageFormatPixelLayout</a> object contains
at least one <a>ChannelPixelLayout</a> object.
</p>
<p>
Although an image or a video frame is a two-dimensional structure, its
data is usually stored in an one-dimensional array in the raw-major
way and the <a>ChannelPixelLayout</a> uses the following properties to
describe how pixel values are arranged in the one dimentional array
buffer.
<ol>
<li>
<strong>offset</strong>: where is each <a>channel</a>'s data
starts from.
(Relative to the beginning of the video data one-dimension array.)
</li>
<li>
<strong>width</strong> and <strong>height</strong>:
how much samples are in each channel.
</li>
<li>
<strong>data type</strong>: the data type used to store one single
<a>pixel value</a>.
</li>
<li>
<strong>stride</strong>: the total bytes of each raw plus the
padding bytes of each row.
</li>
<li>
<strong>skip</strong>: this is used to describe <a>interleaving
pixel layout</a>. (For <a>planar pixel layout</a>, this property
will be zero.)
</li>
</ol>
</p>
<pre class='example highlight'>
Example1: RGBA image, width = 620, height = 480, stride = 2560
chanel_r: offset = 0, width = 620, height = 480, data type = uint8, stride = 2560, skip = 3
chanel_g: offset = 1, width = 620, height = 480, data type = uint8, stride = 2560, skip = 3
chanel_b: offset = 2, width = 620, height = 480, data type = uint8, stride = 2560, skip = 3
chanel_a: offset = 3, width = 620, height = 480, data type = uint8, stride = 2560, skip = 3
<---------------------------- stride ---------------------------->
<---------------------- width x 4 ---------------------->
[index] 01234 8 12 16 20 24 28 2479 2559
|||||---|---|---|---|---|---|----------------------------|-------|
[data] RGBARGBARGBARGBARGBAR___R___R... A%%%%%%%%
[data] RGBARGBARGBARGBARGBAR___R___R... A%%%%%%%%
[data] RGBARGBARGBARGBARGBAR___R___R... A%%%%%%%%
^^^
r-skip
</pre>
<pre class='example highlight'>
Example2: YUV420P image, width = 620, height = 480, stride = 640
chanel_y: offset = 0, width = 620, height = 480, stride = 640, skip = 0
chanel_u: offset = 307200, width = 310, height = 240, data type = uint8, stride = 320, skip = 0
chanel_v: offset = 384000, width = 310, height = 240, data type = uint8, stride = 320, skip = 0
<--------------------------- y-stride --------------------------->
<----------------------- y-width ----------------------->
[index] 012345 619 639
||||||--------------------------------------------------|--------|
[data] YYYYYYYYYYYYYYYYYYYYYYYYYYYYY... Y%%%%%%%%%
[data] YYYYYYYYYYYYYYYYYYYYYYYYYYYYY... Y%%%%%%%%%
[data] YYYYYYYYYYYYYYYYYYYYYYYYYYYYY... Y%%%%%%%%%
[data] ......
<-------- u-stride ---------->
<----- u-width ----->
[index] 307200 307509 307519
|-------------------|--------|
[data] UUUUUUUUUU... U%%%%%%%%%
[data] UUUUUUUUUU... U%%%%%%%%%
[data] UUUUUUUUUU... U%%%%%%%%%
[data] ......
<-------- v-stride ---------->
<- --- v-width ----->
[index] 384000 384309 384319
|-------------------|--------|
[data] VVVVVVVVVV... V%%%%%%%%%
[data] VVVVVVVVVV... V%%%%%%%%%
[data] VVVVVVVVVV... V%%%%%%%%%
[data] ......
</pre>
<pre class='example highlight'>
Example3: YUV420SP_NV12 image, width = 620, height = 480, stride = 640
chanel_y: offset = 0, width = 620, height = 480, stride = 640, skip = 0
chanel_u: offset = 307200, width = 310, height = 240, data type = uint8, stride = 640, skip = 1
chanel_v: offset = 307201, width = 310, height = 240, data type = uint8, stride = 640, skip = 1
<--------------------------- y-stride -------------------------->
<----------------------- y-width ---------------------->
[index] 012345 619 639
||||||-------------------------------------------------|--------|
[data] YYYYYYYYYYYYYYYYYYYYYYYYYYYYY... Y%%%%%%%%%
[data] YYYYYYYYYYYYYYYYYYYYYYYYYYYYY... Y%%%%%%%%%
[data] YYYYYYYYYYYYYYYYYYYYYYYYYYYYY... Y%%%%%%%%%
[data] ......
<--------------------- u-stride / v-stride -------------------->
<------------------ u-width + v-width ----------------->
[index] 307200(u-offset) 307819 307839
|------------------------------------------------------|-------|
[index] |307201(v-offset) |307820 |
||-----------------------------------------------------||------|
[data] UVUVUVUVUVUVUVUVUVUVUVUVUVUVUV... UV%%%%%%%
[data] UVUVUVUVUVUVUVUVUVUVUVUVUVUVUV... UV%%%%%%%
[data] UVUVUVUVUVUVUVUVUVUVUVUVUVUVUV... UV%%%%%%%
^ ^
u-skip v-skip
</pre>
<pre class='example highlight'>
Example4: DEPTH image, width = 640, height = 480, stride = 1280
chanel_d: offset = 0, width = 640, height = 480, data type = uint16, stride = 1280, skip = 0
<----------------------- d-stride ---------------------->
<----------------------- d-width ----------------------->
[index] 012345 1280
||||||--------------------------------------------------|
[data] DDDDDDDDDDDDDDDDDDDDDDDDDDDDD... D
[data] DDDDDDDDDDDDDDDDDDDDDDDDDDDDD... D
[data] DDDDDDDDDDDDDDDDDDDDDDDDDDDDD... D
[data] ......
</pre>
<section id='imageformatpixellayout-interface'>
<h2><code>ImageFormatPixelLayout</code> interface</h2>
<dl class="idl" title="[Exposed=(Window,Worker)] interface ChannelPixelLayout">
<dt>
readonly attribute unsigned long offset
</dt>
<dd>
<p>
The beginning position of this <a>channel</a>'s data (relative
to the given <a>BufferSource</a> parameter of the mapDataInto()
method.)
</p>
</dd>
<dt>
readonly attribute unsigned long width
</dt>
<dd>
<p>
The width of this channel.
<a>Channel</a>s in an image format may have different width.
</p>
</dd>
<dt>
readonly attribute unsigned long height
</dt>
<dd>
<p>
The height of this channel.
<a>Channel</a>s in an image format may have different height.
</p>
</dd>
<dt>
readonly attribute DataType dataType
</dt>
<dd>
<p>
The data type used to store one single <a>pixel value</a>.
</p>
</dd>
<dt>
readonly attribute unsigned long stride
</dt>
<dd>
<p>
The stride of this channel.
</p>
</p>
The stride is the number of bytes between the beging two
consecutive raws in memory.
</p>
<p>
The total bytes of each raw plus the padding bytes of each raw.
</p>
</dd>
<dt>
readonly attribute unsigned long skip
</dt>
<dd>
<p>
This is used to describe how much bytes between two adjacent
<a>pixel value</a>s in this channel.
</p>
<p>
Possible values:
<ul>
<li>
zero: for <a>planar pixel layout</a>.
</li>
<li>
a positive integer: for <a>interleaving pixel layout</a>.
</li>
</ul>
</p>
</dd>
</dl>
</section>
<section id='channelpixellayout-interface'>
<h2><code>ChannelPixelLayout</code> interface</h2>
<dl class="idl" title="[Exposed=(Window,Worker)] interface ImageFormatPixelLayout">
<dt>
readonly attribute sequence<ChannelPixelLayout> channels
</dt>
<dd>
<p>
Channel information of this image format.
Each image format has at least one <a>channel</a>.
<p>
</dd>
</dl>
</section>
</section>
<section id='imagebitmap-interface-extensions'>
<h2><code>ImageBitmap</code> interface</h2>
<dl class="idl" title="[Exposed=(Window,Worker)] partial interface ImageBitmap">
<dt>
ImageFormat findOptimalFormat()
</dt>
<dd>
<p>
Find the best image format for receiving data.
</p>
<p>
Return one of the <code>possibleFormats</code> or the empty
string if no any format in the list is supported. If the
<code>possibleFormats</code> is not given, then returns the most
suitable image format for this ImageBitmap from all supported
image formats.
</p>
<dl class="parameters">
<dt>optional sequence<ImageFormat> possibleFormats</dt>
<dd>
A list of image formats that users can handler.
</dd>
</dl>
</dd>
<dt>
long mappedDataLength()
</dt>
<dd>
<p>
Calculate the length of mapped data wile the image is represented
in the given <code>format</code>.
</p>
<p>
Throws if <code>format</code> is not supported.
</p>
<p>
Return the length (in bytes) of image data that is represented in
the given <code>format</code>.
</p>
<dl class="parameters">
<dt>ImageFormat format</dt>
<dd>
The format that users want.
</dd>
</dl>
</dd>
<dt>
Promise<ImageFormatPixelLayout> mapDataInto()
</dt>
<dd>
<p>
Makes a copy of the underlying image data in the given format
<code>format</code> into the given <code>buffer</code> at offset
<code>offset</code>, filling at most <code>length</code> bytes and
returns an <a>ImageFormatPixelLayout</a> object which describes
the pixel layout.
</p>
<p>
Throws if <code>format</code> is not supported.
</p>
<p>
Each time this method is invoked returns a new
<a>ImageFormatPixelLayout</a> object.
</p>
<p>
Return an <a>ImageFormatPixelLayout</a> object which describes the
pixel layout.
</p>
<dl class="parameters">
<dt>ImageFormat format</dt>
<dd>
The format that users want.
</dd>
<dt>BufferSource buffer</dt>
<dd>
A container for receiving the mapped image data.
</dd>
<dt>long offset</dt>
<dd>
The beginning position of the <code>buffer</code> to place
the mapped data.
</dd>
<dt>long length</dt>
<dd>
The length of space in the <code>buffer</code> that could be
filled.
</dd>
</dl>
</dd>
</dl>
</section>
<section id='imagebitmapfactories-interface-extensions'>
<h2><code>ImageBitmapFactories</code> interface</h2>
<dl class="idl" title="[NoInterfaceObject, Exposed=(Window,Worker)] partial interface ImageBitmapFactories">
<dt>
Promise<ImageBitmap> createImageBitmap()
</dt>
<dd>
<p>
Create an <code>ImageBitmap</code> from a
<code>BufferSource</code> containg raw image data.