1 /** 2 A camera feed gives you access to a single physical camera attached to your device. 3 4 Copyright: 5 Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. 6 Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) 7 Copyright (c) 2017-2018 Godot-D contributors 8 9 License: $(LINK2 https://opensource.org/licenses/MIT, MIT License) 10 11 12 */ 13 module godot.camerafeed; 14 import std.meta : AliasSeq, staticIndexOf; 15 import std.traits : Unqual; 16 import godot.d.traits; 17 import godot.core; 18 import godot.c; 19 import godot.d.bind; 20 import godot.d.reference; 21 import godot.globalenums; 22 import godot.object; 23 import godot.classdb; 24 import godot.reference; 25 import godot.image; 26 /** 27 A camera feed gives you access to a single physical camera attached to your device. 28 29 When enabled, Godot will start capturing frames from the camera which can then be used. 30 $(B Note:) Many cameras will return YCbCr images which are split into two textures and need to be combined in a shader. Godot does this automatically for you if you set the environment to show the camera image in the background. 31 */ 32 @GodotBaseClass struct CameraFeed 33 { 34 package(godot) enum string _GODOT_internal_name = "CameraFeed"; 35 public: 36 @nogc nothrow: 37 union { /** */ godot_object _godot_object; /** */ Reference _GODOT_base; } 38 alias _GODOT_base this; 39 alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses); 40 package(godot) __gshared bool _classBindingInitialized = false; 41 package(godot) static struct GDNativeClassBinding 42 { 43 __gshared: 44 @GodotName("_allocate_texture") GodotMethod!(void, long, long, long, long, long) _allocateTexture; 45 @GodotName("_set_RGB_img") GodotMethod!(void, Image) _setRgbImg; 46 @GodotName("_set_YCbCr_img") GodotMethod!(void, Image) _setYcbcrImg; 47 @GodotName("_set_YCbCr_imgs") GodotMethod!(void, Image, Image) _setYcbcrImgs; 48 @GodotName("_set_name") GodotMethod!(void, String) _setName; 49 @GodotName("_set_position") GodotMethod!(void, long) _setPosition; 50 @GodotName("get_id") GodotMethod!(long) getId; 51 @GodotName("get_name") GodotMethod!(String) getName; 52 @GodotName("get_position") GodotMethod!(CameraFeed.FeedPosition) getPosition; 53 @GodotName("get_transform") GodotMethod!(Transform2D) getTransform; 54 @GodotName("is_active") GodotMethod!(bool) isActive; 55 @GodotName("set_active") GodotMethod!(void, bool) setActive; 56 @GodotName("set_transform") GodotMethod!(void, Transform2D) setTransform; 57 } 58 /// 59 pragma(inline, true) bool opEquals(in CameraFeed other) const 60 { return _godot_object.ptr is other._godot_object.ptr; } 61 /// 62 pragma(inline, true) typeof(null) opAssign(typeof(null) n) 63 { _godot_object.ptr = n; return null; } 64 /// 65 pragma(inline, true) bool opEquals(typeof(null) n) const 66 { return _godot_object.ptr is n; } 67 /// 68 size_t toHash() const @trusted { return cast(size_t)_godot_object.ptr; } 69 mixin baseCasts; 70 /// Construct a new instance of CameraFeed. 71 /// Note: use `memnew!CameraFeed` instead. 72 static CameraFeed _new() 73 { 74 static godot_class_constructor constructor; 75 if(constructor is null) constructor = _godot_api.godot_get_class_constructor("CameraFeed"); 76 if(constructor is null) return typeof(this).init; 77 return cast(CameraFeed)(constructor()); 78 } 79 @disable new(size_t s); 80 /// 81 enum FeedDataType : int 82 { 83 /** 84 No image set for the feed. 85 */ 86 feedNoimage = 0, 87 /** 88 Feed supplies RGB images. 89 */ 90 feedRgb = 1, 91 /** 92 Feed supplies YCbCr images that need to be converted to RGB. 93 */ 94 feedYcbcr = 2, 95 /** 96 Feed supplies separate Y and CbCr images that need to be combined and converted to RGB. 97 */ 98 feedYcbcrSep = 3, 99 } 100 /// 101 enum FeedPosition : int 102 { 103 /** 104 Unspecified position. 105 */ 106 feedUnspecified = 0, 107 /** 108 Camera is mounted at the front of the device. 109 */ 110 feedFront = 1, 111 /** 112 Camera is mounted at the back of the device. 113 */ 114 feedBack = 2, 115 } 116 /// 117 enum Constants : int 118 { 119 feedNoimage = 0, 120 feedUnspecified = 0, 121 feedFront = 1, 122 feedRgb = 1, 123 feedYcbcr = 2, 124 feedBack = 2, 125 feedYcbcrSep = 3, 126 } 127 /** 128 129 */ 130 void _allocateTexture(in long width, in long height, in long format, in long texture_type, in long data_type) 131 { 132 Array _GODOT_args = Array.make(); 133 _GODOT_args.append(width); 134 _GODOT_args.append(height); 135 _GODOT_args.append(format); 136 _GODOT_args.append(texture_type); 137 _GODOT_args.append(data_type); 138 String _GODOT_method_name = String("_allocate_texture"); 139 this.callv(_GODOT_method_name, _GODOT_args); 140 } 141 /** 142 143 */ 144 void _setRgbImg(Image rgb_img) 145 { 146 Array _GODOT_args = Array.make(); 147 _GODOT_args.append(rgb_img); 148 String _GODOT_method_name = String("_set_RGB_img"); 149 this.callv(_GODOT_method_name, _GODOT_args); 150 } 151 /** 152 153 */ 154 void _setYcbcrImg(Image ycbcr_img) 155 { 156 Array _GODOT_args = Array.make(); 157 _GODOT_args.append(ycbcr_img); 158 String _GODOT_method_name = String("_set_YCbCr_img"); 159 this.callv(_GODOT_method_name, _GODOT_args); 160 } 161 /** 162 163 */ 164 void _setYcbcrImgs(Image y_img, Image cbcr_img) 165 { 166 Array _GODOT_args = Array.make(); 167 _GODOT_args.append(y_img); 168 _GODOT_args.append(cbcr_img); 169 String _GODOT_method_name = String("_set_YCbCr_imgs"); 170 this.callv(_GODOT_method_name, _GODOT_args); 171 } 172 /** 173 174 */ 175 void _setName(in String name) 176 { 177 Array _GODOT_args = Array.make(); 178 _GODOT_args.append(name); 179 String _GODOT_method_name = String("_set_name"); 180 this.callv(_GODOT_method_name, _GODOT_args); 181 } 182 /** 183 184 */ 185 void _setPosition(in long position) 186 { 187 Array _GODOT_args = Array.make(); 188 _GODOT_args.append(position); 189 String _GODOT_method_name = String("_set_position"); 190 this.callv(_GODOT_method_name, _GODOT_args); 191 } 192 /** 193 Returns the unique ID for this feed. 194 */ 195 long getId() const 196 { 197 checkClassBinding!(typeof(this))(); 198 return ptrcall!(long)(GDNativeClassBinding.getId, _godot_object); 199 } 200 /** 201 Returns the camera's name. 202 */ 203 String getName() const 204 { 205 checkClassBinding!(typeof(this))(); 206 return ptrcall!(String)(GDNativeClassBinding.getName, _godot_object); 207 } 208 /** 209 Returns the position of camera on the device. 210 */ 211 CameraFeed.FeedPosition getPosition() const 212 { 213 checkClassBinding!(typeof(this))(); 214 return ptrcall!(CameraFeed.FeedPosition)(GDNativeClassBinding.getPosition, _godot_object); 215 } 216 /** 217 218 */ 219 Transform2D getTransform() const 220 { 221 checkClassBinding!(typeof(this))(); 222 return ptrcall!(Transform2D)(GDNativeClassBinding.getTransform, _godot_object); 223 } 224 /** 225 226 */ 227 bool isActive() const 228 { 229 checkClassBinding!(typeof(this))(); 230 return ptrcall!(bool)(GDNativeClassBinding.isActive, _godot_object); 231 } 232 /** 233 234 */ 235 void setActive(in bool active) 236 { 237 checkClassBinding!(typeof(this))(); 238 ptrcall!(void)(GDNativeClassBinding.setActive, _godot_object, active); 239 } 240 /** 241 242 */ 243 void setTransform(in Transform2D transform) 244 { 245 checkClassBinding!(typeof(this))(); 246 ptrcall!(void)(GDNativeClassBinding.setTransform, _godot_object, transform); 247 } 248 /** 249 If `true`, the feed is active. 250 */ 251 @property bool feedIsActive() 252 { 253 return isActive(); 254 } 255 /// ditto 256 @property void feedIsActive(bool v) 257 { 258 setActive(v); 259 } 260 /** 261 The transform applied to the camera's image. 262 */ 263 @property Transform2D feedTransform() 264 { 265 return getTransform(); 266 } 267 /// ditto 268 @property void feedTransform(Transform2D v) 269 { 270 setTransform(v); 271 } 272 }