Welcome to mirror list, hosted at ThFree Co, Russian Federation.

bge.texture.rst « rst « python_api « doc - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 4588a3e1800f03423a66a68007f32bc108eff85a (plain)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122

Video Texture (bge.texture)
===========================

************
Introduction
************

The bge.texture module allows you to manipulate textures during the game.

Several sources for texture are possible: video files, image files, video capture, memory buffer, camera render or a mix of that.

The video and image files can be loaded from the internet using an URL instead of a file name.

In addition, you can apply filters on the images before sending them to the GPU, allowing video effect: blue screen, color band, gray, normal map.

bge.texture uses FFmpeg to load images and videos. All the formats and codecs that FFmpeg supports are supported by this module, including but not limited to:

* AVI
* Ogg
* Xvid
* Theora
* dv1394 camera
* video4linux capture card (this includes many webcams)
* videoForWindows capture card (this includes many webcams)
* JPG

The principle is simple: first you identify a texture on an existing object using
the :class:`~bge.texture.materialID` function, then you create a new texture with dynamic content
and swap the two textures in the GPU.

The GE is not aware of the substitution and continues to display the object as always,
except that you are now in control of the texture.

When the texture object is deleted, the new texture is deleted and the old texture restored.

.. module:: bge.texture

.. include:: ../examples/bge.texture.py
   :start-line: 1
   :end-line: 5
   
.. literalinclude:: ../examples/bge.texture.py
   :lines: 7-

.. include:: ../examples/bge.texture.1.py
   :start-line: 1
   :end-line: 6
   
.. literalinclude:: ../examples/bge.texture.1.py
   :lines: 8-
   
   
*************
Video classes
*************

.. class:: VideoFFmpeg(file, capture=-1, rate=25.0, width=0, height=0)

   FFmpeg video source.
      
   :arg file: Path to the video to load; if capture >= 0 on Windows, this parameter will not be used.
   :type file: str
   :arg capture: Capture device number; if >= 0, the corresponding webcam will be used. (optional)
   :type capture: int
   :arg rate: Capture rate. (optional, used only if capture >= 0)
   :type rate: float
   :arg width: Capture width. (optional, used only if capture >= 0)
   :type width: int
   :arg height: Capture height. (optional, used only if capture >= 0)
   :type height: int

   .. attribute:: status

      Video status. (readonly)
      
      :type: int
      :value: see `FFmpeg Video and Image Status`_.

   .. attribute:: range

      Replay range.
      
      :type: sequence of two floats

   .. attribute:: repeat

      Repeat count, -1 for infinite repeat.

      :type: int

   .. attribute:: framerate

      Frame rate.

      :type: float

   .. attribute:: valid

      Tells if an image is available. (readonly)

      :type: bool

   .. attribute:: image

      Image data. (readonly)
      
      :type: :class:`~bgl.Buffer` or None

   .. attribute:: size

      Image size. (readonly)
      
      :type: tuple of two ints

   .. attribute:: scale

      Fast scale of image (near neighbour).
      
      :type: bool

   .. attribute:: flip

      Flip image vertically.
      
      :type: bool

   .. attribute:: filter

      Pixel filter.
      
      :type: one of...
      
         * :class:`FilterBGR24`
         * :class:`FilterBlueScreen`
         * :class:`FilterColor`
         * :class:`FilterGray`
         * :class:`FilterLevel`
         * :class:`FilterNormal`
         * :class:`FilterRGB24`
         * :class:`FilterRGBA32`

   .. attribute:: preseek

      Number of frames of preseek.

      :type: int

   .. attribute:: deinterlace

      Deinterlace image.

      :type: bool

   .. method:: play()

      Play (restart) video.
      
      :return: Whether the video was ready or stopped.
      :rtype: bool

   .. method:: pause()

      Pause video.
      
      :return: Whether the video was playing.
      :rtype: bool

   .. method:: stop()

      Stop video (play will replay it from start).
      
      :return: Whether the video was playing.
      :rtype: bool

   .. method:: refresh()

      Refresh video - get its status.
      
      :value: see `FFmpeg Video and Image Status`_.

      :rtype: int

*************
Image classes
*************

.. class:: ImageFFmpeg(file)

   FFmpeg image source.
      
   :arg file: Path to the image to load.
   :type file: str

   .. attribute:: status

      Image status. (readonly)
      
      :type: int
      :value: see `FFmpeg Video and Image Status`_.

   .. attribute:: valid

      Tells if an image is available. (readonly)

      :type: bool

   .. attribute:: image

      Image data. (readonly)
      
      :type: :class:`~bgl.Buffer` or None

   .. attribute:: size

      Image size. (readonly)
      
      :type: tuple of two ints

   .. attribute:: scale

      Fast scale of image (near neighbour).
      
      :type: bool

   .. attribute:: flip

      Flip image vertically.
      
      :type: bool

   .. attribute:: filter

      Pixel filter.
      
      :type: one of...
      
         * :class:`FilterBGR24`
         * :class:`FilterBlueScreen`
         * :class:`FilterColor`
         * :class:`FilterGray`
         * :class:`FilterLevel`
         * :class:`FilterNormal`
         * :class:`FilterRGB24`
         * :class:`FilterRGBA32`

   .. method:: refresh()

      Refresh image, i.e. load it.
      
      :value: see `FFmpeg Video and Image Status`_.

      :rtype: int

   .. method:: reload(newname=None)

      Reload image, i.e. reopen it.
      
      :arg newname: Path to a new image. (optional)
      :type newname: str

.. class:: ImageBuff(width, height, color=0, scale=False)

   Image source from image buffer.
   
   :arg width: Width of the image.
   :type width: int
   :arg height: Height of the image.
   :type height: int
   :arg color: Value to initialize RGB channels with. The initialized buffer will have
               all pixels set to (color, color, color, 255). (optional)
   :type color: int in [0, 255]
   :arg scale: Image uses scaling. (optional)
   :type scale: bool

   .. attribute:: filter

      Pixel filter.
      
      :type: one of...
      
         * :class:`FilterBGR24`
         * :class:`FilterBlueScreen`
         * :class:`FilterColor`
         * :class:`FilterGray`
         * :class:`FilterLevel`
         * :class:`FilterNormal`
         * :class:`FilterRGB24`
         * :class:`FilterRGBA32`

   .. attribute:: flip

      Flip image vertically.
      
      :type: bool

   .. attribute:: image

      Image data. (readonly)
      
      :type: :class:`~bgl.Buffer` or None

   .. method:: load(imageBuffer, width, height)

      Load image from buffer.
      
      :arg imageBuffer: Buffer to load the image from.
      :type imageBuffer: :class:`~bgl.Buffer` or Python object implementing the buffer protocol (f.ex. bytes)
      :arg width: Width of the image to load.
      :type width: int
      :arg height: Height of the image to load.
      :type height: int

   .. method:: plot(imageBuffer, width, height, positionX, positionY, mode=IMB_BLEND_COPY)

      Update image buffer.
      
      :arg imageBuffer: Buffer to load the new data from.
      :type imageBuffer: :class:`~bgl.Buffer`, :class:`ImageBuff` or Python object implementing the buffer protocol (f.ex. bytes)
      :arg width: Width of the data to load.
      :type width: int
      :arg height: Height of the data to load.
      :type height: int
      :arg positionX: Left boundary of the region to be drawn on.
      :type positionX: int
      :arg positionY: Upper boundary of the region to be drawn on.
      :type positionY: int
      :arg mode: Drawing mode, see `Image Blending Modes`_.
      :type mode: int
      

   .. attribute:: scale

      Fast scale of image (near neighbour).
      
      :type: bool

   .. attribute:: size

      Image size. (readonly)
      
      :type: tuple of two ints

   .. attribute:: valid

      Tells if an image is available. (readonly)

      :type: bool

.. class:: ImageMirror(scene, observer, mirror, material=0)

   Image source from mirror.
   
   :arg scene: Scene in which the image has to be taken.
   :type scene: :class:`~bge.types.KX_Scene`
   :arg observer: Reference object for the mirror (the object from which the mirror has to be looked at, for example a camera).
   :type observer: :class:`~bge.types.KX_GameObject`
   :arg mirror: Object holding the mirror.
   :type mirror: :class:`~bge.types.KX_GameObject`
   :arg material: ID of the mirror's material to be used for mirroring. (optional)
   :type material: int

   .. attribute:: alpha

      Use alpha in texture.
      
      :type: bool

   .. attribute:: background

      Background color.
      
      :type: int or float list [r, g, b, a] in [0.0, 255.0]

   .. attribute:: capsize

      Size of render area.
      
      :type: sequence of two ints

   .. attribute:: clip

      Clipping distance.
      
      :type: float in [0.01, 5000.0]

   .. attribute:: filter

      Pixel filter.
      
      :type: one of...
      
         * :class:`FilterBGR24`
         * :class:`FilterBlueScreen`
         * :class:`FilterColor`
         * :class:`FilterGray`
         * :class:`FilterLevel`
         * :class:`FilterNormal`
         * :class:`FilterRGB24`
         * :class:`FilterRGBA32`

   .. attribute:: flip

      Flip image vertically.
      
      :type: bool

   .. attribute:: image

      Image data. (readonly)
      
      :type: :class:`~bgl.Buffer` or None

   .. method:: refresh()

      Refresh image - invalidate its current content.

   .. attribute:: scale

      Fast scale of image (near neighbour).
      
      :type: bool

   .. attribute:: size

      Image size (readonly).
      
      :type: tuple of two ints

   .. attribute:: valid

      Tells if an image is available. (readonly)

      :type: bool

   .. attribute:: whole

      Use whole viewport to render.
      
      :type: bool

.. class:: ImageMix

   Image mixer.

   .. attribute:: filter

      Pixel filter.
      
      :type: one of...
      
         * :class:`FilterBGR24`
         * :class:`FilterBlueScreen`
         * :class:`FilterColor`
         * :class:`FilterGray`
         * :class:`FilterLevel`
         * :class:`FilterNormal`
         * :class:`FilterRGB24`
         * :class:`FilterRGBA32`

   .. attribute:: flip

      Flip image vertically.
      
      :type: bool

   .. method:: getSource(id)

      Get image source.
      
      :arg id: Identifier of the source to get.
      :type id: str
      
      :return: Image source.
      :rtype: one of...
      
         * :class:`VideoFFmpeg`
         * :class:`ImageFFmpeg`
         * :class:`ImageBuff`
         * :class:`ImageMirror`
         * :class:`ImageMix`
         * :class:`ImageRender`
         * :class:`ImageViewport`

   .. method:: getWeight(id)

      Get image source weight.
      
      :arg id: Identifier of the source.
      :type id: str
      
      :return: Weight of the source.
      :rtype: int

   .. attribute:: image

      Image data. (readonly)
      
      :type: :class:`~bgl.Buffer` or None

   .. method:: refresh()

      Refresh image - invalidate its current content.

   .. attribute:: scale

      Fast scale of image (near neighbour).
      
      :type: bool
      
   .. attribute:: size

      Image size. (readonly)
      
      :type: tuple of two ints

   .. method:: setSource(id, image)

      Set image source - all sources must have the same size.
      
      :arg id: Identifier of the source to set.
      :type id: str
      :arg image: Image source of type...
      
         * :class:`VideoFFmpeg`
         * :class:`ImageFFmpeg`
         * :class:`ImageBuff`
         * :class:`ImageMirror`
         * :class:`ImageMix`
         * :class:`ImageRender`
         * :class:`ImageViewport`

   .. method:: setWeight(id, weight)

      Set image source weight - the sum of the weights should be 256 to get full color intensity in the output.
      
      :arg id: Identifier of the source.
      :type id: str
      :arg weight: Weight of the source.
      :type weight: int

   .. attribute:: valid

      Tells if an image is available. (readonly)

      :type: bool

.. class:: ImageRender(scene, camera)

   Image source from render.
   
   :arg scene: Scene in which the image has to be taken.
   :type scene: :class:`~bge.types.KX_Scene`
   :arg camera: Camera from which the image has to be taken.
   :type camera: :class:`~bge.types.KX_Camera`

   .. attribute:: alpha

      Use alpha in texture.
      
      :type: bool

   .. attribute:: background

      Background color.
      
      :type: int or float list [r, g, b, a] in [0.0, 255.0]

   .. attribute:: capsize

      Size of render area.
      
      :type: sequence of two ints

   .. attribute:: filter

      Pixel filter.
      
      :type: one of...
      
         * :class:`FilterBGR24`
         * :class:`FilterBlueScreen`
         * :class:`FilterColor`
         * :class:`FilterGray`
         * :class:`FilterLevel`
         * :class:`FilterNormal`
         * :class:`FilterRGB24`
         * :class:`FilterRGBA32`

   .. attribute:: flip

      Flip image vertically.
      
      :type: bool

   .. attribute:: image

      Image data. (readonly)
      
      :type: :class:`~bgl.Buffer` or None

   .. method:: refresh()

      Refresh image - invalidate its current content.

   .. attribute:: scale

      Fast scale of image (near neighbour).
      
      :type: bool

   .. attribute:: size

      Image size. (readonly)
      
      :type: tuple of two ints

   .. attribute:: valid

      Tells if an image is available. (readonly)

      :type: bool

   .. attribute:: whole

      Use whole viewport to render.
      
      :type: bool

   .. attribute:: depth

      Use depth component of render as array of float - not suitable for texture source,
      should only be used with bge.texture.imageToArray(mode='F').
      
      :type: bool

   .. attribute:: zbuff

      Use depth component of render as grey scale color -  suitable for texture source.
      
      :type: bool

.. class:: ImageViewport

   Image source from viewport.

   .. attribute:: alpha

      Use alpha in texture.
      
      :type: bool

   .. attribute:: capsize

      Size of viewport area being captured.
      
      :type: sequence of two ints

   .. attribute:: filter

      Pixel filter.
      
      :type: one of...
      
         * :class:`FilterBGR24`
         * :class:`FilterBlueScreen`
         * :class:`FilterColor`
         * :class:`FilterGray`
         * :class:`FilterLevel`
         * :class:`FilterNormal`
         * :class:`FilterRGB24`
         * :class:`FilterRGBA32`

   .. attribute:: flip

      Flip image vertically.
      
      :type: bool

   .. attribute:: image

      Image data. (readonly)
      
      :type: :class:`~bgl.Buffer` or None

   .. attribute:: position

      Upper left corner of the captured area.
      
      :type: sequence of two ints

   .. method:: refresh()

      Refresh image - invalidate its current content.

   .. attribute:: scale

      Fast scale of image (near neighbour).
      
      :type: bool

   .. attribute:: size

      Image size. (readonly)
      
      :type: tuple of two ints

   .. attribute:: valid

      Tells if an image is available. (readonly)

      :type: bool

   .. attribute:: whole

      Use whole viewport to capture.
      
      :type: bool

   .. attribute:: depth

      Use depth component of viewport as array of float - not suitable for texture source,
      should only be used with bge.texture.imageToArray(mode='F').
      
      :type: bool

   .. attribute:: zbuff

      Use depth component of viewport as grey scale color -  suitable for texture source.
      
      :type: bool

   
***************
Texture classes
***************

.. class:: Texture(gameObj, materialID=0, textureID=0, textureObj=None)

   Texture object.
   
   :arg gameObj: Game object to be created a video texture on.
   :type gameObj: :class:`~bge.types.KX_GameObject`
   :arg materialID: Material ID. (optional)
   :type materialID: int
   :arg textureID: Texture ID. (optional)
   :type textureID: int
   :arg textureObj: Texture object with shared bindId. (optional)
   :type textureObj: :class:`Texture`

   .. attribute:: bindId

      OpenGL Bind Name. (readonly)
      
      :type: int

   .. method:: close()

      Close dynamic texture and restore original.

   .. attribute:: mipmap

      Mipmap texture.
      
      :type: bool

   .. method:: refresh(refresh_source=True, ts=-1.0)

      Refresh texture from source.
      
      :arg refresh_source: Whether to also refresh the image source of the texture.
      :type refresh_source: bool
      :arg ts: If the texture controls a VideoFFmpeg object:
               timestamp (in seconds from the start of the movie) of the frame to be loaded; this can be
               used for video-sound synchonization by passing :attr:`~bge.types.KX_SoundActuator.time` to it. (optional)
      :type ts: float

   .. attribute:: source

      Source of texture.
      
      :type: one of...
      
         * :class:`VideoFFmpeg`
         * :class:`ImageFFmpeg`
         * :class:`ImageBuff`
         * :class:`ImageMirror`
         * :class:`ImageMix`
         * :class:`ImageRender`
         * :class:`ImageViewport`

   
**************
Filter classes
**************


.. class:: FilterBGR24

   Source filter BGR24.

.. class:: FilterBlueScreen

   Filter for Blue Screen. The RGB channels of the color are left unchanged, while the output alpha is obtained as follows:
   
   * if the square of the euclidian distance between the RGB color and the filter's reference color is smaller than the filter's lower limit,
     the output alpha is set to 0;
   
   * if that square is bigger than the filter's upper limit, the output alpha is set to 255;
   
   * otherwise the output alpha is linarly extrapoled between 0 and 255 in the interval of the limits.

   .. attribute:: color

      Reference color.
      
      :type: sequence of three ints
      :default: (0, 0, 255)

   .. attribute:: limits

      Reference color limits.
      
      :type: sequence of two ints
      :default: (64, 64)

   .. attribute:: previous

      Previous pixel filter.
      
      :type: one of...
      
         * :class:`FilterBGR24`
         * :class:`FilterBlueScreen`
         * :class:`FilterColor`
         * :class:`FilterGray`
         * :class:`FilterLevel`
         * :class:`FilterNormal`
         * :class:`FilterRGB24`
         * :class:`FilterRGBA32`

.. class:: FilterColor

   Filter for color calculations. The output color is obtained by multiplying the reduced 4x4 matrix with the input color
   and adding the remaining column to the result.

   .. attribute:: matrix

      Matrix [4][5] for color calculation.
      
      :type: sequence of four sequences of five ints
      :default: ((256, 0, 0, 0, 0), (0, 256, 0, 0, 0), (0, 0, 256, 0, 0), (0, 0, 0, 256, 0))

   .. attribute:: previous

      Previous pixel filter.
      
      :type: one of...
      
         * :class:`FilterBGR24`
         * :class:`FilterBlueScreen`
         * :class:`FilterColor`
         * :class:`FilterGray`
         * :class:`FilterLevel`
         * :class:`FilterNormal`
         * :class:`FilterRGB24`
         * :class:`FilterRGBA32`

.. class:: FilterGray

   Filter for gray scale effect. Proportions of R, G and B contributions in the output gray scale are 28:151:77.

   .. attribute:: previous

      Previous pixel filter.
      
      :type: one of...
      
         * :class:`FilterBGR24`
         * :class:`FilterBlueScreen`
         * :class:`FilterColor`
         * :class:`FilterGray`
         * :class:`FilterLevel`
         * :class:`FilterNormal`
         * :class:`FilterRGB24`
         * :class:`FilterRGBA32`

.. class:: FilterLevel

   Filter for levels calculations. Each output color component is obtained as follows:
   
   * if it is smaller than its corresponding min value, it is set to 0;
   
   * if it is bigger than its corresponding max value, it is set to 255;
   
   * Otherwise it is linearly extrapoled between 0 and 255 in the (min, max) interval.

   .. attribute:: levels

      Levels matrix [4] (min, max).
      
      :type: sequence of four sequences of two ints
      :default: ((0, 255), (0, 255), (0, 255), (0, 255))

   .. attribute:: previous

      Previous pixel filter.
      
      :type: one of...
      
         * :class:`FilterBGR24`
         * :class:`FilterBlueScreen`
         * :class:`FilterColor`
         * :class:`FilterGray`
         * :class:`FilterLevel`
         * :class:`FilterNormal`
         * :class:`FilterRGB24`
         * :class:`FilterRGBA32`

.. class:: FilterNormal

   Normal map filter.

   .. attribute:: colorIdx

      Index of color used to calculate normal (0 - red, 1 - green, 2 - blue, 3 - alpha).
      
      :type: int in [0, 3]
      :default: 0

   .. attribute:: depth

      Depth of relief.
      
      :type: float
      :default: 4.0

   .. attribute:: previous

      Previous pixel filter.
      
      :type: one of...
      
         * :class:`FilterBGR24`
         * :class:`FilterBlueScreen`
         * :class:`FilterColor`
         * :class:`FilterGray`
         * :class:`FilterLevel`
         * :class:`FilterNormal`
         * :class:`FilterRGB24`
         * :class:`FilterRGBA32`

.. class:: FilterRGB24

   Returns a new input filter object to be used with :class:`ImageBuff` object when the image passed
   to the :meth:`ImageBuff.load` function has the 3-bytes pixel format BGR.

.. class:: FilterRGBA32

   Source filter RGBA32.


*********
Functions
*********

.. function:: getLastError()

   Last error that occurred in a bge.texture function.

   :return: The description of the last error occurred in a bge.texture function.
   :rtype: str

.. function:: imageToArray(image, mode)

   Returns a :class:`~bgl.Buffer` corresponding to the current image stored in a texture source object.

   :arg image: Image source object of type ...

      * :class:`VideoFFmpeg`
      * :class:`ImageFFmpeg`
      * :class:`ImageBuff`
      * :class:`ImageMirror`
      * :class:`ImageMix`
      * :class:`ImageRender`
      * :class:`ImageViewport`
   
   :arg mode: Optional argument representing the pixel format.
              
      * You can use the characters R, G, B for the 3 color channels, A for the alpha channel,
        0 to force a fixed 0 color channel and 1 to force a fixed 255 color channel.
        
        Examples:
            * "BGR" will return 3 bytes per pixel with the Blue, Green and Red channels in that order.
            * "RGB1" will return 4 bytes per pixel with the Red, Green, Blue channels in that order and the alpha channel forced to 255.
      
      * A special mode "F" allows to return the image as an array of float. This mode should only be used to retrieve
        the depth buffer of the class:`ImageViewport` and :class:`ImageRender` objects.
        The default mode is "RGBA".
   
   :type mode: str
   
   :return: An object representing the image as one dimensional array of bytes of size (pixel_size*width*height),
            line by line starting from the bottom of the image. The pixel size and format is determined by the mode
            parameter. For mode 'F', the array is a one dimensional array of float of size (width*height).
   :rtype: :class:`~bgl.Buffer`

.. function:: materialID(object, name)

   Returns a numeric value that can be used in :class:`Texture` to create a dynamic texture.

   The value corresponds to an internal material number that uses the texture identified
   by name. name is a string representing a texture name with ``IM`` prefix if you want to
   identify the texture directly. This method works for basic tex face and for material,
   provided the material has a texture channel using that particular texture in first
   position of the texture stack. name can also have ``MA`` prefix if you want to identify
   the texture by material. In that case the material must have a texture channel in first
   position.

   If the object has no material that matches name, it generates a runtime error. Use try/except to catch the exception.

   Ex: ``bge.texture.materialID(obj, 'IMvideo.png')``

   :arg object: The game object that uses the texture you want to make dynamic.
   :type object: :class:`~bge.types.KX_GameObject`
   :arg name: Name of the texture/material you want to make dynamic.
   :type name: str
   
   :return: The internal material number.
   :rtype: int

.. function:: setLogFile(filename)

   Sets the name of a text file in which runtime error messages will be written, in addition to the printing
   of the messages on the Python console. Only the runtime errors specific to the VideoTexture module
   are written in that file, ordinary runtime time errors are not written.

   :arg filename: Name of the error log file.
   :type filename: str
   
   :return: -1 if the parameter name is invalid (not of type string), else 0.
   :rtype: int

   
*********
Constants
*********

FFmpeg Video and Image Status
+++++++++++++++++++++++++++++


.. data:: SOURCE_ERROR

.. data:: SOURCE_EMPTY

.. data:: SOURCE_READY

.. data:: SOURCE_PLAYING

.. data:: SOURCE_STOPPED


Image Blending Modes
++++++++++++++++++++

See Wikipedia's `Blend Modes <https://en.wikipedia.org/wiki/Blend_modes>`_ for reference.

.. data:: IMB_BLEND_MIX

.. data:: IMB_BLEND_ADD

.. data:: IMB_BLEND_SUB

.. data:: IMB_BLEND_MUL

.. data:: IMB_BLEND_LIGHTEN

.. data:: IMB_BLEND_DARKEN

.. data:: IMB_BLEND_ERASE_ALPHA

.. data:: IMB_BLEND_ADD_ALPHA

.. data:: IMB_BLEND_OVERLAY

.. data:: IMB_BLEND_HARDLIGHT

.. data:: IMB_BLEND_COLORBURN

.. data:: IMB_BLEND_LINEARBURN

.. data:: IMB_BLEND_COLORDODGE

.. data:: IMB_BLEND_SCREEN

.. data:: IMB_BLEND_SOFTLIGHT

.. data:: IMB_BLEND_PINLIGHT

.. data:: IMB_BLEND_VIVIDLIGHT

.. data:: IMB_BLEND_LINEARLIGHT

.. data:: IMB_BLEND_DIFFERENCE

.. data:: IMB_BLEND_EXCLUSION

.. data:: IMB_BLEND_HUE

.. data:: IMB_BLEND_SATURATION

.. data:: IMB_BLEND_LUMINOSITY

.. data:: IMB_BLEND_COLOR

.. data:: IMB_BLEND_COPY

.. data:: IMB_BLEND_COPY_RGB

.. data:: IMB_BLEND_COPY_ALPHA