| 159 | } |
| 160 | |
| 161 | std::shared_ptr<ImageCodec> ImageCodec::MakeNativeCodec(const std::string& filePath) { |
| 162 | JNIEnvironment environment; |
| 163 | auto env = environment.current(); |
| 164 | if (env == nullptr || filePath.empty()) { |
| 165 | return nullptr; |
| 166 | } |
| 167 | if (BitmapFactoryOptionsClass.get() == nullptr) { |
| 168 | LOGE("Could not run NativeCodec.GetOrientation(), BitmapFactoryOptionsClass is not found!"); |
| 169 | return nullptr; |
| 170 | } |
| 171 | auto options = env->NewObject(BitmapFactoryOptionsClass.get(), BitmapFactoryOptions_Constructor); |
| 172 | if (options == nullptr) { |
| 173 | return nullptr; |
| 174 | } |
| 175 | env->SetBooleanField(options, BitmapFactoryOptions_inJustDecodeBounds, true); |
| 176 | auto imagePath = SafeToJString(env, filePath); |
| 177 | env->CallStaticObjectMethod(BitmapFactoryClass.get(), BitmapFactory_decodeFile, imagePath, |
| 178 | options); |
| 179 | if (env->ExceptionCheck()) { |
| 180 | return nullptr; |
| 181 | } |
| 182 | auto width = env->GetIntField(options, BitmapFactoryOptions_outWidth); |
| 183 | auto height = env->GetIntField(options, BitmapFactoryOptions_outHeight); |
| 184 | if (width <= 0 || height <= 0) { |
| 185 | env->ExceptionClear(); |
| 186 | LOGE("NativeCodec::readPixels(): Failed to get the size of the image!"); |
| 187 | return nullptr; |
| 188 | } |
| 189 | jobject exifInterface = nullptr; |
| 190 | if (ExifInterfaceClass.get() != nullptr) { |
| 191 | exifInterface = |
| 192 | env->NewObject(ExifInterfaceClass.get(), ExifInterface_Constructor_Path, imagePath); |
| 193 | } |
| 194 | auto origin = GetOrientation(env, exifInterface); |
| 195 | auto codec = std::shared_ptr<NativeCodec>(new NativeCodec(width, height, origin)); |
| 196 | codec->imagePath = filePath; |
| 197 | return codec; |
| 198 | } |
| 199 | |
| 200 | std::shared_ptr<ImageCodec> ImageCodec::MakeNativeCodec(std::shared_ptr<Data> imageBytes) { |
| 201 | JNIEnvironment environment; |
nothing calls this directly
no test coverage detected