MCPcopy Create free account
hub / github.com/android/ndk-samples / YUV2RGB

Function YUV2RGB

camera/basic/src/main/cpp/image_reader.cpp:172–197  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

170static const int kMaxChannelValue = 262143;
171
172static inline uint32_t YUV2RGB(int nY, int nU, int nV) {
173 nY -= 16;
174 nU -= 128;
175 nV -= 128;
176 if (nY < 0) nY = 0;
177
178 // This is the floating point equivalent. We do the conversion in integer
179 // because some Android devices do not have floating point in hardware.
180 // nR = (int)(1.164 * nY + 1.596 * nV);
181 // nG = (int)(1.164 * nY - 0.813 * nV - 0.391 * nU);
182 // nB = (int)(1.164 * nY + 2.018 * nU);
183
184 int nR = (int)(1192 * nY + 1634 * nV);
185 int nG = (int)(1192 * nY - 833 * nV - 400 * nU);
186 int nB = (int)(1192 * nY + 2066 * nU);
187
188 nR = MIN(kMaxChannelValue, MAX(0, nR));
189 nG = MIN(kMaxChannelValue, MAX(0, nG));
190 nB = MIN(kMaxChannelValue, MAX(0, nB));
191
192 nR = (nR >> 10) & 0xff;
193 nG = (nG >> 10) & 0xff;
194 nB = (nB >> 10) & 0xff;
195
196 return 0xff000000 | (nB << 16) | (nG << 8) | nR;
197}
198
199/**
200 * Convert yuv image inside AImage into ANativeWindow_Buffer

Callers 4

PresentImageMethod · 0.85
PresentImage90Method · 0.85
PresentImage180Method · 0.85
PresentImage270Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected