blob: 729890638931c407397f4ddd0686697cd439c383 [file] [log] [blame]
Dichen Zhang3b2c0ce2022-12-14 19:58:55 +00001#undef LOG_TAG
2#define LOG_TAG "YuvToJpegEncoder"
3
Wei-Ta Chenbca2d612009-11-30 17:52:05 +08004#include "CreateJavaOutputStreamAdaptor.h"
Kevin Lubick1175dc02022-02-28 12:41:27 -05005#include "SkStream.h"
Wei-Ta Chenbca2d612009-11-30 17:52:05 +08006#include "YuvToJpegEncoder.h"
Mathias Agopian8f2423e2010-02-16 17:33:37 -08007#include <ui/PixelFormat.h>
Harish Mahendrakar6b09b822023-10-12 20:45:45 +00008#include <utils/Errors.h>
Mathias Agopian8f2423e2010-02-16 17:33:37 -08009#include <hardware/hardware.h>
Wei-Ta Chenbca2d612009-11-30 17:52:05 +080010
Derek Sollenbergerc5882c42019-10-25 11:11:32 -040011#include "graphics_jni_helpers.h"
Wei-Ta Chenbca2d612009-11-30 17:52:05 +080012
Kevin Lubickba253602022-08-09 21:13:39 +000013#include <csetjmp>
14
Kevin Lubick4c391972023-02-16 12:54:46 +000015extern "C" {
16 // We need to include stdio.h before jpeg because jpeg does not include it, but uses FILE
17 // See https://github.com/libjpeg-turbo/libjpeg-turbo/issues/17
18 #include <stdio.h>
19 #include "jpeglib.h"
20 #include "jerror.h"
21 #include "jmorecfg.h"
22}
23
Wei-Ta Chenbca2d612009-11-30 17:52:05 +080024YuvToJpegEncoder* YuvToJpegEncoder::create(int format, int* strides) {
Mathias Agopiana696f5d2010-02-17 17:53:09 -080025 // Only ImageFormat.NV21 and ImageFormat.YUY2 are supported
Wei-Ta Chenbca2d612009-11-30 17:52:05 +080026 // for now.
Mathias Agopiana696f5d2010-02-17 17:53:09 -080027 if (format == HAL_PIXEL_FORMAT_YCrCb_420_SP) {
Wei-Ta Chenbca2d612009-11-30 17:52:05 +080028 return new Yuv420SpToJpegEncoder(strides);
Mathias Agopian8f2423e2010-02-16 17:33:37 -080029 } else if (format == HAL_PIXEL_FORMAT_YCbCr_422_I) {
Wei-Ta Chenbca2d612009-11-30 17:52:05 +080030 return new Yuv422IToJpegEncoder(strides);
31 } else {
32 return NULL;
33 }
34}
35
36YuvToJpegEncoder::YuvToJpegEncoder(int* strides) : fStrides(strides) {
37}
38
Leon Scroggins III1c3ded392018-02-28 13:23:32 -050039struct ErrorMgr {
40 struct jpeg_error_mgr pub;
41 jmp_buf jmp;
42};
43
44void error_exit(j_common_ptr cinfo) {
45 ErrorMgr* err = (ErrorMgr*) cinfo->err;
46 (*cinfo->err->output_message) (cinfo);
47 longjmp(err->jmp, 1);
48}
49
Kevin Lubick4c391972023-02-16 12:54:46 +000050/*
51 * Destination struct for directing decompressed pixels to a SkStream.
52 */
53static constexpr size_t kMgrBufferSize = 1024;
54struct skstream_destination_mgr : jpeg_destination_mgr {
55 skstream_destination_mgr(SkWStream* stream);
56
57 SkWStream* const fStream;
58
59 uint8_t fBuffer[kMgrBufferSize];
60};
61
62static void sk_init_destination(j_compress_ptr cinfo) {
63 skstream_destination_mgr* dest = (skstream_destination_mgr*)cinfo->dest;
64
65 dest->next_output_byte = dest->fBuffer;
66 dest->free_in_buffer = kMgrBufferSize;
67}
68
69static boolean sk_empty_output_buffer(j_compress_ptr cinfo) {
70 skstream_destination_mgr* dest = (skstream_destination_mgr*)cinfo->dest;
71
72 if (!dest->fStream->write(dest->fBuffer, kMgrBufferSize)) {
73 ERREXIT(cinfo, JERR_FILE_WRITE);
74 return FALSE;
75 }
76
77 dest->next_output_byte = dest->fBuffer;
78 dest->free_in_buffer = kMgrBufferSize;
79 return TRUE;
80}
81
82static void sk_term_destination(j_compress_ptr cinfo) {
83 skstream_destination_mgr* dest = (skstream_destination_mgr*)cinfo->dest;
84
85 size_t size = kMgrBufferSize - dest->free_in_buffer;
86 if (size > 0) {
87 if (!dest->fStream->write(dest->fBuffer, size)) {
88 ERREXIT(cinfo, JERR_FILE_WRITE);
89 return;
90 }
91 }
92
93 dest->fStream->flush();
94}
95
96skstream_destination_mgr::skstream_destination_mgr(SkWStream* stream)
97 : fStream(stream) {
98 this->init_destination = sk_init_destination;
99 this->empty_output_buffer = sk_empty_output_buffer;
100 this->term_destination = sk_term_destination;
101}
102
Wei-Ta Chenbca2d612009-11-30 17:52:05 +0800103bool YuvToJpegEncoder::encode(SkWStream* stream, void* inYuv, int width,
104 int height, int* offsets, int jpegQuality) {
Kevin Lubick4c391972023-02-16 12:54:46 +0000105 jpeg_compress_struct cinfo;
106 ErrorMgr err;
107 skstream_destination_mgr sk_wstream(stream);
Wei-Ta Chenbca2d612009-11-30 17:52:05 +0800108
Leon Scroggins III1c3ded392018-02-28 13:23:32 -0500109 cinfo.err = jpeg_std_error(&err.pub);
110 err.pub.error_exit = error_exit;
111
112 if (setjmp(err.jmp)) {
113 jpeg_destroy_compress(&cinfo);
Wei-Ta Chenbca2d612009-11-30 17:52:05 +0800114 return false;
115 }
116 jpeg_create_compress(&cinfo);
117
118 cinfo.dest = &sk_wstream;
119
120 setJpegCompressStruct(&cinfo, width, height, jpegQuality);
121
122 jpeg_start_compress(&cinfo, TRUE);
123
124 compress(&cinfo, (uint8_t*) inYuv, offsets);
125
126 jpeg_finish_compress(&cinfo);
127
Leon Scroggins III1c3ded392018-02-28 13:23:32 -0500128 jpeg_destroy_compress(&cinfo);
129
Wei-Ta Chenbca2d612009-11-30 17:52:05 +0800130 return true;
131}
132
133void YuvToJpegEncoder::setJpegCompressStruct(jpeg_compress_struct* cinfo,
134 int width, int height, int quality) {
Wei-Ta Chenbca2d612009-11-30 17:52:05 +0800135 cinfo->image_width = width;
136 cinfo->image_height = height;
Wei-Ta Chenbca2d612009-11-30 17:52:05 +0800137 cinfo->input_components = 3;
138 cinfo->in_color_space = JCS_YCbCr;
139 jpeg_set_defaults(cinfo);
Chia-chi Yehaa868592010-03-10 17:08:58 +0800140
141 jpeg_set_quality(cinfo, quality, TRUE);
Wei-Ta Chenbca2d612009-11-30 17:52:05 +0800142 jpeg_set_colorspace(cinfo, JCS_YCbCr);
143 cinfo->raw_data_in = TRUE;
Wei-Ta Chenbca2d612009-11-30 17:52:05 +0800144 cinfo->dct_method = JDCT_IFAST;
Wei-Ta Chenbca2d612009-11-30 17:52:05 +0800145 configSamplingFactors(cinfo);
146}
147
148///////////////////////////////////////////////////////////////////
149Yuv420SpToJpegEncoder::Yuv420SpToJpegEncoder(int* strides) :
150 YuvToJpegEncoder(strides) {
151 fNumPlanes = 2;
152}
153
154void Yuv420SpToJpegEncoder::compress(jpeg_compress_struct* cinfo,
155 uint8_t* yuv, int* offsets) {
Sally Qi7e3f93b2021-07-15 00:00:54 +0000156 ALOGD("onFlyCompress");
Wei-Ta Chenbca2d612009-11-30 17:52:05 +0800157 JSAMPROW y[16];
158 JSAMPROW cb[8];
159 JSAMPROW cr[8];
160 JSAMPARRAY planes[3];
161 planes[0] = y;
162 planes[1] = cb;
163 planes[2] = cr;
164
165 int width = cinfo->image_width;
166 int height = cinfo->image_height;
167 uint8_t* yPlanar = yuv + offsets[0];
168 uint8_t* vuPlanar = yuv + offsets[1]; //width * height;
169 uint8_t* uRows = new uint8_t [8 * (width >> 1)];
170 uint8_t* vRows = new uint8_t [8 * (width >> 1)];
171
172
173 // process 16 lines of Y and 8 lines of U/V each time.
174 while (cinfo->next_scanline < cinfo->image_height) {
175 //deitnerleave u and v
Wu-cheng Li4b63f142012-10-16 23:40:03 +0800176 deinterleave(vuPlanar, uRows, vRows, cinfo->next_scanline, width, height);
Wei-Ta Chenbca2d612009-11-30 17:52:05 +0800177
Wu-cheng Li4b63f142012-10-16 23:40:03 +0800178 // Jpeg library ignores the rows whose indices are greater than height.
Wei-Ta Chenbca2d612009-11-30 17:52:05 +0800179 for (int i = 0; i < 16; i++) {
180 // y row
181 y[i] = yPlanar + (cinfo->next_scanline + i) * fStrides[0];
182
183 // construct u row and v row
184 if ((i & 1) == 0) {
185 // height and width are both halved because of downsampling
186 int offset = (i >> 1) * (width >> 1);
187 cb[i/2] = uRows + offset;
188 cr[i/2] = vRows + offset;
189 }
190 }
191 jpeg_write_raw_data(cinfo, planes, 16);
192 }
193 delete [] uRows;
194 delete [] vRows;
195
196}
197
198void Yuv420SpToJpegEncoder::deinterleave(uint8_t* vuPlanar, uint8_t* uRows,
Wu-cheng Li4b63f142012-10-16 23:40:03 +0800199 uint8_t* vRows, int rowIndex, int width, int height) {
200 int numRows = (height - rowIndex) / 2;
201 if (numRows > 8) numRows = 8;
202 for (int row = 0; row < numRows; ++row) {
Wei-Ta Chenbca2d612009-11-30 17:52:05 +0800203 int offset = ((rowIndex >> 1) + row) * fStrides[1];
204 uint8_t* vu = vuPlanar + offset;
205 for (int i = 0; i < (width >> 1); ++i) {
206 int index = row * (width >> 1) + i;
207 uRows[index] = vu[1];
208 vRows[index] = vu[0];
209 vu += 2;
210 }
211 }
212}
213
214void Yuv420SpToJpegEncoder::configSamplingFactors(jpeg_compress_struct* cinfo) {
215 // cb and cr are horizontally downsampled and vertically downsampled as well.
216 cinfo->comp_info[0].h_samp_factor = 2;
217 cinfo->comp_info[0].v_samp_factor = 2;
218 cinfo->comp_info[1].h_samp_factor = 1;
219 cinfo->comp_info[1].v_samp_factor = 1;
220 cinfo->comp_info[2].h_samp_factor = 1;
221 cinfo->comp_info[2].v_samp_factor = 1;
222}
223
224///////////////////////////////////////////////////////////////////////////////
225Yuv422IToJpegEncoder::Yuv422IToJpegEncoder(int* strides) :
226 YuvToJpegEncoder(strides) {
227 fNumPlanes = 1;
228}
229
230void Yuv422IToJpegEncoder::compress(jpeg_compress_struct* cinfo,
231 uint8_t* yuv, int* offsets) {
Sally Qi7e3f93b2021-07-15 00:00:54 +0000232 ALOGD("onFlyCompress_422");
Wei-Ta Chenbca2d612009-11-30 17:52:05 +0800233 JSAMPROW y[16];
234 JSAMPROW cb[16];
235 JSAMPROW cr[16];
236 JSAMPARRAY planes[3];
237 planes[0] = y;
238 planes[1] = cb;
239 planes[2] = cr;
240
241 int width = cinfo->image_width;
242 int height = cinfo->image_height;
243 uint8_t* yRows = new uint8_t [16 * width];
244 uint8_t* uRows = new uint8_t [16 * (width >> 1)];
245 uint8_t* vRows = new uint8_t [16 * (width >> 1)];
246
247 uint8_t* yuvOffset = yuv + offsets[0];
248
249 // process 16 lines of Y and 16 lines of U/V each time.
250 while (cinfo->next_scanline < cinfo->image_height) {
251 deinterleave(yuvOffset, yRows, uRows, vRows, cinfo->next_scanline, width, height);
252
Wu-cheng Li4b63f142012-10-16 23:40:03 +0800253 // Jpeg library ignores the rows whose indices are greater than height.
Wei-Ta Chenbca2d612009-11-30 17:52:05 +0800254 for (int i = 0; i < 16; i++) {
255 // y row
256 y[i] = yRows + i * width;
257
258 // construct u row and v row
259 // width is halved because of downsampling
260 int offset = i * (width >> 1);
261 cb[i] = uRows + offset;
262 cr[i] = vRows + offset;
263 }
264
265 jpeg_write_raw_data(cinfo, planes, 16);
266 }
267 delete [] yRows;
268 delete [] uRows;
269 delete [] vRows;
270}
271
272
273void Yuv422IToJpegEncoder::deinterleave(uint8_t* yuv, uint8_t* yRows, uint8_t* uRows,
274 uint8_t* vRows, int rowIndex, int width, int height) {
Wu-cheng Li4b63f142012-10-16 23:40:03 +0800275 int numRows = height - rowIndex;
276 if (numRows > 16) numRows = 16;
277 for (int row = 0; row < numRows; ++row) {
Wei-Ta Chenbca2d612009-11-30 17:52:05 +0800278 uint8_t* yuvSeg = yuv + (rowIndex + row) * fStrides[0];
279 for (int i = 0; i < (width >> 1); ++i) {
280 int indexY = row * width + (i << 1);
281 int indexU = row * (width >> 1) + i;
282 yRows[indexY] = yuvSeg[0];
283 yRows[indexY + 1] = yuvSeg[2];
284 uRows[indexU] = yuvSeg[1];
285 vRows[indexU] = yuvSeg[3];
286 yuvSeg += 4;
287 }
288 }
289}
290
291void Yuv422IToJpegEncoder::configSamplingFactors(jpeg_compress_struct* cinfo) {
292 // cb and cr are horizontally downsampled and vertically downsampled as well.
293 cinfo->comp_info[0].h_samp_factor = 2;
294 cinfo->comp_info[0].v_samp_factor = 2;
295 cinfo->comp_info[1].h_samp_factor = 1;
296 cinfo->comp_info[1].v_samp_factor = 2;
297 cinfo->comp_info[2].h_samp_factor = 1;
298 cinfo->comp_info[2].v_samp_factor = 2;
299}
300///////////////////////////////////////////////////////////////////////////////
301
Harish Mahendrakar6b09b822023-10-12 20:45:45 +0000302using namespace ultrahdr;
Dichen Zhang3b2c0ce2022-12-14 19:58:55 +0000303
Dichen Zhang7087aaf2023-04-14 19:01:05 +0000304ultrahdr_color_gamut P010Yuv420ToJpegREncoder::findColorGamut(JNIEnv* env, int aDataSpace) {
Dichen Zhang3b2c0ce2022-12-14 19:58:55 +0000305 switch (aDataSpace & ADataSpace::STANDARD_MASK) {
306 case ADataSpace::STANDARD_BT709:
Dichen Zhang7087aaf2023-04-14 19:01:05 +0000307 return ultrahdr_color_gamut::ULTRAHDR_COLORGAMUT_BT709;
Dichen Zhang3b2c0ce2022-12-14 19:58:55 +0000308 case ADataSpace::STANDARD_DCI_P3:
Dichen Zhang7087aaf2023-04-14 19:01:05 +0000309 return ultrahdr_color_gamut::ULTRAHDR_COLORGAMUT_P3;
Dichen Zhang3b2c0ce2022-12-14 19:58:55 +0000310 case ADataSpace::STANDARD_BT2020:
Dichen Zhang7087aaf2023-04-14 19:01:05 +0000311 return ultrahdr_color_gamut::ULTRAHDR_COLORGAMUT_BT2100;
Dichen Zhang3b2c0ce2022-12-14 19:58:55 +0000312 default:
313 jclass IllegalArgumentException = env->FindClass("java/lang/IllegalArgumentException");
314 env->ThrowNew(IllegalArgumentException,
315 "The requested color gamut is not supported by JPEG/R.");
316 }
317
Dichen Zhang7087aaf2023-04-14 19:01:05 +0000318 return ultrahdr_color_gamut::ULTRAHDR_COLORGAMUT_UNSPECIFIED;
Dichen Zhang3b2c0ce2022-12-14 19:58:55 +0000319}
320
Dichen Zhang7087aaf2023-04-14 19:01:05 +0000321ultrahdr_transfer_function P010Yuv420ToJpegREncoder::findHdrTransferFunction(JNIEnv* env,
Dichen Zhang3b2c0ce2022-12-14 19:58:55 +0000322 int aDataSpace) {
323 switch (aDataSpace & ADataSpace::TRANSFER_MASK) {
324 case ADataSpace::TRANSFER_ST2084:
Dichen Zhang7087aaf2023-04-14 19:01:05 +0000325 return ultrahdr_transfer_function::ULTRAHDR_TF_PQ;
Dichen Zhang3b2c0ce2022-12-14 19:58:55 +0000326 case ADataSpace::TRANSFER_HLG:
Dichen Zhang7087aaf2023-04-14 19:01:05 +0000327 return ultrahdr_transfer_function::ULTRAHDR_TF_HLG;
Dichen Zhang3b2c0ce2022-12-14 19:58:55 +0000328 default:
329 jclass IllegalArgumentException = env->FindClass("java/lang/IllegalArgumentException");
330 env->ThrowNew(IllegalArgumentException,
331 "The requested HDR transfer function is not supported by JPEG/R.");
332 }
333
Dichen Zhang7087aaf2023-04-14 19:01:05 +0000334 return ultrahdr_transfer_function::ULTRAHDR_TF_UNSPECIFIED;
Dichen Zhang3b2c0ce2022-12-14 19:58:55 +0000335}
336
337bool P010Yuv420ToJpegREncoder::encode(JNIEnv* env,
338 SkWStream* stream, void* hdr, int hdrColorSpace, void* sdr, int sdrColorSpace,
339 int width, int height, int jpegQuality) {
340 // Check SDR color space. Now we only support SRGB transfer function
341 if ((sdrColorSpace & ADataSpace::TRANSFER_MASK) != ADataSpace::TRANSFER_SRGB) {
342 jclass IllegalArgumentException = env->FindClass("java/lang/IllegalArgumentException");
343 env->ThrowNew(IllegalArgumentException,
344 "The requested SDR color space is not supported. Transfer function must be SRGB");
345 return false;
346 }
347
Dichen Zhang7087aaf2023-04-14 19:01:05 +0000348 ultrahdr_color_gamut hdrColorGamut = findColorGamut(env, hdrColorSpace);
349 ultrahdr_color_gamut sdrColorGamut = findColorGamut(env, sdrColorSpace);
350 ultrahdr_transfer_function hdrTransferFunction = findHdrTransferFunction(env, hdrColorSpace);
Dichen Zhang3b2c0ce2022-12-14 19:58:55 +0000351
Dichen Zhang7087aaf2023-04-14 19:01:05 +0000352 if (hdrColorGamut == ultrahdr_color_gamut::ULTRAHDR_COLORGAMUT_UNSPECIFIED
353 || sdrColorGamut == ultrahdr_color_gamut::ULTRAHDR_COLORGAMUT_UNSPECIFIED
354 || hdrTransferFunction == ultrahdr_transfer_function::ULTRAHDR_TF_UNSPECIFIED) {
Dichen Zhang3b2c0ce2022-12-14 19:58:55 +0000355 return false;
356 }
357
Dichen Zhangf84ed402023-02-10 22:41:46 +0000358 JpegR jpegREncoder;
Dichen Zhang3b2c0ce2022-12-14 19:58:55 +0000359
360 jpegr_uncompressed_struct p010;
361 p010.data = hdr;
362 p010.width = width;
363 p010.height = height;
364 p010.colorGamut = hdrColorGamut;
365
366 jpegr_uncompressed_struct yuv420;
367 yuv420.data = sdr;
368 yuv420.width = width;
369 yuv420.height = height;
370 yuv420.colorGamut = sdrColorGamut;
371
372 jpegr_compressed_struct jpegR;
373 jpegR.maxLength = width * height * sizeof(uint8_t);
374
375 std::unique_ptr<uint8_t[]> jpegr_data = std::make_unique<uint8_t[]>(jpegR.maxLength);
376 jpegR.data = jpegr_data.get();
377
Dichen Zhangf84ed402023-02-10 22:41:46 +0000378 if (int success = jpegREncoder.encodeJPEGR(&p010, &yuv420,
Dichen Zhang3b2c0ce2022-12-14 19:58:55 +0000379 hdrTransferFunction,
380 &jpegR, jpegQuality, nullptr); success != android::OK) {
381 ALOGW("Encode JPEG/R failed, error code: %d.", success);
382 return false;
383 }
384
385 if (!stream->write(jpegR.data, jpegR.length)) {
386 ALOGW("Writing JPEG/R to stream failed.");
387 return false;
388 }
389
390 return true;
391}
392
393///////////////////////////////////////////////////////////////////////////////
394
Wei-Ta Chenbca2d612009-11-30 17:52:05 +0800395static jboolean YuvImage_compressToJpeg(JNIEnv* env, jobject, jbyteArray inYuv,
Ashok Bhat39029b22014-01-10 16:24:38 +0000396 jint format, jint width, jint height, jintArray offsets,
397 jintArray strides, jint jpegQuality, jobject jstream,
Wei-Ta Chenbca2d612009-11-30 17:52:05 +0800398 jbyteArray jstorage) {
399 jbyte* yuv = env->GetByteArrayElements(inYuv, NULL);
400 SkWStream* strm = CreateJavaOutputStreamAdaptor(env, jstream, jstorage);
401
402 jint* imgOffsets = env->GetIntArrayElements(offsets, NULL);
403 jint* imgStrides = env->GetIntArrayElements(strides, NULL);
404 YuvToJpegEncoder* encoder = YuvToJpegEncoder::create(format, imgStrides);
Pawel Augustyn7c68a4072012-07-16 11:23:54 +0200405 jboolean result = JNI_FALSE;
406 if (encoder != NULL) {
407 encoder->encode(strm, yuv, width, height, imgOffsets, jpegQuality);
408 delete encoder;
409 result = JNI_TRUE;
Wei-Ta Chenbca2d612009-11-30 17:52:05 +0800410 }
Wei-Ta Chenbca2d612009-11-30 17:52:05 +0800411
Wei-Ta Chenbca2d612009-11-30 17:52:05 +0800412 env->ReleaseByteArrayElements(inYuv, yuv, 0);
413 env->ReleaseIntArrayElements(offsets, imgOffsets, 0);
414 env->ReleaseIntArrayElements(strides, imgStrides, 0);
Martin Wallgrend8659002014-08-20 14:58:58 +0200415 delete strm;
Pawel Augustyn7c68a4072012-07-16 11:23:54 +0200416 return result;
Wei-Ta Chenbca2d612009-11-30 17:52:05 +0800417}
Dichen Zhang3b2c0ce2022-12-14 19:58:55 +0000418
419static jboolean YuvImage_compressToJpegR(JNIEnv* env, jobject, jbyteArray inHdr,
420 jint hdrColorSpace, jbyteArray inSdr, jint sdrColorSpace,
421 jint width, jint height, jint quality, jobject jstream,
422 jbyteArray jstorage) {
423 jbyte* hdr = env->GetByteArrayElements(inHdr, NULL);
424 jbyte* sdr = env->GetByteArrayElements(inSdr, NULL);
425 SkWStream* strm = CreateJavaOutputStreamAdaptor(env, jstream, jstorage);
426 P010Yuv420ToJpegREncoder encoder;
427
428 jboolean result = JNI_FALSE;
429 if (encoder.encode(env, strm, hdr, hdrColorSpace, sdr, sdrColorSpace,
430 width, height, quality)) {
431 result = JNI_TRUE;
432 }
433
434 env->ReleaseByteArrayElements(inHdr, hdr, 0);
435 env->ReleaseByteArrayElements(inSdr, sdr, 0);
436 delete strm;
437 return result;
438}
Wei-Ta Chenbca2d612009-11-30 17:52:05 +0800439///////////////////////////////////////////////////////////////////////////////
440
Daniel Micay76f6a862015-09-19 17:31:01 -0400441static const JNINativeMethod gYuvImageMethods[] = {
Wei-Ta Chenbca2d612009-11-30 17:52:05 +0800442 { "nativeCompressToJpeg", "([BIII[I[IILjava/io/OutputStream;[B)Z",
Dichen Zhang3b2c0ce2022-12-14 19:58:55 +0000443 (void*)YuvImage_compressToJpeg },
444 { "nativeCompressToJpegR", "([BI[BIIIILjava/io/OutputStream;[B)Z",
445 (void*)YuvImage_compressToJpegR }
Wei-Ta Chenbca2d612009-11-30 17:52:05 +0800446};
447
Wei-Ta Chenbca2d612009-11-30 17:52:05 +0800448int register_android_graphics_YuvImage(JNIEnv* env)
449{
Andreas Gampeed6b9df2014-11-20 22:02:20 -0800450 return android::RegisterMethodsOrDie(env, "android/graphics/YuvImage", gYuvImageMethods,
451 NELEM(gYuvImageMethods));
Wei-Ta Chenbca2d612009-11-30 17:52:05 +0800452}