Change image files in Android sample to use standard int types

Change: 143786104
This commit is contained in:
A. Unique TensorFlower 2017-01-06 10:10:57 -08:00 committed by TensorFlower Gardener
parent a3932aa4a3
commit 74329ee9ba
5 changed files with 68 additions and 83 deletions

View File

@ -20,15 +20,12 @@ limitations under the License.
#include <stdio.h>
#include <stdlib.h>
#include "tensorflow/core/platform/types.h"
#include "tensorflow/examples/android/jni/rgb2yuv.h"
#include "tensorflow/examples/android/jni/yuv2rgb.h"
#define IMAGEUTILS_METHOD(METHOD_NAME) \
Java_org_tensorflow_demo_env_ImageUtils_##METHOD_NAME // NOLINT
using namespace tensorflow;
#ifdef __cplusplus
extern "C" {
#endif
@ -72,14 +69,13 @@ IMAGEUTILS_METHOD(convertYUV420SPToARGB8888)(
jint* const o = env->GetIntArrayElements(output, &outputCopy);
if (halfSize) {
ConvertYUV420SPToARGB8888HalfSize(reinterpret_cast<uint8*>(i),
reinterpret_cast<uint32*>(o),
width, height);
ConvertYUV420SPToARGB8888HalfSize(reinterpret_cast<uint8_t*>(i),
reinterpret_cast<uint32_t*>(o), width,
height);
} else {
ConvertYUV420SPToARGB8888(reinterpret_cast<uint8*>(i),
reinterpret_cast<uint8*>(i) + width * height,
reinterpret_cast<uint32*>(o),
width, height);
ConvertYUV420SPToARGB8888(reinterpret_cast<uint8_t*>(i),
reinterpret_cast<uint8_t*>(i) + width * height,
reinterpret_cast<uint32_t*>(o), width, height);
}
env->ReleaseByteArrayElements(input, i, JNI_ABORT);
@ -96,17 +92,17 @@ JNIEXPORT void JNICALL IMAGEUTILS_METHOD(convertYUV420ToARGB8888)(
jint* const o = env->GetIntArrayElements(output, &outputCopy);
if (halfSize) {
ConvertYUV420SPToARGB8888HalfSize(reinterpret_cast<uint8*>(y_buff),
reinterpret_cast<uint32*>(o), width,
ConvertYUV420SPToARGB8888HalfSize(reinterpret_cast<uint8_t*>(y_buff),
reinterpret_cast<uint32_t*>(o), width,
height);
} else {
jbyte* const u_buff = env->GetByteArrayElements(u, &inputCopy);
jbyte* const v_buff = env->GetByteArrayElements(v, &inputCopy);
ConvertYUV420ToARGB8888(
reinterpret_cast<uint8*>(y_buff), reinterpret_cast<uint8*>(u_buff),
reinterpret_cast<uint8*>(v_buff), reinterpret_cast<uint32*>(o), width,
height, y_row_stride, uv_row_stride, uv_pixel_stride);
reinterpret_cast<uint8_t*>(y_buff), reinterpret_cast<uint8_t*>(u_buff),
reinterpret_cast<uint8_t*>(v_buff), reinterpret_cast<uint32_t*>(o),
width, height, y_row_stride, uv_row_stride, uv_pixel_stride);
env->ReleaseByteArrayElements(u, u_buff, JNI_ABORT);
env->ReleaseByteArrayElements(v, v_buff, JNI_ABORT);
@ -125,9 +121,8 @@ JNIEXPORT void JNICALL IMAGEUTILS_METHOD(convertYUV420SPToRGB565)(
jboolean outputCopy = JNI_FALSE;
jbyte* const o = env->GetByteArrayElements(output, &outputCopy);
ConvertYUV420SPToRGB565(reinterpret_cast<uint8*>(i),
reinterpret_cast<uint16*>(o),
width, height);
ConvertYUV420SPToRGB565(reinterpret_cast<uint8_t*>(i),
reinterpret_cast<uint16_t*>(o), width, height);
env->ReleaseByteArrayElements(input, i, JNI_ABORT);
env->ReleaseByteArrayElements(output, o, 0);
@ -143,9 +138,8 @@ IMAGEUTILS_METHOD(convertARGB8888ToYUV420SP)(
jboolean outputCopy = JNI_FALSE;
jbyte* const o = env->GetByteArrayElements(output, &outputCopy);
ConvertARGB8888ToYUV420SP(reinterpret_cast<uint32*>(i),
reinterpret_cast<uint8*>(o),
width, height);
ConvertARGB8888ToYUV420SP(reinterpret_cast<uint32_t*>(i),
reinterpret_cast<uint8_t*>(o), width, height);
env->ReleaseIntArrayElements(input, i, JNI_ABORT);
env->ReleaseByteArrayElements(output, o, 0);
@ -161,9 +155,8 @@ IMAGEUTILS_METHOD(convertRGB565ToYUV420SP)(
jboolean outputCopy = JNI_FALSE;
jbyte* const o = env->GetByteArrayElements(output, &outputCopy);
ConvertRGB565ToYUV420SP(reinterpret_cast<uint16*>(i),
reinterpret_cast<uint8*>(o),
width, height);
ConvertRGB565ToYUV420SP(reinterpret_cast<uint16_t*>(i),
reinterpret_cast<uint8_t*>(o), width, height);
env->ReleaseByteArrayElements(input, i, JNI_ABORT);
env->ReleaseByteArrayElements(output, o, 0);

View File

@ -17,14 +17,9 @@ limitations under the License.
#include "tensorflow/examples/android/jni/rgb2yuv.h"
#include "tensorflow/core/platform/types.h"
using namespace tensorflow;
static inline void WriteYUV(const int x, const int y, const int width,
const int r8, const int g8, const int b8,
uint8* const pY,
uint8* const pUV) {
uint8_t* const pY, uint8_t* const pUV) {
// Using formulas from http://msdn.microsoft.com/en-us/library/ms893078
*pY = ((66 * r8 + 129 * g8 + 25 * b8 + 128) >> 8) + 16;
@ -55,15 +50,15 @@ static inline void WriteYUV(const int x, const int y, const int width,
pUV[offset + u_offset] += ((-38 * r8 - 74 * g8 + 112 * b8 + 128) >> 10) + 32;
}
void ConvertARGB8888ToYUV420SP(const uint32* const input, uint8* const output,
int width, int height) {
uint8* pY = output;
uint8* pUV = output + (width * height);
const uint32* in = input;
void ConvertARGB8888ToYUV420SP(const uint32_t* const input,
uint8_t* const output, int width, int height) {
uint8_t* pY = output;
uint8_t* pUV = output + (width * height);
const uint32_t* in = input;
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
const uint32 rgb = *in++;
const uint32_t rgb = *in++;
#ifdef __APPLE__
const int nB = (rgb >> 8) & 0xFF;
const int nG = (rgb >> 16) & 0xFF;
@ -78,15 +73,15 @@ void ConvertARGB8888ToYUV420SP(const uint32* const input, uint8* const output,
}
}
void ConvertRGB565ToYUV420SP(const uint16* const input, uint8* const output,
void ConvertRGB565ToYUV420SP(const uint16_t* const input, uint8_t* const output,
const int width, const int height) {
uint8* pY = output;
uint8* pUV = output + (width * height);
const uint16* in = input;
uint8_t* pY = output;
uint8_t* pUV = output + (width * height);
const uint16_t* in = input;
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
const uint32 rgb = *in++;
const uint32_t rgb = *in++;
const int r5 = ((rgb >> 11) & 0x1F);
const int g6 = ((rgb >> 5) & 0x3F);

View File

@ -16,19 +16,16 @@ limitations under the License.
#ifndef ORG_TENSORFLOW_JNI_IMAGEUTILS_RGB2YUV_H_
#define ORG_TENSORFLOW_JNI_IMAGEUTILS_RGB2YUV_H_
#include "tensorflow/core/platform/types.h"
using namespace tensorflow;
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
void ConvertARGB8888ToYUV420SP(const uint32* const input, uint8* const output,
int width, int height);
void ConvertARGB8888ToYUV420SP(const uint32_t* const input,
uint8_t* const output, int width, int height);
void ConvertRGB565ToYUV420SP(const uint16* const input,
uint8* const output,
void ConvertRGB565ToYUV420SP(const uint16_t* const input, uint8_t* const output,
const int width, const int height);
#ifdef __cplusplus

View File

@ -27,7 +27,7 @@ limitations under the License.
// are normalized to eight bits.
static const int kMaxChannelValue = 262143;
static inline uint32 YUV2RGB(int nY, int nU, int nV) {
static inline uint32_t YUV2RGB(int nY, int nU, int nV) {
nY -= 16;
nU -= 128;
nV -= 128;
@ -58,19 +58,20 @@ static inline uint32 YUV2RGB(int nY, int nU, int nV) {
// separate u and v planes with arbitrary row and column strides,
// containing 8 bit 2x2 subsampled chroma samples.
// Converts to a packed ARGB 32 bit output of the same pixel dimensions.
void ConvertYUV420ToARGB8888(const uint8* const yData, const uint8* const uData,
const uint8* const vData, uint32* const output,
void ConvertYUV420ToARGB8888(const uint8_t* const yData,
const uint8_t* const uData,
const uint8_t* const vData, uint32_t* const output,
const int width, const int height,
const int y_row_stride, const int uv_row_stride,
const int uv_pixel_stride) {
uint32* out = output;
uint32_t* out = output;
for (int y = 0; y < height; y++) {
const uint8* pY = yData + y_row_stride * y;
const uint8_t* pY = yData + y_row_stride * y;
const int uv_row_start = uv_row_stride * (y >> 1);
const uint8* pU = uData + uv_row_start;
const uint8* pV = vData + uv_row_start;
const uint8_t* pU = uData + uv_row_start;
const uint8_t* pV = vData + uv_row_start;
for (int x = 0; x < width; x++) {
const int uv_offset = (x >> 1) * uv_pixel_stride;
@ -83,13 +84,13 @@ void ConvertYUV420ToARGB8888(const uint8* const yData, const uint8* const uData,
// interleaved U/V plane containing 8 bit 2x2 subsampled chroma samples,
// except the interleave order of U and V is reversed. Converts to a packed
// ARGB 32 bit output of the same pixel dimensions.
void ConvertYUV420SPToARGB8888(const uint8* const yData,
const uint8* const uvData,
uint32* const output, const int width,
void ConvertYUV420SPToARGB8888(const uint8_t* const yData,
const uint8_t* const uvData,
uint32_t* const output, const int width,
const int height) {
const uint8* pY = yData;
const uint8* pUV = uvData;
uint32* out = output;
const uint8_t* pY = yData;
const uint8_t* pUV = uvData;
uint32_t* out = output;
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
@ -109,12 +110,12 @@ void ConvertYUV420SPToARGB8888(const uint8* const yData,
}
// The same as above, but downsamples each dimension to half size.
void ConvertYUV420SPToARGB8888HalfSize(const uint8* const input,
uint32* const output,
int width, int height) {
const uint8* pY = input;
const uint8* pUV = input + (width * height);
uint32* out = output;
void ConvertYUV420SPToARGB8888HalfSize(const uint8_t* const input,
uint32_t* const output, int width,
int height) {
const uint8_t* pY = input;
const uint8_t* pUV = input + (width * height);
uint32_t* out = output;
int stride = width;
width >>= 1;
height >>= 1;
@ -141,11 +142,11 @@ void ConvertYUV420SPToARGB8888HalfSize(const uint8* const input,
// interleaved U/V plane containing 8 bit 2x2 subsampled chroma samples,
// except the interleave order of U and V is reversed. Converts to a packed
// RGB 565 bit output of the same pixel dimensions.
void ConvertYUV420SPToRGB565(const uint8* const input, uint16* const output,
void ConvertYUV420SPToRGB565(const uint8_t* const input, uint16_t* const output,
const int width, const int height) {
const uint8* pY = input;
const uint8* pUV = input + (width * height);
uint16 *out = output;
const uint8_t* pY = input;
const uint8_t* pUV = input + (width * height);
uint16_t* out = output;
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {

View File

@ -19,16 +19,15 @@ limitations under the License.
#ifndef ORG_TENSORFLOW_JNI_IMAGEUTILS_YUV2RGB_H_
#define ORG_TENSORFLOW_JNI_IMAGEUTILS_YUV2RGB_H_
#include "tensorflow/core/platform/types.h"
using namespace tensorflow;
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
void ConvertYUV420ToARGB8888(const uint8* const yData, const uint8* const uData,
const uint8* const vData, uint32* const output,
void ConvertYUV420ToARGB8888(const uint8_t* const yData,
const uint8_t* const uData,
const uint8_t* const vData, uint32_t* const output,
const int width, const int height,
const int y_row_stride, const int uv_row_stride,
const int uv_pixel_stride);
@ -36,19 +35,19 @@ void ConvertYUV420ToARGB8888(const uint8* const yData, const uint8* const uData,
// Converts YUV420 semi-planar data to ARGB 8888 data using the supplied width
// and height. The input and output must already be allocated and non-null.
// For efficiency, no error checking is performed.
void ConvertYUV420SPToARGB8888(const uint8* const pY, const uint8* const pUV,
uint32* const output, const int width,
const int height);
void ConvertYUV420SPToARGB8888(const uint8_t* const pY,
const uint8_t* const pUV, uint32_t* const output,
const int width, const int height);
// The same as above, but downsamples each dimension to half size.
void ConvertYUV420SPToARGB8888HalfSize(const uint8* const input,
uint32* const output,
int width, int height);
void ConvertYUV420SPToARGB8888HalfSize(const uint8_t* const input,
uint32_t* const output, int width,
int height);
// Converts YUV420 semi-planar data to RGB 565 data using the supplied width
// and height. The input and output must already be allocated and non-null.
// For efficiency, no error checking is performed.
void ConvertYUV420SPToRGB565(const uint8* const input, uint16* const output,
void ConvertYUV420SPToRGB565(const uint8_t* const input, uint16_t* const output,
const int width, const int height);
#ifdef __cplusplus