| COLOR_FormatMonochrome = 1, |
| 6 | COLOR_Format8bitRGB332 = 2, |
| 7 | COLOR_Format12bitRGB444 = 3, |
| 8 | COLOR_Format16bitARGB4444 = 4, |
| 9 | COLOR_Format16bitARGB1555 = 5, |
| 10 | COLOR_Format16bitRGB565 = 6, |
| 11 | COLOR_Format16bitBGR565 = 7, |
| 12 | COLOR_Format18bitRGB666 = 8, |
| 13 | COLOR_Format18bitARGB1665 = 9, |
| 14 | COLOR_Format19bitARGB1666 = 10, |
| 15 | COLOR_Format24bitRGB888 = 11, |
| 16 | COLOR_Format24bitBGR888 = 12, |
| 17 | COLOR_Format24bitARGB1887 = 13, |
| 18 | COLOR_Format25bitARGB1888 = 14, |
| 19 | COLOR_Format32bitBGRA8888 = 15, |
| 20 | COLOR_Format32bitARGB8888 = 16, |
| 21 | COLOR_FormatYUV411Planar = 17, |
| 22 | COLOR_FormatYUV411PackedPlanar = 18, |
| 23 | COLOR_FormatYUV420Planar = 19, |
| 24 | COLOR_FormatYUV420PackedPlanar = 20, |
| 25 | COLOR_FormatYUV420SemiPlanar = 21, |
| 26 | COLOR_FormatYUV422Planar = 22, |
| 27 | COLOR_FormatYUV422PackedPlanar = 23, |
| 28 | COLOR_FormatYUV422SemiPlanar = 24, |
| 29 | COLOR_FormatYCbYCr = 25, |
| 30 | COLOR_FormatYCrYCb = 26, |
| 31 | COLOR_FormatCbYCrY = 27, |
| 32 | COLOR_FormatCrYCbY = 28, |
| 33 | COLOR_FormatYUV444Interleaved = 29, |
| 34 | COLOR_FormatRawBayer8bit = 30, |
| 35 | COLOR_FormatRawBayer10bit = 31, |
| 36 | COLOR_FormatRawBayer8bitcompressed = 32, |
| 37 | COLOR_FormatL2 = 33, |
| 38 | COLOR_FormatL4 = 34, |
| 39 | COLOR_FormatL8 = 35, |
| 40 | COLOR_FormatL16 = 36, |
| 41 | COLOR_FormatL24 = 37, |
| 42 | COLOR_FormatL32 = 38, |
| 43 | COLOR_FormatYUV420PackedSemiPlanar = 39, |
| 44 | COLOR_FormatYUV422PackedSemiPlanar = 40, |
| 45 | COLOR_Format18BitBGR666 = 41, |
| 46 | COLOR_Format24BitARGB6666 = 42, |
| 47 | COLOR_Format24BitABGR6666 = 43, |
| 48 |
| 49 | COLOR_TI_FormatYUV420PackedSemiPlanar = 0x7f000100, |
| 50 | COLOR_FormatSurface = 0x7F000789, |
| 51 | COLOR_QCOM_FormatYUV420SemiPlanar = 0x7fa30c00 |
| 52 | }; |
| 53 |
| 54 | jint isSemiPlanarYUV(jint colorFormat) { |
| 55 | switch (colorFormat) { |
| 56 | case COLOR_FormatYUV420Planar: |
| 57 | case COLOR_FormatYUV420PackedPlanar: |
| 58 | return 0; |
| 59 | case COLOR_FormatYUV420SemiPlanar: |
| 60 | case COLOR_FormatYUV420PackedSemiPlanar: |
| 61 | case COLOR_TI_FormatYUV420PackedSemiPlanar: |
| 62 | return 1; |
| 63 | default: |
| 64 | return 0; |
| 65 | } |
| 66 | } |
| 67 |
| 68 | JNIEXPORT jint Java_org_telegram_messenger_Utilities_convertVideoFrame(JNIEnv *env, jclass class, jobject src, jobject dest, jint destFormat, jint width, jint height, jint padding, jint swap) { |
| 69 | if (!src || !dest || !destFormat) { |
| 70 | return 0; |
| 71 | } |
| 72 |
| 73 | jbyte *srcBuff = (*env)->GetDirectBufferAddress(env, src); |
| 74 | jbyte *destBuff = (*env)->GetDirectBufferAddress(env, dest); |
| 75 |
| 76 | int half_width = (width + 1) / 2; |
| 77 | int half_height = (height + 1) / 2; |
| 78 |
| 79 | if (!isSemiPlanarYUV(destFormat)) { |
| 80 | if (!swap) { |
| 81 | ARGBToI420((uint8_t *) srcBuff, width * 4, |
| 82 | (uint8_t *) destBuff, width, |
| 83 | (uint8_t *) (destBuff + width * height + half_width * half_height + padding * 5 / 4), half_width, |
| 84 | (uint8_t *) (destBuff + width * height + padding), half_width, |
| 85 | width, height); |
| 86 | } else { |
| 87 | ARGBToI420((uint8_t *) srcBuff, width * 4, |
| 88 | (uint8_t *) destBuff, width, |
| 89 | (uint8_t *) (destBuff + width * height + padding), half_width, |
| 90 | (uint8_t *) (destBuff + width * height + half_width * half_height + padding * 5 / 4), half_width, |
| 91 | width, height); |
| 92 | } |
| 93 | } else { |
| 94 | if (!swap) { |
| 95 | ARGBToNV21((uint8_t *) srcBuff, width * 4, |
| 96 | (uint8_t *) destBuff, width, |
| 97 | (uint8_t *) (destBuff + width * height + padding), half_width * 2, |
| 98 | width, height); |
| 99 | } else { |
| 100 | ARGBToNV12((uint8_t *) srcBuff, width * 4, |
| 101 | (uint8_t *) destBuff, width, |
| 102 | (uint8_t *) (destBuff + width * height + padding), half_width * 2, |
| 103 | width, height); |
| 104 | } |
| 105 | } |
| 106 |
| 107 | return 1; |
| 108 | } |
| 109 |