summaryrefslogtreecommitdiffstats
path: root/src/core/hle/service/cam/cam.h
blob: 34a9c84793ec105342e9ed03531060f70ec1abce (plain) (blame)
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
// Copyright 2015 Citra Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.

#pragma once

#include "common/common_funcs.h"
#include "common/common_types.h"
#include "common/swap.h"
#include "core/hle/kernel/kernel.h"
#include "core/hle/service/service.h"

namespace Service {
namespace CAM {

enum CameraIndex {
    OuterRightCamera = 0,
    InnerCamera = 1,
    OuterLeftCamera = 2,

    NumCameras = 3,
};

enum class Effect : u8 {
    None = 0,
    Mono = 1,
    Sepia = 2,
    Negative = 3,
    Negafilm = 4,
    Sepia01 = 5,
};

enum class Flip : u8 {
    None = 0,
    Horizontal = 1,
    Vertical = 2,
    Reverse = 3,
};

enum class Size : u8 {
    VGA = 0,
    QVGA = 1,
    QQVGA = 2,
    CIF = 3,
    QCIF = 4,
    DS_LCD = 5,
    DS_LCDx4 = 6,
    CTR_TOP_LCD = 7,
    CTR_BOTTOM_LCD = QVGA,
};

enum class FrameRate : u8 {
    Rate_15 = 0,
    Rate_15_To_5 = 1,
    Rate_15_To_2 = 2,
    Rate_10 = 3,
    Rate_8_5 = 4,
    Rate_5 = 5,
    Rate_20 = 6,
    Rate_20_To_5 = 7,
    Rate_30 = 8,
    Rate_30_To_5 = 9,
    Rate_15_To_10 = 10,
    Rate_20_To_10 = 11,
    Rate_30_To_10 = 12,
};

enum class ShutterSoundType : u8 {
    Normal = 0,
    Movie = 1,
    MovieEnd = 2,
};

enum class WhiteBalance : u8 {
    BalanceAuto = 0,
    Balance3200K = 1,
    Balance4150K = 2,
    Balance5200K = 3,
    Balance6000K = 4,
    Balance7000K = 5,
    BalanceMax = 6,
    BalanceNormal = BalanceAuto,
    BalanceTungsten = Balance3200K,
    BalanceWhiteFluorescentLight = Balance4150K,
    BalanceDaylight = Balance5200K,
    BalanceCloudy = Balance6000K,
    BalanceHorizon = Balance6000K,
    BalanceShade = Balance7000K,
};

enum class PhotoMode : u8 {
    Normal = 0,
    Portrait = 1,
    Landscape = 2,
    Nightview = 3,
    Letter0 = 4,
};

enum class LensCorrection : u8 {
    Off = 0,
    On70 = 1,
    On90 = 2,
    Dark = Off,
    Normal = On70,
    Bright = On90,
};

enum class Contrast : u8 {
    Pattern01 = 1,
    Pattern02 = 2,
    Pattern03 = 3,
    Pattern04 = 4,
    Pattern05 = 5,
    Pattern06 = 6,
    Pattern07 = 7,
    Pattern08 = 8,
    Pattern09 = 9,
    Pattern10 = 10,
    Pattern11 = 11,
    Low = Pattern05,
    Normal = Pattern06,
    High = Pattern07,
};

enum class OutputFormat : u8 {
    YUV422 = 0,
    RGB565 = 1,
};

/// Stereo camera calibration data.
struct StereoCameraCalibrationData {
    u8 isValidRotationXY; ///< Bool indicating whether the X and Y rotation data is valid.
    INSERT_PADDING_BYTES(3);
    float_le scale;        ///< Scale to match the left camera image with the right.
    float_le rotationZ;    ///< Z axis rotation to match the left camera image with the right.
    float_le translationX; ///< X axis translation to match the left camera image with the right.
    float_le translationY; ///< Y axis translation to match the left camera image with the right.
    float_le rotationX;    ///< X axis rotation to match the left camera image with the right.
    float_le rotationY;    ///< Y axis rotation to match the left camera image with the right.
    float_le angleOfViewRight; ///< Right camera angle of view.
    float_le angleOfViewLeft;  ///< Left camera angle of view.
    float_le distanceToChart;  ///< Distance between cameras and measurement chart.
    float_le distanceCameras;  ///< Distance between left and right cameras.
    s16_le imageWidth;         ///< Image width.
    s16_le imageHeight;        ///< Image height.
    INSERT_PADDING_BYTES(16);
};
static_assert(sizeof(StereoCameraCalibrationData) == 64,
              "StereoCameraCalibrationData structure size is wrong");

/**
 * Resolution parameters for the camera.
 * The native resolution of 3DS camera is 640 * 480. The captured image will be cropped in the
 * region [crop_x0, crop_x1] * [crop_y0, crop_y1], and then scaled to size width * height as the
 * output image. Note that all cropping coordinates are inclusive.
 */
struct Resolution {
    u16 width;
    u16 height;
    u16 crop_x0;
    u16 crop_y0;
    u16 crop_x1;
    u16 crop_y1;
};

struct PackageParameterWithoutContext {
    u8 camera_select;
    s8 exposure;
    WhiteBalance white_balance;
    s8 sharpness;
    bool auto_exposure;
    bool auto_white_balance;
    FrameRate frame_rate;
    PhotoMode photo_mode;
    Contrast contrast;
    LensCorrection lens_correction;
    bool noise_filter;
    u8 padding;
    s16 auto_exposure_window_x;
    s16 auto_exposure_window_y;
    s16 auto_exposure_window_width;
    s16 auto_exposure_window_height;
    s16 auto_white_balance_window_x;
    s16 auto_white_balance_window_y;
    s16 auto_white_balance_window_width;
    s16 auto_white_balance_window_height;
};

static_assert(sizeof(PackageParameterWithoutContext) == 28,
              "PackageParameterCameraWithoutContext structure size is wrong");

struct PackageParameterWithContext {
    u8 camera_select;
    u8 context_select;
    Flip flip;
    Effect effect;
    Size size;
    INSERT_PADDING_BYTES(3);

    Resolution GetResolution();
};

static_assert(sizeof(PackageParameterWithContext) == 8,
              "PackageParameterWithContext structure size is wrong");

struct PackageParameterWithContextDetail {
    u8 camera_select;
    u8 context_select;
    Flip flip;
    Effect effect;
    Resolution resolution;

    Resolution GetResolution() {
        return resolution;
    }
};

static_assert(sizeof(PackageParameterWithContextDetail) == 16,
              "PackageParameterWithContextDetail structure size is wrong");

/**
 * Starts capturing at the selected port.
 *  Inputs:
 *      0: 0x00010040
 *      1: u8 selected port
 *  Outputs:
 *      0: 0x00010040
 *      1: ResultCode
 */
void StartCapture(Service::Interface* self);

/**
 * Stops capturing from the selected port.
 *  Inputs:
 *      0: 0x00020040
 *      1: u8 selected port
 *  Outputs:
 *      0: 0x00020040
 *      1: ResultCode
 */
void StopCapture(Service::Interface* self);

/**
 * Gets whether the selected port is currently capturing.
 *  Inputs:
 *      0: 0x00030040
 *      1: u8 selected port
 *  Outputs:
 *      0: 0x00030080
 *      1: ResultCode
 *      2: 0 if not capturing, 1 if capturing
 */
void IsBusy(Service::Interface* self);

/**
 * Clears the buffer of selected ports.
 *  Inputs:
 *      0: 0x00040040
 *      1: u8 selected port
 *  Outputs:
 *      0: 0x00040040
 *      2: ResultCode
 */
void ClearBuffer(Service::Interface* self);

/**
 * Unknown
 *  Inputs:
 *      0: 0x00050040
 *      1: u8 selected port
 *  Outputs:
 *      0: 0x00050042
 *      1: ResultCode
 *      2: Descriptor: Handle
 *      3: Event handle
 */
void GetVsyncInterruptEvent(Service::Interface* self);

/**
 * Unknown
 *  Inputs:
 *      0: 0x00060040
 *      1: u8 selected port
 *  Outputs:
 *      0: 0x00060042
 *      1: ResultCode
 *      2: Descriptor: Handle
 *      3: Event handle
 */
void GetBufferErrorInterruptEvent(Service::Interface* self);

/**
 * Sets the target buffer to receive a frame of image data and starts the transfer. Each camera
 * port has its own event to signal the end of the transfer.
 *
 *  Inputs:
 *      0: 0x00070102
 *      1: Destination address in calling process
 *      2: u8 selected port
 *      3: Image size (in bytes)
 *      4: u16 Transfer unit size (in bytes)
 *      5: Descriptor: Handle
 *      6: Handle to destination process
 *  Outputs:
 *      0: 0x00070042
 *      1: ResultCode
 *      2: Descriptor: Handle
 *      3: Handle to event signalled when transfer finishes
 */
void SetReceiving(Service::Interface* self);

/**
 * Gets whether the selected port finished receiving a frame.
 *  Inputs:
 *      0: 0x00080040
 *      1: u8 selected port
 *  Outputs:
 *      0: 0x00080080
 *      1: ResultCode
 *      2: 0 if not finished, 1 if finished
 */
void IsFinishedReceiving(Service::Interface* self);

/**
 * Sets the number of lines the buffer contains.
 *  Inputs:
 *      0: 0x00090100
 *      1: u8 selected port
 *      2: u16 Number of lines to transfer
 *      3: u16 Width
 *      4: u16 Height
 *  Outputs:
 *      0: 0x00090040
 *      1: ResultCode
 * @todo figure out how the "buffer" actually works.
 */
void SetTransferLines(Service::Interface* self);

/**
 * Gets the maximum number of lines that fit in the buffer
 *  Inputs:
 *      0: 0x000A0080
 *      1: u16 Width
 *      2: u16 Height
 *  Outputs:
 *      0: 0x000A0080
 *      1: ResultCode
 *      2: Maximum number of lines that fit in the buffer
 * @todo figure out how the "buffer" actually works.
 */
void GetMaxLines(Service::Interface* self);

/**
 * Sets the number of bytes the buffer contains.
 *  Inputs:
 *      0: 0x000B0100
 *      1: u8 selected port
 *      2: u16 Number of bytes to transfer
 *      3: u16 Width
 *      4: u16 Height
 *  Outputs:
 *      0: 0x000B0040
 *      1: ResultCode
 * @todo figure out how the "buffer" actually works.
 */
void SetTransferBytes(Service::Interface* self);

/**
 * Gets the number of bytes to the buffer contains.
 *  Inputs:
 *      0: 0x000C0040
 *      1: u8 selected port
 *  Outputs:
 *      0: 0x000C0080
 *      1: ResultCode
 *      2: The number of bytes the buffer contains
 * @todo figure out how the "buffer" actually works.
 */
void GetTransferBytes(Service::Interface* self);

/**
 * Gets the maximum number of bytes that fit in the buffer.
 *  Inputs:
 *      0: 0x000D0080
 *      1: u16 Width
 *      2: u16 Height
 *  Outputs:
 *      0: 0x000D0080
 *      1: ResultCode
 *      2: Maximum number of bytes that fit in the buffer
 * @todo figure out how the "buffer" actually works.
 */
void GetMaxBytes(Service::Interface* self);

/**
 * Enables or disables trimming.
 *  Inputs:
 *      0: 0x000E0080
 *      1: u8 selected port
 *      2: u8 bool Enable trimming if true
 *  Outputs:
 *      0: 0x000E0040
 *      1: ResultCode
 */
void SetTrimming(Service::Interface* self);

/**
 * Gets whether trimming is enabled.
 *  Inputs:
 *      0: 0x000F0040
 *      1: u8 selected port
 *  Outputs:
 *      0: 0x000F0080
 *      1: ResultCode
 *      2: u8 bool Enable trimming if true
 */
void IsTrimming(Service::Interface* self);

/**
 * Sets the position to trim.
 *  Inputs:
 *      0: 0x00100140
 *      1: u8 selected port
 *      2: x start
 *      3: y start
 *      4: x end (exclusive)
 *      5: y end (exclusive)
 *  Outputs:
 *      0: 0x00100040
 *      1: ResultCode
 */
void SetTrimmingParams(Service::Interface* self);

/**
 * Gets the position to trim.
 *  Inputs:
 *      0: 0x00110040
 *      1: u8 selected port
 *
 *  Outputs:
 *      0: 0x00110140
 *      1: ResultCode
 *      2: x start
 *      3: y start
 *      4: x end (exclusive)
 *      5: y end (exclusive)
 */
void GetTrimmingParams(Service::Interface* self);

/**
 * Sets the position to trim by giving the width and height. The trimming window is always at the
 * center.
 *  Inputs:
 *      0: 0x00120140
 *      1: u8 selected port
 *      2: s16 Trim width
 *      3: s16 Trim height
 *      4: s16 Camera width
 *      5: s16 Camera height
 *  Outputs:
 *      0: 0x00120040
 *      1: ResultCode
 */
void SetTrimmingParamsCenter(Service::Interface* self);

/**
 * Selects up to two physical cameras to enable.
 *  Inputs:
 *      0: 0x00130040
 *      1: u8 selected camera
 *  Outputs:
 *      0: 0x00130040
 *      1: ResultCode
 */
void Activate(Service::Interface* self);

/**
 * Switches the context of camera settings.
 *  Inputs:
 *      0: 0x00140080
 *      1: u8 selected camera
 *      2: u8 selected context
 *  Outputs:
 *      0: 0x00140040
 *      1: ResultCode
 */
void SwitchContext(Service::Interface* self);

/**
 * Sets flipping of images
 *  Inputs:
 *      0: 0x001D00C0
 *      1: u8 selected camera
 *      2: u8 Type of flipping to perform (`Flip` enum)
 *      3: u8 selected context
 *  Outputs:
 *      0: 0x001D0040
 *      1: ResultCode
 */
void FlipImage(Service::Interface* self);

/**
 * Sets camera resolution from custom parameters. For more details see the Resolution struct.
 *  Inputs:
 *      0: 0x001E0200
 *      1: u8 selected camera
 *      2: width
 *      3: height
 *      4: crop x0
 *      5: crop y0
 *      6: crop x1
 *      7: crop y1
 *      8: u8 selected context
 *  Outputs:
 *      0: 0x001E0040
 *      1: ResultCode
 */
void SetDetailSize(Service::Interface* self);

/**
 * Sets camera resolution from preset resolution parameters.
 *  Inputs:
 *      0: 0x001F00C0
 *      1: u8 selected camera
 *      2: u8 Camera frame resolution (`Size` enum)
 *      3: u8 selected context
 *  Outputs:
 *      0: 0x001F0040
 *      1: ResultCode
 */
void SetSize(Service::Interface* self);

/**
 * Sets camera framerate.
 *  Inputs:
 *      0: 0x00200080
 *      1: u8 selected camera
 *      2: u8 Camera framerate (`FrameRate` enum)
 *  Outputs:
 *      0: 0x00200040
 *      1: ResultCode
 */
void SetFrameRate(Service::Interface* self);

/**
 * Sets effect on the output image
 *  Inputs:
 *      0: 0x002200C0
 *      1: u8 selected camera
 *      2: u8 image effect (`Effect` enum)
 *      3: u8 selected context
 *  Outputs:
 *      0: 0x00220040
 *      1: ResultCode
 */
void SetEffect(Service::Interface* self);

/**
 * Sets format of the output image
 *  Inputs:
 *      0: 0x002500C0
 *      1: u8 selected camera
 *      2: u8 image format (`OutputFormat` enum)
 *      3: u8 selected context
 *  Outputs:
 *      0: 0x00250040
 *      1: ResultCode
 */
void SetOutputFormat(Service::Interface* self);

/**
 * Synchronizes the V-Sync timing of two cameras.
 *  Inputs:
 *      0: 0x00290080
 *      1: u8 selected camera 1
 *      2: u8 selected camera 2
 *  Outputs:
 *      0: 0x00280040
 *      1: ResultCode
 */
void SynchronizeVsyncTiming(Service::Interface* self);

/**
 * Returns calibration data relating the outside cameras to eachother, for use in AR applications.
 *
 *  Inputs:
 *      0: 0x002B0000
 *  Outputs:
 *      0: 0x002B0440
 *      1: ResultCode
 *      2-17: `StereoCameraCalibrationData` structure with calibration values
 */
void GetStereoCameraCalibrationData(Service::Interface* self);

/**
 * Batch-configures context-free settings.
 *
 *  Inputs:
 *      0: 0x003302C0
 *      1-7: struct PachageParameterWithoutContext
 *      8-11: unused
 *  Outputs:
 *      0: 0x00330040
 *      1: ResultCode
 */
void SetPackageParameterWithoutContext(Service::Interface* self);

/**
 * Batch-configures context-related settings with preset resolution parameters.
 *
 *  Inputs:
 *      0: 0x00340140
 *      1-2: struct PackageParameterWithContext
 *      3-5: unused
 *  Outputs:
 *      0: 0x00340040
 *      1: ResultCode
 */
void SetPackageParameterWithContext(Service::Interface* self);

/**
 * Batch-configures context-related settings with custom resolution parameters
 *
 *  Inputs:
 *      0: 0x003501C0
 *      1-4: struct PackageParameterWithContextDetail
 *      5-7: unused
 *  Outputs:
 *      0: 0x00350040
 *      1: ResultCode
 */
void SetPackageParameterWithContextDetail(Service::Interface* self);

/**
 * Unknown
 *  Inputs:
 *      0: 0x00360000
 *  Outputs:
 *      0: 0x00360080
 *      1: ResultCode
 *      2: ?
 */
void GetSuitableY2rStandardCoefficient(Service::Interface* self);

/**
 * Unknown
 *  Inputs:
 *      0: 0x00380040
 *      1: u8 Sound ID
 *  Outputs:
 *      0: 0x00380040
 *      1: ResultCode
 */
void PlayShutterSound(Service::Interface* self);

/**
 * Initializes the camera driver. Must be called before using other functions.
 *  Inputs:
 *      0: 0x00390000
 *  Outputs:
 *      0: 0x00390040
 *      1: ResultCode
 */
void DriverInitialize(Service::Interface* self);

/**
 * Shuts down the camera driver.
 *  Inputs:
 *      0: 0x003A0000
 *  Outputs:
 *      0: 0x003A0040
 *      1: ResultCode
 */
void DriverFinalize(Service::Interface* self);

/// Initialize CAM service(s)
void Init();

/// Shutdown CAM service(s)
void Shutdown();

} // namespace CAM
} // namespace Service