MCPcopy Create free account
hub / github.com/Tencent/tgfx / MakeNativeCodec

Method MakeNativeCodec

src/platform/android/NativeCodec.cpp:161–198  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

159}
160
161std::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
200std::shared_ptr<ImageCodec> ImageCodec::MakeNativeCodec(std::shared_ptr<Data> imageBytes) {
201 JNIEnvironment environment;

Callers

nothing calls this directly

Calls 7

SafeToJStringFunction · 0.85
currentMethod · 0.80
GetOrientationFunction · 0.70
emptyMethod · 0.45
getMethod · 0.45
sizeMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected