2 * Copyright (C) 2012 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 * The Scene class implements a simple physical simulation of a scene, using the
19 * CIE 1931 colorspace to represent light in physical units (lux).
21 * It's fairly approximate, but does provide a scene with realistic widely
22 * variable illumination levels and colors over time.
26 #ifndef HW_EMULATOR_CAMERA2_SCENE_H
27 #define HW_EMULATOR_CAMERA2_SCENE_H
29 #include "utils/Timers.h"
35 Scene(int sensorWidthPx,
37 float sensorSensitivity);
40 // Set the filter coefficients for the red, green, and blue filters on the
41 // sensor. Used as an optimization to pre-calculate various illuminance
42 // values. Two different green filters can be provided, to account for
43 // possible cross-talk on a Bayer sensor. Must be called before
45 void setColorFilterXYZ(
46 float rX, float rY, float rZ,
47 float grX, float grY, float grZ,
48 float gbX, float gbY, float gbZ,
49 float bX, float bY, float bZ);
51 // Set time of day (24-hour clock). This controls the general light levels
52 // in the scene. Must be called before calculateScene
53 void setHour(int hour);
57 // Set the duration of exposure for determining luminous exposure.
58 // Must be called before calculateScene
59 void setExposureDuration(float seconds);
61 // Calculate scene information for current hour and the time offset since
62 // the hour. Must be called at least once before calling getLuminousExposure.
63 // Resets pixel readout location to 0,0
64 void calculateScene(nsecs_t time);
66 // Set sensor pixel readout location.
67 void setReadoutPixel(int x, int y);
69 // Get sensor response in physical units (electrons) for light hitting the
70 // current readout pixel, after passing through color filters. The readout
71 // pixel will be auto-incremented. The returned array can be indexed with
73 const uint32_t* getPixelElectrons();
87 // Sensor color filtering coefficients in XYZ
93 int mOffsetX, mOffsetY;
96 int mHandshakeX, mHandshakeY;
107 uint32_t *mCurrentSceneMaterial;
110 float mExposureDuration;
111 float mSensorSensitivity;
128 uint32_t mCurrentColors[NUM_MATERIALS*NUM_CHANNELS];
131 * Constants for scene definition. These are various degrees of approximate.
134 // Fake handshake parameters. Two shake frequencies per axis, plus magnitude
135 // as a fraction of a scene tile, and relative magnitudes for the frequencies
136 static const float kHorizShakeFreq1;
137 static const float kHorizShakeFreq2;
138 static const float kVertShakeFreq1;
139 static const float kVertShakeFreq2;
140 static const float kFreq1Magnitude;
141 static const float kFreq2Magnitude;
143 static const float kShakeFraction;
145 // RGB->YUV conversion
146 static const float kRgb2Yuv[12];
148 // Aperture of imaging lens
149 static const float kAperture;
151 // Sun, moon illuminance levels in 2-hour increments. These don't match any
152 // real day anywhere.
153 static const uint32_t kTimeStep = 2;
154 static const float kSunlight[];
155 static const float kMoonlight[];
156 static const int kSunOverhead;
157 static const int kMoonOverhead;
159 // Illumination levels for various conditions, in lux
160 static const float kDirectSunIllum;
161 static const float kDaylightShadeIllum;
162 static const float kSunsetIllum;
163 static const float kTwilightIllum;
164 static const float kFullMoonIllum;
165 static const float kClearNightIllum;
166 static const float kStarIllum;
167 static const float kLivingRoomIllum;
169 // Chromaticity of various illumination sources
170 static const float kIncandescentXY[2];
171 static const float kDirectSunlightXY[2];
172 static const float kDaylightXY[2];
173 static const float kNoonSkyXY[2];
174 static const float kMoonlightXY[2];
175 static const float kSunsetXY[2];
177 static const uint8_t kSelfLit;
178 static const uint8_t kShadowed;
179 static const uint8_t kSky;
181 static const float kMaterials_xyY[NUM_MATERIALS][3];
182 static const uint8_t kMaterialsFlags[NUM_MATERIALS];
184 static const int kSceneWidth;
185 static const int kSceneHeight;
186 static const uint8_t kScene[];
191 #endif // HW_EMULATOR_CAMERA2_SCENE_H