/
CameraReport.java
798 lines (707 loc) · 30.2 KB
/
CameraReport.java
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
/* Utility static class with constants and methods for presenting camera device
* properties using the camera2 API framework. Converts values returned from
* instances of various forms of CameraMetadata into their human-readable
* labels.
*
* E.g., converts the Integer value 2 returned by a call to
* captureResult.get(CaptureResult.CONTROL_AE_STATE) into the string
* "CONVERGED".
*
* This class works based on mapping values to strings based on their "context."
* The context is an Android domain name string, such as
* "android.control.aeMode" or "android.graphics.ImageFormat".
* These context can be generated from a .getName() call on a CaptureRequest.Key,
* CaptureResult.Key, or CameraCharacteristics.Key.
*
* Currently up-to-date to API 22.
*
* The main function is cameraConstantStringer(context, value), which returns a
* human-readable interpretation of the value. (It "stringifies" the value.)
* This will return a legible string for any type of value generated by a
* metadata.getKey(KEY) call and the correct context.
*
* There are other useful functions which will write a JSON file which reports
* the contents of a metadata structure. This is particularly useful when
* applied to a camera device's CameraCharacteristics object, as it will report
* the capabilities of the device for reference.
*
*
* Rob Sumner
* rcsumner@ucsc.edu
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.devcam;
import android.content.Context;
import android.hardware.camera2.CameraCharacteristics;
import android.hardware.camera2.CaptureRequest;
import android.hardware.camera2.CaptureResult;
import android.media.MediaScannerConnection;
import android.net.Uri;
import android.util.JsonWriter;
import android.util.Log;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.lang.reflect.Array;
import java.text.DecimalFormat;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
final public class CameraReport {
final static public String CAMERA_REPORT_TAG = "CameraReport";
static final public Map<String, Map<Integer,String>> sContextMap =
new HashMap<String,Map<Integer,String>>();
// class initialization block, to populate the table of constants
static {
Map<Integer,String> subMap = new HashMap<Integer,String>();
subMap.put(0,"OFF");
subMap.put(1,"FAST");
subMap.put(2,"HIGH_QUALITY");
sContextMap.put("android.colorCorrection.availableAberrationModes",subMap);
sContextMap.put("android.colorCorrection.aberrationMode",subMap);
subMap = new HashMap<Integer,String>();
subMap.put(0,"TRANSFORM_MATRIX");
subMap.put(1,"FAST");
subMap.put(2,"HIGH_QUALITY");
sContextMap.put("android.colorCorrection.mode",subMap);
subMap = new HashMap<Integer,String>();
subMap.put(0,"OFF");
subMap.put(1,"50HZ");
subMap.put(2,"60HZ");
subMap.put(3,"AUTO");
sContextMap.put("android.control.aeAvailableAntibandingModes",subMap);
sContextMap.put("android.control.aeAntibandingMode",subMap);
subMap = new HashMap<Integer,String>();
subMap.put(0,"OFF");
subMap.put(1,"ON");
subMap.put(2,"ON_AUTO_FLASH");
subMap.put(3,"ON_ALWAYS_FLASH");
subMap.put(4,"ON_AUTO_FLASH_REDEYE");
sContextMap.put("android.control.aeAvailableModes",subMap);
sContextMap.put("android.control.aeMode",subMap);
subMap = new HashMap<Integer,String>();
subMap.put(0,"IDLE");
subMap.put(1,"START");
subMap.put(2,"CANCEL");
sContextMap.put("android.control.aePrecaptureTrigger",subMap);
subMap = new HashMap<Integer,String>();
subMap.put(0,"INACTIVE");
subMap.put(1,"SEARCHING");
subMap.put(2,"CONVERGED");
subMap.put(3,"LOCKED");
subMap.put(4,"FLASH_REQUIRED");
subMap.put(5,"PRECAPTURE");
sContextMap.put("android.control.aeState",subMap);
subMap = new HashMap<Integer,String>();
subMap.put(0,"OFF");
subMap.put(1,"AUTO");
subMap.put(2,"MACRO");
subMap.put(3,"CONTINUOUS_VIDEO");
subMap.put(4,"CONTINUOUS_PICTURE");
subMap.put(5,"EDOF");
sContextMap.put("android.control.afAvailableModes",subMap);
sContextMap.put("android.control.afMode",subMap);
subMap = new HashMap<Integer,String>();
subMap.put(0,"IDLE");
subMap.put(1,"START");
subMap.put(2,"CANCEL");
sContextMap.put("android.control.afTrigger",subMap);
subMap = new HashMap<Integer,String>();
subMap.put(0,"INACTIVE");
subMap.put(1,"PASSIVE_SCAN");
subMap.put(2,"PASSIVE_FOCUSED");
subMap.put(3,"ACTIVE_SCAN");
subMap.put(4,"FOCUSED_LOCKED");
subMap.put(5,"NOT_FOCUSED_LOCKED");
subMap.put(6,"PASSIVE_UNFOCUSED");
sContextMap.put("android.control.afState",subMap);
subMap = new HashMap<Integer,String>();
subMap.put(0,"INACTIVE");
subMap.put(1,"SEARCHING");
subMap.put(2,"CONVERGED");
subMap.put(3,"LOCKED");
sContextMap.put("android.control.awbState",subMap);
subMap = new HashMap<Integer,String>();
subMap.put(0,"OFF");
subMap.put(1,"AUTO");
subMap.put(2,"INCANDESCENT");
subMap.put(3,"FLOURESCENT");
subMap.put(4,"WARM_FLOURESCENT");
subMap.put(5,"DAYLIGHT");
subMap.put(6,"CLOUDY_DAYLIGHT");
subMap.put(7,"TWILIGHT");
subMap.put(8,"SHADE");
sContextMap.put("android.control.awbAvailableModes",subMap);
sContextMap.put("android.control.awbMode",subMap);
subMap = new HashMap<Integer,String>();
subMap.put(0,"CUSTOM");
subMap.put(1,"PREVIEW");
subMap.put(2,"STILL_CAPTURE");
subMap.put(3,"VIDEO_RECORD");
subMap.put(4,"VIDEO_SNAPSHOT");
subMap.put(5,"ZERO_SHUTTER_LAG");
subMap.put(6,"MANUAL");
sContextMap.put("android.control.captureIntent",subMap);
subMap = new HashMap<Integer,String>();
subMap.put(0,"OFF");
subMap.put(1,"MONO");
subMap.put(2,"NEGATIVE");
subMap.put(3,"SOLARIZE");
subMap.put(4,"SEPIA");
subMap.put(5,"POSTERIZE");
subMap.put(6,"WHITEBOARD");
subMap.put(7,"BLACKBOARD");
subMap.put(8,"AQUA");
sContextMap.put("android.control.availableEffects",subMap);
sContextMap.put("android.control.effectsMode",subMap);
subMap = new HashMap<Integer,String>();
subMap.put(0,"OFF");
subMap.put(1,"AUTO");
subMap.put(2,"USE_SCENE_MODE");
subMap.put(3,"OFF_KEEP_STATE");
sContextMap.put("android.control.mode",subMap);
subMap = new HashMap<Integer,String>();
subMap.put(0,"DISABLED");
subMap.put(1,"FACE_PRIORITY");
subMap.put(2,"ACTION");
subMap.put(3,"PORTRAIT");
subMap.put(4,"LANDSCAPE");
subMap.put(5,"NIGHT");
subMap.put(6,"NIGHT_PORTRAIT");
subMap.put(7,"THEATRE");
subMap.put(8,"BEACH");
subMap.put(9,"SNOW");
subMap.put(10,"SUNSET");
subMap.put(11,"STEADYPHOTO");
subMap.put(12,"FIREWORKS");
subMap.put(13,"SPORTS");
subMap.put(14,"PARTY");
subMap.put(15,"CANDLELIGHT");
subMap.put(16,"BARCODE");
subMap.put(17,"HIGH_SPEED_VIDEO");
subMap.put(18,"HDR");
sContextMap.put("android.control.availableSceneModes",subMap);
sContextMap.put("android.control.sceneMode",subMap);
subMap = new HashMap<Integer,String>();
subMap.put(0,"OFF");
subMap.put(1,"ON");
sContextMap.put("android.control.availableVideoStabilizationModes",subMap);
sContextMap.put("android.control.videoStabilizationMode",subMap);
subMap = new HashMap<Integer,String>();
subMap.put(0,"OFF");
subMap.put(1,"FAST");
subMap.put(2,"HIGH_QUALITY");
subMap.put(3,"ZERO_SHUTTER_LAG");
sContextMap.put("android.edge.availableEdgeModes",subMap);
sContextMap.put("android.edge.mode",subMap);
subMap = new HashMap<Integer,String>();
subMap.put(0,"OFF");
subMap.put(1,"SINGLE");
subMap.put(2,"TORCH");
sContextMap.put("android.flash.mode",subMap);
subMap = new HashMap<Integer,String>();
subMap.put(0,"UNAVAILABLE");
subMap.put(1,"CHARGING");
subMap.put(2,"READY");
subMap.put(3,"FIRED");
subMap.put(4,"PARTIAL");
sContextMap.put("android.flash.state",subMap);
subMap = new HashMap<Integer,String>();
subMap.put(0,"OFF");
subMap.put(1,"FAST");
subMap.put(2,"HIGH_QUALITY");
sContextMap.put("android.hotPixel.availableHotPixelModes",subMap);
sContextMap.put("android.hotPixel.mode",subMap);
subMap = new HashMap<Integer,String>();
subMap.put(0,"LIMITED");
subMap.put(1,"FULL");
subMap.put(2,"LEGACY");
sContextMap.put("android.info.supportedHardwareLevel",subMap);
subMap = new HashMap<Integer,String>();
subMap.put(0,"FRONT");
subMap.put(1,"BACK");
subMap.put(2,"EXTERNAL");
sContextMap.put("android.lens.facing",subMap);
subMap = new HashMap<Integer,String>();
subMap.put(0,"OFF");
subMap.put(1,"ON");
sContextMap.put("android.lens.info.availableOpticalStabilization",subMap);
sContextMap.put("android.lens.opticalStabilizationMode",subMap);
subMap = new HashMap<Integer,String>();
subMap.put(0,"UNCALIBRATED");
subMap.put(1,"APPROXIMATE");
subMap.put(2,"CALIBRATED");
sContextMap.put("android.lens.info.focusDistanceCalibration",subMap);
subMap = new HashMap<Integer,String>();
subMap.put(0,"STATIONARY");
subMap.put(1,"MOVING");
sContextMap.put("android.lens.state",subMap);
subMap = new HashMap<Integer,String>();
subMap.put(0,"OFF");
subMap.put(1,"FAST");
subMap.put(2,"HIGH_QUALITY");
subMap.put(3,"MINIMAL");
subMap.put(4,"ZERO_SHUTTER_LAG");
sContextMap.put("android.noiseReduction.availableNoiseReductionModes",subMap);
sContextMap.put("android.noiseReduction.mode",subMap);
subMap = new HashMap<Integer,String>();
subMap.put(0,"BACKWARDS_COMPATIBLE");
subMap.put(1,"MANUAL_SENSOR");
subMap.put(2,"MANUAL_POST_PROCESSING");
subMap.put(3,"RAW");
subMap.put(4,"PRIVATE_REPROCESSING");
subMap.put(5,"READ_SENSOR_SETTINGS");
subMap.put(6,"BURST_CAPTURE");
subMap.put(7,"YUV_REPROCESSING");
subMap.put(8,"DEPTH_OUTPUT");
subMap.put(9,"CONSTRAINED_HIGH_SPEED_VIDEO");
sContextMap.put("android.request.availableCapabilities",subMap);
subMap = new HashMap<Integer,String>();
subMap.put(0,"CENTER_ONLY");
subMap.put(1,"FREEFORM");
sContextMap.put("android.scaler.croppingType",subMap);
subMap = new HashMap<Integer,String>();
subMap.put(0,"OFF");
subMap.put(1,"SOLID_COLOR");
subMap.put(2,"COLOR_BARS");
subMap.put(3,"COLOR_BARS_FADE_TO_GRAY");
subMap.put(4,"PN9");
subMap.put(5,"CUSTOM1");
sContextMap.put("android.sensor.availableTestPatternModes",subMap);
sContextMap.put("android.sensor.testPatternMode",subMap);
subMap = new HashMap<Integer,String>();
subMap.put(0,"RGGB");
subMap.put(1,"GRBG");
subMap.put(2,"GBRG");
subMap.put(3,"BGGR");
subMap.put(4,"RGB");
sContextMap.put("android.sensor.info.colorFilterArrangement",subMap);
subMap = new HashMap<Integer,String>();
subMap.put(0,"UNKNOWN");
subMap.put(1,"REALTIME");
sContextMap.put("android.sensor.info.timestampSource",subMap);
subMap = new HashMap<Integer,String>();
subMap.put(10,"CLOUDY_WEATHER");
subMap.put(14,"COOL_WHITE_FLOURESCENT");
subMap.put(23,"D50");
subMap.put(20,"D55");
subMap.put(21,"D65");
subMap.put(22,"D75");
subMap.put(1,"DAYLIGHT");
subMap.put(12,"DAYLIGHT_FLOURESCENT");
subMap.put(13,"DAY_WHITE_FLOURESCENT");
subMap.put(9,"FINE_WEATHER");
subMap.put(4,"FLASH");
subMap.put(2,"FLOURESCENT");
subMap.put(24,"ISO_STUDIO_TUNGSTEN");
subMap.put(11,"SHADE");
subMap.put(17,"STANDARD_A");
subMap.put(18,"STANDARD_B");
subMap.put(19,"STANDARD_C");
subMap.put(3,"TUNGSTEN");
subMap.put(15,"WHITE_FLOURESCENT");
sContextMap.put("android.sensor.referenceIlluminant1",subMap);
sContextMap.put("android.sensor.referenceIlluminant2",subMap);
subMap = new HashMap<Integer,String>();
subMap.put(0,"OFF");
subMap.put(1,"FAST");
subMap.put(2,"HIGH_QUALITY");
sContextMap.put("android.shading.mode",subMap);
subMap = new HashMap<Integer,String>();
subMap.put(0,"OFF");
subMap.put(1,"SIMPLE");
subMap.put(2,"FULL");
sContextMap.put("android.statistics.info.availableFaceDetectModes",subMap);
sContextMap.put("android.statistics.faceDetectMode",subMap);
subMap = new HashMap<Integer,String>();
subMap.put(0,"OFF");
subMap.put(1,"ON");
sContextMap.put("android.statistics.lensShadingMapMode",subMap);
subMap = new HashMap<Integer,String>();
subMap.put(0,"NONE");
subMap.put(1,"50HZ");
subMap.put(2,"60HZ");
sContextMap.put("android.statistics.sceneFlicker",subMap);
subMap = new HashMap<Integer,String>();
subMap.put(0,"CONTRAST_CURVE");
subMap.put(1,"FAST");
subMap.put(2,"HIGH_QUALITY");
subMap.put(3,"GAMMA_VALUE");
subMap.put(4,"PRESET_CURVE");
sContextMap.put("android.tonemap.availableToneMapModes",subMap);
sContextMap.put("android.tonemap.mode",subMap);
subMap = new HashMap<Integer,String>();
subMap.put(0,"SRGB");
subMap.put(1,"REC709");
sContextMap.put("android.tonemap.preset",subMap);
subMap = new HashMap<Integer,String>();
subMap.put(256,"JPEG");
subMap.put(16,"NV16");
subMap.put(17,"NV21");
subMap.put(37,"RAW10");
subMap.put(32,"RAW_SENSOR");
subMap.put(4,"RGB_565");
subMap.put(34,"PRIVATE");
subMap.put(35,"YUV_420_888");
subMap.put(39,"YUV_422_888");
subMap.put(40,"YUV_444_888");
subMap.put(38,"RAW12");
subMap.put(20,"YUY2");
subMap.put(41,"FLEX_RGB_888");
subMap.put(42,"FLEX_RGBA_8888");
subMap.put(257,"DEPTH_POINT_CLOUD");
subMap.put(842094169,"YV12");
subMap.put(1144402265,"DEPTH16");
sContextMap.put("android.graphics.ImageFormat",subMap);
}
// Utility function for turning a metadata constant into a meaningful string
// based on its context. That is, turns an integer into the right label.
// For example, cameraConstantStringer("android.lens.facing", 1) returns
// "BACK" while cameraConstantStringer("android.control.aeMode", 1) returns
// "ON".
//
// - - Parameters - -
// String contextName : Android domain string from a CameraMetadata field
// Object value : a value retrieved from some metadata.get(KEY) call
//
// Note this function is set up so that it can stringify returns from
// any metadata returned value, including arrays of labeled values, though
// some may not be meaningful, e.g. a TonemapCurve's toString() value.
static public String cameraConstantStringer(
String contextName,
Object value){
// Note this function tries to be extremely general. Values retrieved
// from a metadata.get(KEY) call are often constants as in the map
// above, but they can also have intrinsic value, like
// android.request.pipelineMaxDepth, or may be arrays of values, like
// android.control.aeAvailableTargetFpsRanges.
if (sContextMap.containsKey(contextName)){
try{
// If contextName is in the context map, there are label values
// defined for this value/array of values
Map<Integer,String> context = sContextMap.get(contextName);
//Log.v(cameraFragment.APP_TAG,"context: " + contextName);
if (value.getClass().isArray()){
int len = Array.getLength(value);
String str = "";
for (int i=0; i<len; i++){
Integer ind = (Integer) Array.get(value,i);
// This case statement just for correct useage of element-separating commas
if(i==0) {
str = str + context.get(ind);
} else {
str = str + ", " + context.get(ind);
}
}
return str;
} else
// this awkward construction is because SOME values (looking at
// you, Reference Illuminant 2!) are Byte instead of Integer.
return context.get(Integer.valueOf(value.toString()));
} catch (RuntimeException re){
re.printStackTrace();
return "Unknown value " + value ;
}
} else if(value==null){
return "Null"; // Catches bad behavior
} else {
// contextName is not in constant map, so either it is an array
// of meaningful values, or is a meaningful value itself.
if (value.getClass().isArray()){
int len = Array.getLength(value);
String str = "";
for (int i=0; i<len; i++){
Object ob = (Object) Array.get(value, i);
// If the key generated no useful string value, i.e. some default
// Object.toString() response instead of a meaningful one, return '<COMPLEX_OBJECT>'
if (ob.toString().equals(ob.getClass().getName() + '@' + Integer.toHexString(ob.hashCode()))) {
// This case statement just for correct useage of element-separating commas
if(i==0) {
str = str + "<COMPLEX_OBJECT>";
} else {
str = str + ", " + "<COMPLEX_OBJECT>";
}
} else {
// This case statement just for correct useage of element-separating commas
if(i==0) {
str = str + ob.toString();
} else {
str = str + ", " + ob.toString();
}
}
}
return str;
} else {
// If the key generated no useful string value, i.e. some default
// Object.toString() response instead of a meaningful one, return '<COMPLEX_OBJECT>'
if (value.toString().equals(value.getClass().getName() + '@' + Integer.toHexString(value.hashCode()))) {
return "<COMPLEX_OBJECT>";
} else {
return value.toString();
}
}
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// The following set of functions are all essentially the same, but
// are unfortunately needed to deal with the different types of metadata
// since none of their Key types play nicely together. I could not find a
// way to make a single general function that was cleaner than this, since
// each type is a generic of its specific Key type.
// These all write a type of metadata file to a JSON file which has a field
// for every key present in the metadata.
//
// Parameters:
// <metadata> : a CameraCharacteristics, CaptureRequest, or CaptureResult
// File file: a File to write the JSON data to.
static final void writeCharacteristicsToFile(CameraCharacteristics camChars,
File file) {
try{
FileOutputStream fostream = new FileOutputStream(file);
try{
JsonWriter writer = new JsonWriter(
new OutputStreamWriter(fostream, "UTF-8"));
writer.setIndent(" ");
writer.beginObject();
// Write the image formats the camera can produce. It's useful info.
writer.name("android.graphics.ImageFormat");
writer.value(cameraConstantStringer("android.graphics.ImageFormat",
camChars.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP).getOutputFormats()));
// For each key in the characteristics data, create a JSON field
// with its Android domain name and its stringified value.
for (CameraCharacteristics.Key<?> key : camChars.getKeys()){
String name = key.getName();
Object value = camChars.get(key);
String valueString = cameraConstantStringer(name, value);
writer.name(name);
writer.value(valueString);
}
writer.endObject();
writer.close();
} catch (FileNotFoundException fnfe) {
fnfe.printStackTrace();
} finally {
if (null!=fostream){
fostream.close();
}
}
}
catch (IOException ioe){
ioe.printStackTrace();
}
}
static final void writeCaptureRequestToFile(CaptureRequest request,
File file){
try{
FileOutputStream fostream = new FileOutputStream(file);
try{
JsonWriter writer = new JsonWriter(
new OutputStreamWriter(fostream, "UTF-8"));
writer.setIndent(" ");
writer.beginObject();
// For each key in the request data, create a JSON field
// with its Android domain name and its stringified value.
for (CaptureRequest.Key<?> key : request.getKeys()){
writer.name(key.getName());
writer.value(cameraConstantStringer(key.getName(),
request.get(key)));
}
writer.endObject();
writer.close();
} catch (FileNotFoundException fnfe) {
fnfe.printStackTrace();
} finally {
if (null!=fostream){
fostream.close();
}
}
}
catch (IOException ioe){
ioe.printStackTrace();
}
}
static final void writeCaptureResultToFile(
CaptureResult result,
File file){
try{
FileOutputStream fostream = new FileOutputStream(file);
try{
JsonWriter writer = new JsonWriter(
new OutputStreamWriter(fostream, "UTF-8"));
writer.setIndent(" ");
writer.beginObject();
// For each key in the result data, create a JSON field
// with its Android domain name and its stringified value.
for (CaptureResult.Key<?> key : result.getKeys()){
writer.name(key.getName());
writer.value(cameraConstantStringer(key.getName(),
result.get(key)));
}
writer.endObject();
writer.close();
} catch (FileNotFoundException fnfe) {
fnfe.printStackTrace();
} finally {
if (null!=fostream){
fostream.close();
}
}
}
catch (IOException ioe){
ioe.printStackTrace();
}
}
// Sometimes I want to write an array of CaptureResults to an array of
// objects in a JSON.
static void writeCaptureResultsToFile(List<CaptureResult> results,
File file){
try{
FileOutputStream fostream = new FileOutputStream(file);
try{
JsonWriter writer = new JsonWriter(
new OutputStreamWriter(fostream, "UTF-8"));
writer.setIndent(" ");
writer.beginArray();
for (int i=0; i<results.size(); i++){
CaptureResult result = results.get(i);
writer.beginObject();
List<CaptureResult.Key<?>> keys = result.getKeys();
// For each key in the results data, create a JSON field
// with its Android domain name and its stringified value.
for (CaptureResult.Key<?> key : keys){
writer.name(key.getName());
writer.value(cameraConstantStringer(key.getName(),
result.get(key)));
}
writer.endObject();
}
writer.endArray();
writer.close();
} catch (FileNotFoundException fnfe) {
fnfe.printStackTrace();
} finally {
if (null!=fostream){
fostream.close();
}
}
}
catch (IOException ioe){
ioe.printStackTrace();
}
}
// Sometimes I want to write an array of CaptureResults to an array of
// objects in a JSON, along with the associated image file names.
static void writeCaptureResultsToFile(List<CaptureResult> results,
List<String> imageFileNames,
File file){
try{
FileOutputStream fostream = new FileOutputStream(file);
try{
JsonWriter writer = new JsonWriter(
new OutputStreamWriter(fostream, "UTF-8"));
writer.setIndent(" ");
writer.beginArray();
for (int i=0; i<results.size(); i++){
CaptureResult result = results.get(i);
writer.beginObject();
writer.name("Filename");
writer.value(imageFileNames.get(i));
List<CaptureResult.Key<?>> keys = result.getKeys();
for (CaptureResult.Key<?> key : keys){
writer.name(key.getName());
writer.value(cameraConstantStringer(key.getName(),
result.get(key)));
}
writer.endObject();
}
writer.endArray();
writer.close();
} catch (FileNotFoundException fnfe) {
fnfe.printStackTrace();
} finally {
if (null!=fostream){
fostream.close();
}
}
}
catch (IOException ioe){
ioe.printStackTrace();
}
}
// Little conversion function to correctly format time units from
// long value in ns to string representing ms.
static public String nsToString(long ns){
String units;
if (ns>=1000000){
ns = ns/1000000;
units = "ms";
} else if (ns>=1000) {
ns = ns/1000;
units = Character.toChars(956)[0]+"s";
} else {
units = "ns";
}
DecimalFormat df = new DecimalFormat("@@@");
return df.format(ns) + units;
}
// Little conversion function to correctly format diopter units
// from float into string in meters.
static public String diopterToMeters(Float f){
f = 1/f;
DecimalFormat df = new DecimalFormat("@@@");
return df.format(f) + "m";
}
/* void addFilesToMTP(String[])
*
* Adds files with full paths indicated in the input string array to be
* recognized by the system via the mediascanner.
*/
static public void addFilesToMTP(Context context,String[] filePathsToAdd){
MediaScannerConnection.scanFile(context, filePathsToAdd, null,
new MediaScannerConnection.OnScanCompletedListener() {
public void onScanCompleted(String path, Uri uri) {
Log.i("ExternalStorage", "Scanned " + path + ":");
Log.i("ExternalStorage", "-> uri=" + uri);
}
});
}
/* void addFileToMTP(String)
*
* Adds a file with full path indicated by input string to be recognized
* by the system via the mediascanner.
*/
static public void addFileToMTP(Context context,String file){
addFilesToMTP(context, new String[]{file});
}
}
/* Possibly worthy code for the future. Looks over ALL fields, not just the
ones presented as having valid keys
public static void printCharacteristics(CameraCharacteristics camChars){
Field[] fields = camChars.getClass().getDeclaredFields();
for (Field f : fields){
if (f.getType()==CameraCharacteristics.Key.class){
String name = f.getName();
if (sContextMap.containsKey(name)){
String[] values = sContextMap.get(name);
Log.v(cameraFragment.APP_TAG,name + " has possible values:");
Log.v(cameraFragment.APP_TAG,Arrays.deepToString(values));
} else {
Log.v(cameraFragment.APP_TAG,name + " has intrinsic value. ");
}
}
}
}*/