@@ -95,6 +95,8 @@ jbyteArray encodeBitmap(JNIEnv *env, jobject thiz,
95
95
std::copy (reinterpret_cast <uint8_t *>(addr),
96
96
reinterpret_cast <uint8_t *>(addr) + info.height * info.stride , sourceData.data ());
97
97
98
+ AndroidBitmap_unlockPixels (env, bitmap);
99
+
98
100
heif_image *image;
99
101
heif_chroma chroma = heif_chroma_interleaved_RGBA;
100
102
if (info.format == ANDROID_BITMAP_FORMAT_RGBA_F16 &&
@@ -104,7 +106,6 @@ jbyteArray encodeBitmap(JNIEnv *env, jobject thiz,
104
106
result = heif_image_create ((int ) info.width , (int ) info.height , heif_colorspace_RGB,
105
107
chroma, &image);
106
108
if (result.code != heif_error_Ok) {
107
- AndroidBitmap_unlockPixels (env, bitmap);
108
109
throwCantEncodeImageException (env, result.message );
109
110
return static_cast <jbyteArray>(nullptr );
110
111
}
@@ -123,15 +124,15 @@ jbyteArray encodeBitmap(JNIEnv *env, jobject thiz,
123
124
result = heif_image_add_plane (image, heif_channel_interleaved, (int ) info.width ,
124
125
(int ) info.height , bitDepth);
125
126
if (result.code != heif_error_Ok) {
126
- AndroidBitmap_unlockPixels (env, bitmap);
127
127
throwCantEncodeImageException (env, result.message );
128
128
return static_cast <jbyteArray>(nullptr );
129
129
}
130
130
int stride;
131
131
uint8_t *imgData = heif_image_get_plane (image, heif_channel_interleaved, &stride);
132
132
if (info.format == ANDROID_BITMAP_FORMAT_RGBA_8888) {
133
- libyuv::ARGBCopy (sourceData.data (), (int ) info.stride , imgData,
134
- stride, (int ) info.width , (int ) info.height );
133
+ libyuv::ARGBCopy (sourceData.data (), (int ) info.stride ,
134
+ imgData,
135
+ stride, (int ) info.width , (int ) info.height );
135
136
} else if (info.format == ANDROID_BITMAP_FORMAT_RGB_565) {
136
137
libyuv::RGB565ToARGB (sourceData.data (), (int ) info.stride , imgData,
137
138
stride, (int ) info.width , (int ) info.height );
@@ -178,21 +179,22 @@ jbyteArray encodeBitmap(JNIEnv *env, jobject thiz,
178
179
for (int y = 0 ; y < info.height ; ++y) {
179
180
180
181
auto srcPtr = reinterpret_cast <uint16_t *>(srcData);
181
- auto dstPtr = reinterpret_cast <uint64_t *>(data64Ptr);
182
+ auto dstPtr = reinterpret_cast <uint16_t *>(data64Ptr);
182
183
183
184
for (int x = 0 ; x < info.width ; ++x) {
184
185
auto alpha = half_to_float (srcPtr[3 ]);
185
- tmpR = (uint16_t ) (half_to_float (srcPtr[0 ]) / scale / (alpha != 0 ? alpha : 1 ) );
186
- tmpG = (uint16_t ) (half_to_float (srcPtr[1 ]) / scale / (alpha != 0 ? alpha : 1 ) );
187
- tmpB = (uint16_t ) (half_to_float (srcPtr[2 ]) / scale / (alpha != 0 ? alpha : 1 ) );
186
+ tmpR = (uint16_t ) (half_to_float (srcPtr[0 ]) / scale);
187
+ tmpG = (uint16_t ) (half_to_float (srcPtr[1 ]) / scale);
188
+ tmpB = (uint16_t ) (half_to_float (srcPtr[2 ]) / scale);
188
189
tmpA = (uint16_t ) (alpha / scale);
189
- uint64_t color =
190
- ((uint64_t ) tmpA & 0xffff ) << 48 | ((uint64_t ) tmpB & 0xffff ) << 32 |
191
- ((uint64_t ) tmpG & 0xffff ) << 16 | ((uint64_t ) tmpR & 0xffff );
192
- dstPtr[0 ] = color;
190
+
191
+ dstPtr[0 ] = tmpR;
192
+ dstPtr[1 ] = tmpG;
193
+ dstPtr[2 ] = tmpB;
194
+ dstPtr[3 ] = tmpA;
193
195
194
196
srcPtr += 4 ;
195
- dstPtr += 1 ;
197
+ dstPtr += 4 ;
196
198
}
197
199
198
200
srcData += info.stride ;
@@ -242,7 +244,6 @@ jbyteArray encodeBitmap(JNIEnv *env, jobject thiz,
242
244
dstARGB.reset ();
243
245
}
244
246
}
245
- AndroidBitmap_unlockPixels (env, bitmap);
246
247
247
248
heif_image_handle *handle;
248
249
std::shared_ptr<heif_encoding_options> options (heif_encoding_options_alloc (),
@@ -251,6 +252,8 @@ jbyteArray encodeBitmap(JNIEnv *env, jobject thiz,
251
252
});
252
253
options->version = 5 ;
253
254
options->image_orientation = heif_orientation_normal;
255
+ options->output_nclx_profile = nullptr ;
256
+ options->save_two_colr_boxes_when_ICC_and_nclx_available = false ;
254
257
255
258
result = heif_context_encode_image (ctx.get (), image, encoder.get (), options.get (), &handle);
256
259
options.reset ();
0 commit comments