printf debug statements in ifdef

This commit is contained in:
Greg DiCristofaro 2022-03-02 09:21:53 -05:00
parent 1eaef023eb
commit 28076a26e6
9 changed files with 323 additions and 419 deletions

View File

@ -1,112 +0,0 @@
AUTOMAKE_OPTIONS = subdir-objects
examples = \
heif-convert \
heif-enc \
heif-info
examples_noinst = \
heif-test \
test-c-api
dist_man_MANS =
heif_convert_DEPENDENCIES = ../libheif/libheif.la
heif_convert_CXXFLAGS = -I$(top_srcdir) -I$(top_builddir)/.
heif_convert_LDFLAGS =
heif_convert_LDADD = ../libheif/libheif.la
heif_convert_SOURCES = encoder.cc encoder.h heif_convert.cc encoder_y4m.cc encoder_y4m.h
dist_man_MANS += heif-convert.1
if HAVE_LIBPNG
examples += heif-thumbnailer
heif_thumbnailer_DEPENDENCIES = ../libheif/libheif.la
heif_thumbnailer_CXXFLAGS = -I$(top_srcdir) -I$(top_builddir) $(libpng_CFLAGS)
heif_thumbnailer_LDFLAGS = $(libpng_LIBS)
heif_thumbnailer_LDADD = ../libheif/libheif.la
heif_thumbnailer_SOURCES = encoder.cc encoder.h heif_thumbnailer.cc encoder_png.cc encoder_png.h
dist_man_MANS += heif-thumbnailer.1
endif
if HAVE_LIBJPEG
heif_convert_CXXFLAGS += $(libjpeg_CFLAGS)
heif_convert_LDADD += $(libjpeg_LIBS)
heif_convert_SOURCES += encoder_jpeg.cc encoder_jpeg.h
endif
if HAVE_LIBPNG
heif_convert_CXXFLAGS += $(libpng_CFLAGS)
heif_convert_LDADD += $(libpng_LIBS)
heif_convert_SOURCES += encoder_png.cc encoder_png.h
endif
heif_info_DEPENDENCIES = ../libheif/libheif.la
heif_info_CXXFLAGS = -I$(top_srcdir) -I$(top_builddir)
heif_info_LDFLAGS =
heif_info_LDADD = ../libheif/libheif.la
heif_info_SOURCES = heif_info.cc
dist_man_MANS += heif-info.1
heif_enc_DEPENDENCIES = ../libheif/libheif.la
heif_enc_CXXFLAGS = -I$(top_srcdir) -I$(top_builddir)
heif_enc_LDFLAGS =
heif_enc_LDADD = ../libheif/libheif.la
heif_enc_SOURCES = heif_enc.cc
dist_man_MANS += heif-enc.1
if HAVE_LIBJPEG
heif_enc_CXXFLAGS += $(libjpeg_CFLAGS)
heif_enc_LDADD += $(libjpeg_LIBS)
endif
if HAVE_LIBPNG
heif_enc_CXXFLAGS += $(libpng_CFLAGS)
heif_enc_LDADD += $(libpng_LIBS)
endif
heif_test_DEPENDENCIES = ../libheif/libheif.la
heif_test_CXXFLAGS = -I$(top_srcdir) -I$(top_builddir)
heif_test_LDFLAGS =
heif_test_LDADD = ../libheif/libheif.la
heif_test_SOURCES = heif_test.cc
test_c_api_DEPENDENCIES = ../libheif/libheif.la
test_c_api_CFLAGS = -I$(top_srcdir) -I$(top_builddir)
test_c_api_LDFLAGS =
test_c_api_LDADD = ../libheif/libheif.la
test_c_api_SOURCES = test_c_api.c
EXTRA_DIST = \
CMakeLists.txt \
COPYING \
demo.html \
example.avif \
example.heic
if HAVE_GO
examples_noinst += \
heif-test-go
heif_test_go_SOURCES = heif-test.go
gopath:
mkdir -p ${CURDIR}/src/github.com/strukturag/libheif
ln -sf ${CURDIR}/../go ${CURDIR}/src/github.com/strukturag/libheif/
heif-test-go: gopath $(top_builddir)/libheif/libheif.la $(top_builddir)/libheif.pc heif-test.go
GOPATH=${CURDIR} PKG_CONFIG_PATH=${PKG_CONFIG_PATH}:$(abs_top_builddir):$(abs_top_builddir)/libde265/dist/lib/pkgconfig/ CGO_CFLAGS="-I$(abs_top_builddir)" CGO_LDFLAGS="-L$(abs_top_builddir)/libheif/.libs" LD_LIBRARY_PATH=$(abs_top_builddir)/libheif/.libs $(GO) build -o heif-test-go ${heif_test_go_SOURCES}
format-go: ${heif_test_go_SOURCES}
$(GO) fmt ${heif_test_go_SOURCES}
else
format-go:
echo ""go" not present in "${PATH}", skipping formatting"
endif
if WITH_EXAMPLES
bin_PROGRAMS = $(examples)
noinst_PROGRAMS = $(examples_noinst)
endif
format-local: format-go

View File

@ -9,7 +9,7 @@ The output was:
Microsoft (R) Build Engine version 17.1.0+ae57d105c for .NET Framework Microsoft (R) Build Engine version 17.1.0+ae57d105c for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved. Copyright (C) Microsoft Corporation. All rights reserved.
Build started 3/1/2022 8:15:06 PM. Build started 3/2/2022 9:19:03 AM.
Project "C:\Users\gregd\Documents\Source\autopsy\thirdparty\libheif\HeifConvertTestJNI\dist\CMakeFiles\3.23.0-rc2\CompilerIdC\CompilerIdC.vcxproj" on node 1 (default targets). Project "C:\Users\gregd\Documents\Source\autopsy\thirdparty\libheif\HeifConvertTestJNI\dist\CMakeFiles\3.23.0-rc2\CompilerIdC\CompilerIdC.vcxproj" on node 1 (default targets).
PrepareForBuild: PrepareForBuild:
Creating directory "Debug\". Creating directory "Debug\".
@ -35,7 +35,7 @@ Build succeeded.
0 Warning(s) 0 Warning(s)
0 Error(s) 0 Error(s)
Time Elapsed 00:00:00.67 Time Elapsed 00:00:00.64
Compilation of the C compiler identification source "CMakeCCompilerId.c" produced "CompilerIdC.exe" Compilation of the C compiler identification source "CMakeCCompilerId.c" produced "CompilerIdC.exe"
@ -54,7 +54,7 @@ The output was:
Microsoft (R) Build Engine version 17.1.0+ae57d105c for .NET Framework Microsoft (R) Build Engine version 17.1.0+ae57d105c for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved. Copyright (C) Microsoft Corporation. All rights reserved.
Build started 3/1/2022 8:15:07 PM. Build started 3/2/2022 9:19:04 AM.
Project "C:\Users\gregd\Documents\Source\autopsy\thirdparty\libheif\HeifConvertTestJNI\dist\CMakeFiles\3.23.0-rc2\CompilerIdCXX\CompilerIdCXX.vcxproj" on node 1 (default targets). Project "C:\Users\gregd\Documents\Source\autopsy\thirdparty\libheif\HeifConvertTestJNI\dist\CMakeFiles\3.23.0-rc2\CompilerIdCXX\CompilerIdCXX.vcxproj" on node 1 (default targets).
PrepareForBuild: PrepareForBuild:
Creating directory "Debug\". Creating directory "Debug\".
@ -80,7 +80,7 @@ Build succeeded.
0 Warning(s) 0 Warning(s)
0 Error(s) 0 Error(s)
Time Elapsed 00:00:00.61 Time Elapsed 00:00:00.48
Compilation of the CXX compiler identification source "CMakeCXXCompilerId.cpp" produced "CompilerIdCXX.exe" Compilation of the CXX compiler identification source "CMakeCXXCompilerId.cpp" produced "CompilerIdCXX.exe"
@ -92,42 +92,42 @@ The CXX compiler identification is MSVC, found in "C:/Users/gregd/Documents/Sour
Detecting C compiler ABI info compiled with the following output: Detecting C compiler ABI info compiled with the following output:
Change Dir: C:/Users/gregd/Documents/Source/autopsy/thirdparty/libheif/HeifConvertTestJNI/dist/CMakeFiles/CMakeTmp Change Dir: C:/Users/gregd/Documents/Source/autopsy/thirdparty/libheif/HeifConvertTestJNI/dist/CMakeFiles/CMakeTmp
Run Build Command(s):C:/Program Files/Microsoft Visual Studio/2022/Community/MSBuild/Current/Bin/amd64/MSBuild.exe cmTC_d5263.vcxproj /p:Configuration=Debug /p:Platform=x64 /p:VisualStudioVersion=17.0 /v:m && Microsoft (R) Build Engine version 17.1.0+ae57d105c for .NET Framework Run Build Command(s):C:/Program Files/Microsoft Visual Studio/2022/Community/MSBuild/Current/Bin/amd64/MSBuild.exe cmTC_4b51a.vcxproj /p:Configuration=Debug /p:Platform=x64 /p:VisualStudioVersion=17.0 /v:m && Microsoft (R) Build Engine version 17.1.0+ae57d105c for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved. Copyright (C) Microsoft Corporation. All rights reserved.
Microsoft (R) C/C++ Optimizing Compiler Version 19.31.31104 for x64 Microsoft (R) C/C++ Optimizing Compiler Version 19.31.31104 for x64
Copyright (C) Microsoft Corporation. All rights reserved.
CMakeCCompilerABI.c CMakeCCompilerABI.c
cl /c /Zi /W3 /WX- /diagnostics:column /Od /Ob0 /D _MBCS /D WIN32 /D _WINDOWS /D "CMAKE_INTDIR=\"Debug\"" /Gm- /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /Fo"cmTC_d5263.dir\Debug\\" /Fd"cmTC_d5263.dir\Debug\vc143.pdb" /external:W3 /Gd /TC /errorReport:queue "C:\Program Files\CMake\share\cmake-3.23\Modules\CMakeCCompilerABI.c" Copyright (C) Microsoft Corporation. All rights reserved.
cmTC_d5263.vcxproj -> C:\Users\gregd\Documents\Source\autopsy\thirdparty\libheif\HeifConvertTestJNI\dist\CMakeFiles\CMakeTmp\Debug\cmTC_d5263.exe cl /c /Zi /W3 /WX- /diagnostics:column /Od /Ob0 /D _MBCS /D WIN32 /D _WINDOWS /D "CMAKE_INTDIR=\"Debug\"" /Gm- /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /Fo"cmTC_4b51a.dir\Debug\\" /Fd"cmTC_4b51a.dir\Debug\vc143.pdb" /external:W3 /Gd /TC /errorReport:queue "C:\Program Files\CMake\share\cmake-3.23\Modules\CMakeCCompilerABI.c"
cmTC_4b51a.vcxproj -> C:\Users\gregd\Documents\Source\autopsy\thirdparty\libheif\HeifConvertTestJNI\dist\CMakeFiles\CMakeTmp\Debug\cmTC_4b51a.exe
Detecting CXX compiler ABI info compiled with the following output: Detecting CXX compiler ABI info compiled with the following output:
Change Dir: C:/Users/gregd/Documents/Source/autopsy/thirdparty/libheif/HeifConvertTestJNI/dist/CMakeFiles/CMakeTmp Change Dir: C:/Users/gregd/Documents/Source/autopsy/thirdparty/libheif/HeifConvertTestJNI/dist/CMakeFiles/CMakeTmp
Run Build Command(s):C:/Program Files/Microsoft Visual Studio/2022/Community/MSBuild/Current/Bin/amd64/MSBuild.exe cmTC_2a9c8.vcxproj /p:Configuration=Debug /p:Platform=x64 /p:VisualStudioVersion=17.0 /v:m && Microsoft (R) Build Engine version 17.1.0+ae57d105c for .NET Framework Run Build Command(s):C:/Program Files/Microsoft Visual Studio/2022/Community/MSBuild/Current/Bin/amd64/MSBuild.exe cmTC_d7e81.vcxproj /p:Configuration=Debug /p:Platform=x64 /p:VisualStudioVersion=17.0 /v:m && Microsoft (R) Build Engine version 17.1.0+ae57d105c for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved. Copyright (C) Microsoft Corporation. All rights reserved.
Microsoft (R) C/C++ Optimizing Compiler Version 19.31.31104 for x64 Microsoft (R) C/C++ Optimizing Compiler Version 19.31.31104 for x64
Copyright (C) Microsoft Corporation. All rights reserved. Copyright (C) Microsoft Corporation. All rights reserved.
CMakeCXXCompilerABI.cpp CMakeCXXCompilerABI.cpp
cl /c /Zi /W3 /WX- /diagnostics:column /Od /Ob0 /D _MBCS /D WIN32 /D _WINDOWS /D "CMAKE_INTDIR=\"Debug\"" /Gm- /EHsc /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /GR /Fo"cmTC_2a9c8.dir\Debug\\" /Fd"cmTC_2a9c8.dir\Debug\vc143.pdb" /external:W3 /Gd /TP /errorReport:queue "C:\Program Files\CMake\share\cmake-3.23\Modules\CMakeCXXCompilerABI.cpp" cl /c /Zi /W3 /WX- /diagnostics:column /Od /Ob0 /D _MBCS /D WIN32 /D _WINDOWS /D "CMAKE_INTDIR=\"Debug\"" /Gm- /EHsc /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /GR /Fo"cmTC_d7e81.dir\Debug\\" /Fd"cmTC_d7e81.dir\Debug\vc143.pdb" /external:W3 /Gd /TP /errorReport:queue "C:\Program Files\CMake\share\cmake-3.23\Modules\CMakeCXXCompilerABI.cpp"
cmTC_2a9c8.vcxproj -> C:\Users\gregd\Documents\Source\autopsy\thirdparty\libheif\HeifConvertTestJNI\dist\CMakeFiles\CMakeTmp\Debug\cmTC_2a9c8.exe cmTC_d7e81.vcxproj -> C:\Users\gregd\Documents\Source\autopsy\thirdparty\libheif\HeifConvertTestJNI\dist\CMakeFiles\CMakeTmp\Debug\cmTC_d7e81.exe
Performing C++ SOURCE FILE Test HAVE_JPEG_WRITE_ICC_PROFILE succeeded with the following output: Performing C++ SOURCE FILE Test HAVE_JPEG_WRITE_ICC_PROFILE succeeded with the following output:
Change Dir: C:/Users/gregd/Documents/Source/autopsy/thirdparty/libheif/HeifConvertTestJNI/dist/CMakeFiles/CMakeTmp Change Dir: C:/Users/gregd/Documents/Source/autopsy/thirdparty/libheif/HeifConvertTestJNI/dist/CMakeFiles/CMakeTmp
Run Build Command(s):C:/Program Files/Microsoft Visual Studio/2022/Community/MSBuild/Current/Bin/amd64/MSBuild.exe cmTC_87163.vcxproj /p:Configuration=Debug /p:Platform=x64 /p:VisualStudioVersion=17.0 /v:m && Microsoft (R) Build Engine version 17.1.0+ae57d105c for .NET Framework Run Build Command(s):C:/Program Files/Microsoft Visual Studio/2022/Community/MSBuild/Current/Bin/amd64/MSBuild.exe cmTC_02584.vcxproj /p:Configuration=Debug /p:Platform=x64 /p:VisualStudioVersion=17.0 /v:m && Microsoft (R) Build Engine version 17.1.0+ae57d105c for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved. Copyright (C) Microsoft Corporation. All rights reserved.
Microsoft (R) C/C++ Optimizing Compiler Version 19.31.31104 for x64 Microsoft (R) C/C++ Optimizing Compiler Version 19.31.31104 for x64
src.cxx src.cxx
Copyright (C) Microsoft Corporation. All rights reserved. Copyright (C) Microsoft Corporation. All rights reserved.
cl /c /I"C:\Users\gregd\vcpkg\installed\x64-windows\include" /Zi /W3 /WX- /diagnostics:column /Od /Ob0 /D _MBCS /D WIN32 /D _WINDOWS /D HAVE_JPEG_WRITE_ICC_PROFILE /D "CMAKE_INTDIR=\"Debug\"" /Gm- /EHsc /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /GR /Fo"cmTC_87163.dir\Debug\\" /Fd"cmTC_87163.dir\Debug\vc143.pdb" /external:W3 /Gd /TP /errorReport:queue C:\Users\gregd\Documents\Source\autopsy\thirdparty\libheif\HeifConvertTestJNI\dist\CMakeFiles\CMakeTmp\src.cxx cl /c /I"C:\Users\gregd\vcpkg\installed\x64-windows\include" /Zi /W3 /WX- /diagnostics:column /Od /Ob0 /D _MBCS /D WIN32 /D _WINDOWS /D HAVE_JPEG_WRITE_ICC_PROFILE /D "CMAKE_INTDIR=\"Debug\"" /Gm- /EHsc /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /GR /Fo"cmTC_02584.dir\Debug\\" /Fd"cmTC_02584.dir\Debug\vc143.pdb" /external:W3 /Gd /TP /errorReport:queue C:\Users\gregd\Documents\Source\autopsy\thirdparty\libheif\HeifConvertTestJNI\dist\CMakeFiles\CMakeTmp\src.cxx
cmTC_87163.vcxproj -> C:\Users\gregd\Documents\Source\autopsy\thirdparty\libheif\HeifConvertTestJNI\dist\CMakeFiles\CMakeTmp\Debug\cmTC_87163.exe cmTC_02584.vcxproj -> C:\Users\gregd\Documents\Source\autopsy\thirdparty\libheif\HeifConvertTestJNI\dist\CMakeFiles\CMakeTmp\Debug\cmTC_02584.exe
Source file was: Source file was:

View File

@ -27,18 +27,6 @@
#ifndef _Included_org_sleuthkit_autopsy_modules_pictureanalyzer_impls_HeifJNI #ifndef _Included_org_sleuthkit_autopsy_modules_pictureanalyzer_impls_HeifJNI
#define _Included_org_sleuthkit_autopsy_modules_pictureanalyzer_impls_HeifJNI #define _Included_org_sleuthkit_autopsy_modules_pictureanalyzer_impls_HeifJNI
//#if defined(HAVE_CONFIG_H)
//#include "config.h"
//#endif
//
//#include <cstring>
//
//#if defined(HAVE_UNISTD_H)
//
//#include <unistd.h>
//
//#endif
#include <fstream> #include <fstream>
#include <iostream> #include <iostream>
#include <sstream> #include <sstream>
@ -59,355 +47,383 @@
class ContextReleaser class ContextReleaser
{ {
public: public:
ContextReleaser(struct heif_context* ctx) : ctx_(ctx) ContextReleaser(struct heif_context* ctx) : ctx_(ctx)
{} {}
~ContextReleaser() ~ContextReleaser()
{ {
heif_context_free(ctx_); heif_context_free(ctx_);
} }
private: private:
struct heif_context* ctx_; struct heif_context* ctx_;
}; };
jint throwException(JNIEnv* env, const char* exceptionType, const char* message) jint throwException(JNIEnv* env, const char* exceptionType, const char* message)
{ {
jclass exClass; jclass exClass;
exClass = env->FindClass(exceptionType); exClass = env->FindClass(exceptionType);
return env->ThrowNew(exClass, message); return env->ThrowNew(exClass, message);
} }
jint throwIllegalArgument(JNIEnv* env, const char* message) jint throwIllegalArgument(JNIEnv* env, const char* message)
{ {
std::string className = "java/lang/IllegalArgumentException"; std::string className = "java/lang/IllegalArgumentException";
return throwException(env, className.c_str(), message); return throwException(env, className.c_str(), message);
} }
jint throwIllegalState(JNIEnv* env, const char* message) jint throwIllegalState(JNIEnv* env, const char* message)
{ {
std::string className = "java/lang/IllegalStateException"; std::string className = "java/lang/IllegalStateException";
return throwException(env, className.c_str(), message); return throwException(env, className.c_str(), message);
} }
//void println(JNIEnv* env, std::string message)
//{
// // Get system class
// jclass syscls = env->FindClass("java/lang/System");
// // Lookup the "out" field
// jfieldID fid = env->GetStaticFieldID(syscls, "out", "Ljava/io/PrintStream;");
// jobject out = env->GetStaticObjectField(syscls, fid);
// // Get PrintStream class
// jclass pscls = env->FindClass("java/io/PrintStream");
// // Lookup printLn(String)
// jmethodID mid = env->GetMethodID(pscls, "println", "(Ljava/lang/String;)V");
// // Invoke the method
// jchar* cppstr = (jchar*)message.c_str(); // make an array of jchar (UTF-16 unsigned short encoding)
// jstring str = env->NewString(cppstr, message.length());
// env->CallVoidMethod(out, mid, str);
//}
int convertToDisk int convertToDisk
(JNIEnv* env, jclass cls, jbyteArray byteArr, jstring outputPath) { (JNIEnv* env, jclass cls, jbyteArray byteArr, jstring outputPath) {
size_t arrLen = env->GetArrayLength(byteArr); size_t arrLen = env->GetArrayLength(byteArr);
std::vector<jbyte> nativeByteArr(arrLen); std::vector<jbyte> nativeByteArr(arrLen);
boolean isCopy; boolean isCopy;
env->GetByteArrayRegion(byteArr, 0, arrLen, &nativeByteArr[0]); env->GetByteArrayRegion(byteArr, 0, arrLen, &nativeByteArr[0]);
std::string output_filename = env->GetStringUTFChars(outputPath, 0); std::string output_filename = env->GetStringUTFChars(outputPath, 0);
const int quality = 100; const int quality = 100;
printf("Checking heif file type...\n"); #ifdef _DEBUG
enum heif_filetype_result filetype_check = heif_check_filetype((const uint8_t*)&nativeByteArr[0], 12); printf("Checking heif file type...\n");
if (filetype_check == heif_filetype_no) { #endif
// env->ReleaseByteArrayElements(byteArr, nativeByteArr, 0); enum heif_filetype_result filetype_check = heif_check_filetype((const uint8_t*)&nativeByteArr[0], 12);
throwIllegalArgument(env, "Input file is not an HEIF/AVIF file"); if (filetype_check == heif_filetype_no) {
return 1; throwIllegalArgument(env, "Input file is not an HEIF/AVIF file");
} return 1;
}
printf("Checking heif file type supported...\n"); #ifdef _DEBUG
if (filetype_check == heif_filetype_yes_unsupported) { printf("Checking heif file type supported...\n");
// env->ReleaseByteArrayElements(byteArr, nativeByteArr, 0); #endif
throwIllegalArgument(env, "Input file is an unsupported HEIF/AVIF file type"); if (filetype_check == heif_filetype_yes_unsupported) {
return 1; throwIllegalArgument(env, "Input file is an unsupported HEIF/AVIF file type");
} return 1;
}
printf("Creating heif context...\n"); #ifdef _DEBUG
struct heif_context* ctx = heif_context_alloc(); printf("Creating heif context...\n");
if (!ctx) { #endif
// env->ReleaseByteArrayElements(byteArr, nativeByteArr, 0); struct heif_context* ctx = heif_context_alloc();
throwIllegalState(env, "Could not create context object"); if (!ctx) {
return 1; throwIllegalState(env, "Could not create context object");
} return 1;
}
printf("Reading in heif bytes...\n"); #ifdef _DEBUG
ContextReleaser cr(ctx); printf("Reading in heif bytes...\n");
struct heif_error err; #endif
err = heif_context_read_from_memory_without_copy(ctx, (void*)&nativeByteArr[0], arrLen, nullptr); ContextReleaser cr(ctx);
if (err.code != 0) { struct heif_error err;
// env->ReleaseByteArrayElements(byteArr, nativeByteArr, 0); err = heif_context_read_from_memory_without_copy(ctx, (void*)&nativeByteArr[0], arrLen, nullptr);
std::string err_message = "Could not read HEIF/AVIF file:"; if (err.code != 0) {
err_message += err.message; std::string err_message = "Could not read HEIF/AVIF file:";
throwIllegalState(env, err_message.c_str()); err_message += err.message;
return 1; throwIllegalState(env, err_message.c_str());
} return 1;
}
printf("Checking heif file type...\n"); #ifdef _DEBUG
int num_images = heif_context_get_number_of_top_level_images(ctx); printf("Checking heif file type...\n");
if (num_images == 0) { #endif
// env->ReleaseByteArrayElements(byteArr, nativeByteArr, 0); int num_images = heif_context_get_number_of_top_level_images(ctx);
throwIllegalState(env, "File doesn't contain any images"); if (num_images == 0) {
return 1; throwIllegalState(env, "File doesn't contain any images");
} return 1;
}
printf("File contains %d images. Reading in image ids...\n", num_images); #ifdef _DEBUG
printf("File contains %d images. Reading in image ids...\n", num_images);
#endif
std::vector<heif_item_id> image_IDs(num_images); std::vector<heif_item_id> image_IDs(num_images);
num_images = heif_context_get_list_of_top_level_image_IDs(ctx, image_IDs.data(), num_images); num_images = heif_context_get_list_of_top_level_image_IDs(ctx, image_IDs.data(), num_images);
printf("Resetting encoder...\n"); #ifdef _DEBUG
std::string filename; printf("Resetting encoder...\n");
std::unique_ptr<Encoder> encoder(new JpegEncoder(quality)); #endif
std::string filename;
std::unique_ptr<Encoder> encoder(new JpegEncoder(quality));
size_t image_index = 1; // Image filenames are "1" based. size_t image_index = 1; // Image filenames are "1" based.
for (int idx = 0; idx < num_images; ++idx) { for (int idx = 0; idx < num_images; ++idx) {
printf("Looping through for image %d\n", idx); #ifdef _DEBUG
printf("Looping through for image %d\n", idx);
#endif
if (num_images > 1) { if (num_images > 1) {
std::ostringstream s; std::ostringstream s;
s << output_filename.substr(0, output_filename.find_last_of('.')); s << output_filename.substr(0, output_filename.find_last_of('.'));
s << "-" << image_index; s << "-" << image_index;
s << output_filename.substr(output_filename.find_last_of('.')); s << output_filename.substr(output_filename.find_last_of('.'));
filename.assign(s.str()); filename.assign(s.str());
printf("Assigning filename of %s\n", s.str().c_str()); #ifdef _DEBUG
} printf("Assigning filename of %s\n", s.str().c_str());
else { #endif
filename.assign(output_filename); }
printf("Assigning filename of %s\n", output_filename.c_str()); else {
} filename.assign(output_filename);
#ifdef _DEBUG
printf("Assigning filename of %s\n", output_filename.c_str());
#endif
}
printf("acquiring heif image handle...\n"); #ifdef _DEBUG
struct heif_image_handle* handle; printf("acquiring heif image handle...\n");
err = heif_context_get_image_handle(ctx, image_IDs[idx], &handle); #endif
if (err.code) { struct heif_image_handle* handle;
// env->ReleaseByteArrayElements(byteArr, nativeByteArr, 0); err = heif_context_get_image_handle(ctx, image_IDs[idx], &handle);
std::string err_message = "Could not read HEIF/AVIF image "; if (err.code) {
err_message += idx; std::string err_message = "Could not read HEIF/AVIF image ";
err_message += ": "; err_message += idx;
err_message += err.message; err_message += ": ";
throwIllegalState(env, err_message.c_str()); err_message += err.message;
return 1; throwIllegalState(env, err_message.c_str());
} return 1;
}
printf("handling alpha...\n"); #ifdef _DEBUG
int has_alpha = heif_image_handle_has_alpha_channel(handle); printf("handling alpha...\n");
struct heif_decoding_options* decode_options = heif_decoding_options_alloc(); #endif
encoder->UpdateDecodingOptions(handle, decode_options); int has_alpha = heif_image_handle_has_alpha_channel(handle);
struct heif_decoding_options* decode_options = heif_decoding_options_alloc();
encoder->UpdateDecodingOptions(handle, decode_options);
int bit_depth = heif_image_handle_get_luma_bits_per_pixel(handle); int bit_depth = heif_image_handle_get_luma_bits_per_pixel(handle);
if (bit_depth < 0) { if (bit_depth < 0) {
heif_decoding_options_free(decode_options); heif_decoding_options_free(decode_options);
heif_image_handle_release(handle); heif_image_handle_release(handle);
// env->ReleaseByteArrayElements(byteArr, nativeByteArr, 0); throwIllegalState(env, "Input image has undefined bit-depth");
throwIllegalState(env, "Input image has undefined bit-depth"); return 1;
return 1; }
}
printf("decoding heif image...\n"); #ifdef _DEBUG
struct heif_image* image; printf("decoding heif image...\n");
err = heif_decode_image(handle, #endif
&image, struct heif_image* image;
encoder->colorspace(has_alpha), err = heif_decode_image(handle,
encoder->chroma(has_alpha, bit_depth), &image,
decode_options); encoder->colorspace(has_alpha),
heif_decoding_options_free(decode_options); encoder->chroma(has_alpha, bit_depth),
if (err.code) { decode_options);
heif_image_handle_release(handle); heif_decoding_options_free(decode_options);
std::string err_message = "Could not decode image: "; if (err.code) {
err_message += idx; heif_image_handle_release(handle);
err_message += ": "; std::string err_message = "Could not decode image: ";
err_message += err.message; err_message += idx;
// env->ReleaseByteArrayElements(byteArr, nativeByteArr, 0); err_message += ": ";
throwIllegalState(env, err_message.c_str()); err_message += err.message;
return 1; throwIllegalState(env, err_message.c_str());
} return 1;
}
if (image) { if (image) {
printf("valid image found.\n"); #ifdef _DEBUG
bool written = encoder->Encode(handle, image, filename); printf("valid image found.\n");
if (!written) { #endif
printf("could not write image\n"); bool written = encoder->Encode(handle, image, filename);
} if (!written) {
else { #ifdef _DEBUG
printf("Written to %s\n", filename.c_str()); printf("could not write image\n");
} #endif
heif_image_release(image); }
else {
#ifdef _DEBUG
printf("Written to %s\n", filename.c_str());
#endif
}
heif_image_release(image);
int has_depth = heif_image_handle_has_depth_image(handle); int has_depth = heif_image_handle_has_depth_image(handle);
if (has_depth) { if (has_depth) {
printf("has depth...\n"); #ifdef _DEBUG
heif_item_id depth_id; printf("has depth...\n");
int nDepthImages = heif_image_handle_get_list_of_depth_image_IDs(handle, &depth_id, 1); #endif
assert(nDepthImages == 1); heif_item_id depth_id;
(void)nDepthImages; int nDepthImages = heif_image_handle_get_list_of_depth_image_IDs(handle, &depth_id, 1);
assert(nDepthImages == 1);
(void)nDepthImages;
struct heif_image_handle* depth_handle; struct heif_image_handle* depth_handle;
err = heif_image_handle_get_depth_image_handle(handle, depth_id, &depth_handle); err = heif_image_handle_get_depth_image_handle(handle, depth_id, &depth_handle);
if (err.code) { if (err.code) {
heif_image_handle_release(handle); heif_image_handle_release(handle);
// env->ReleaseByteArrayElements(byteArr, nativeByteArr, 0); throwIllegalState(env, "Could not read depth channel");
throwIllegalState(env, "Could not read depth channel"); return 1;
return 1; }
}
int depth_bit_depth = heif_image_handle_get_luma_bits_per_pixel(depth_handle); int depth_bit_depth = heif_image_handle_get_luma_bits_per_pixel(depth_handle);
printf("decoding depth image...\n"); #ifdef _DEBUG
struct heif_image* depth_image; printf("decoding depth image...\n");
err = heif_decode_image(depth_handle, #endif
&depth_image, struct heif_image* depth_image;
encoder->colorspace(false), err = heif_decode_image(depth_handle,
encoder->chroma(false, depth_bit_depth), &depth_image,
nullptr); encoder->colorspace(false),
if (err.code) { encoder->chroma(false, depth_bit_depth),
heif_image_handle_release(depth_handle); nullptr);
heif_image_handle_release(handle); if (err.code) {
// env->ReleaseByteArrayElements(byteArr, nativeByteArr, 0); heif_image_handle_release(depth_handle);
std::string err_message = "Could not decode depth image: "; heif_image_handle_release(handle);
err_message += err.message; std::string err_message = "Could not decode depth image: ";
throwIllegalState(env, err_message.c_str()); err_message += err.message;
return 1; throwIllegalState(env, err_message.c_str());
} return 1;
}
std::ostringstream s; std::ostringstream s;
s << output_filename.substr(0, output_filename.find('.')); s << output_filename.substr(0, output_filename.find('.'));
s << "-depth"; s << "-depth";
s << output_filename.substr(output_filename.find('.')); s << output_filename.substr(output_filename.find('.'));
printf("Encoding to %s.\n", s.str().c_str()); #ifdef _DEBUG
written = encoder->Encode(depth_handle, depth_image, s.str()); printf("Encoding to %s.\n", s.str().c_str());
if (!written) { #endif
printf("could not write depth image\n"); written = encoder->Encode(depth_handle, depth_image, s.str());
} if (!written) {
else { #ifdef _DEBUG
printf("Depth image written to %s\n", s.str().c_str()); printf("could not write depth image\n");
} #endif
}
else {
#ifdef _DEBUG
printf("Depth image written to %s\n", s.str().c_str());
#endif
}
heif_image_release(depth_image); heif_image_release(depth_image);
heif_image_handle_release(depth_handle); heif_image_handle_release(depth_handle);
} }
printf("checking for aux images...\n"); #ifdef _DEBUG
printf("checking for aux images...\n");
// --- aux images #endif
int nAuxImages = heif_image_handle_get_number_of_auxiliary_images(handle, LIBHEIF_AUX_IMAGE_FILTER_OMIT_ALPHA | LIBHEIF_AUX_IMAGE_FILTER_OMIT_DEPTH); // --- aux images
if (nAuxImages > 0) { int nAuxImages = heif_image_handle_get_number_of_auxiliary_images(handle, LIBHEIF_AUX_IMAGE_FILTER_OMIT_ALPHA | LIBHEIF_AUX_IMAGE_FILTER_OMIT_DEPTH);
printf("found %d aux images.\n", nAuxImages);
std::vector<heif_item_id> auxIDs(nAuxImages); if (nAuxImages > 0) {
heif_image_handle_get_list_of_auxiliary_image_IDs(handle, #ifdef _DEBUG
LIBHEIF_AUX_IMAGE_FILTER_OMIT_ALPHA | LIBHEIF_AUX_IMAGE_FILTER_OMIT_DEPTH, printf("found %d aux images.\n", nAuxImages);
auxIDs.data(), nAuxImages); #endif
for (heif_item_id auxId : auxIDs) { std::vector<heif_item_id> auxIDs(nAuxImages);
printf("getting aux handle...\n"); heif_image_handle_get_list_of_auxiliary_image_IDs(handle,
LIBHEIF_AUX_IMAGE_FILTER_OMIT_ALPHA | LIBHEIF_AUX_IMAGE_FILTER_OMIT_DEPTH,
auxIDs.data(), nAuxImages);
struct heif_image_handle* aux_handle; for (heif_item_id auxId : auxIDs) {
err = heif_image_handle_get_auxiliary_image_handle(handle, auxId, &aux_handle); #ifdef _DEBUG
if (err.code) { printf("getting aux handle...\n");
heif_image_handle_release(handle); #endif
// env->ReleaseByteArrayElements(byteArr, nativeByteArr, 0);
throwIllegalState(env, "Could not read auxiliary image");
return 1;
}
printf("decoding aux handle image...\n"); struct heif_image_handle* aux_handle;
int aux_bit_depth = heif_image_handle_get_luma_bits_per_pixel(aux_handle); err = heif_image_handle_get_auxiliary_image_handle(handle, auxId, &aux_handle);
if (err.code) {
heif_image_handle_release(handle);
throwIllegalState(env, "Could not read auxiliary image");
return 1;
}
struct heif_image* aux_image; #ifdef _DEBUG
err = heif_decode_image(aux_handle, printf("decoding aux handle image...\n");
&aux_image, #endif
encoder->colorspace(false), int aux_bit_depth = heif_image_handle_get_luma_bits_per_pixel(aux_handle);
encoder->chroma(false, aux_bit_depth),
nullptr);
if (err.code) {
heif_image_handle_release(aux_handle);
heif_image_handle_release(handle);
// env->ReleaseByteArrayElements(byteArr, nativeByteArr, 0);
std::string err_message = "Could not decode auxiliary image: ";
err_message += err.message;
throwIllegalState(env, err_message.c_str());
return 1;
}
printf("decoding aux image handle auxiliary type...\n"); struct heif_image* aux_image;
const char* auxTypeC = nullptr; err = heif_decode_image(aux_handle,
err = heif_image_handle_get_auxiliary_type(aux_handle, &auxTypeC); &aux_image,
if (err.code) { encoder->colorspace(false),
heif_image_handle_release(aux_handle); encoder->chroma(false, aux_bit_depth),
heif_image_handle_release(handle); nullptr);
// env->ReleaseByteArrayElements(byteArr, nativeByteArr, 0); if (err.code) {
std::string err_message = "Could not get type of auxiliary image: "; heif_image_handle_release(aux_handle);
err_message += err.message; heif_image_handle_release(handle);
throwIllegalState(env, err_message.c_str()); std::string err_message = "Could not decode auxiliary image: ";
return 1; err_message += err.message;
} throwIllegalState(env, err_message.c_str());
return 1;
}
std::string auxType = std::string(auxTypeC); #ifdef _DEBUG
printf("decoding aux image handle auxiliary type...\n");
#endif
const char* auxTypeC = nullptr;
err = heif_image_handle_get_auxiliary_type(aux_handle, &auxTypeC);
if (err.code) {
heif_image_handle_release(aux_handle);
heif_image_handle_release(handle);
std::string err_message = "Could not get type of auxiliary image: ";
err_message += err.message;
throwIllegalState(env, err_message.c_str());
return 1;
}
printf("freeing auxiliary type.\n"); std::string auxType = std::string(auxTypeC);
heif_image_handle_free_auxiliary_types(aux_handle, &auxTypeC);
std::ostringstream s; #ifdef _DEBUG
s << output_filename.substr(0, output_filename.find('.')); printf("freeing auxiliary type.\n");
s << "-" + auxType; #endif
s << output_filename.substr(output_filename.find('.')); heif_image_handle_free_auxiliary_types(aux_handle, &auxTypeC);
throwIllegalArgument(env, s.str().c_str());
printf("Writing aux to output: %s\n", s.str().c_str()); std::ostringstream s;
s << output_filename.substr(0, output_filename.find('.'));
s << "-" + auxType;
s << output_filename.substr(output_filename.find('.'));
throwIllegalArgument(env, s.str().c_str());
written = encoder->Encode(aux_handle, aux_image, s.str()); #ifdef _DEBUG
if (!written) { printf("Writing aux to output: %s\n", s.str().c_str());
printf("could not write auxiliary image\n"); #endif
}
else {
printf("Auxiliary image written to %s\n", s.str().c_str());
}
heif_image_release(aux_image); written = encoder->Encode(aux_handle, aux_image, s.str());
heif_image_handle_release(aux_handle); if (!written) {
} #ifdef _DEBUG
} printf("could not write auxiliary image\n");
#endif
}
else {
#ifdef _DEBUG
printf("Auxiliary image written to %s\n", s.str().c_str());
#endif
}
heif_image_release(aux_image);
heif_image_handle_release(aux_handle);
}
}
heif_image_handle_release(handle); heif_image_handle_release(handle);
} }
image_index++; image_index++;
} }
return 0;
// env->ReleaseByteArrayElements(byteArr, nativeByteArr, 0);
return 0;
} }
extern "C" { extern "C" {
/* /*
* Class: org_sleuthkit_autopsy_modules_pictureanalyzer_impls_HeifJNI * Class: org_sleuthkit_autopsy_modules_pictureanalyzer_impls_HeifJNI
* Method: convertToDisk * Method: convertToDisk
* Signature: ([BLjava/lang/String;)V * Signature: ([BLjava/lang/String;)V
*/ */
JNIEXPORT int JNICALL Java_org_sleuthkit_autopsy_modules_pictureanalyzer_impls_HeifJNI_convertToDisk JNIEXPORT int JNICALL Java_org_sleuthkit_autopsy_modules_pictureanalyzer_impls_HeifJNI_convertToDisk
(JNIEnv* env, jclass cls, jbyteArray byteArr, jstring outputPath) { (JNIEnv* env, jclass cls, jbyteArray byteArr, jstring outputPath) {
return convertToDisk(env, cls, byteArr, outputPath); return convertToDisk(env, cls, byteArr, outputPath);
} }
} }