-
Notifications
You must be signed in to change notification settings - Fork 18
Iphone native *.heic support #35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
varlog00
wants to merge
2
commits into
NautiluX:master
Choose a base branch
from
varlog00:heif01
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| make | ||
| .swp | ||
| .git | ||
| .user |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ This project depends on the following dynamically linked libraries: | |
|
|
||
| * qt5 | ||
| * libexif | ||
| * libheif | ||
|
|
||
| ### OSX | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -50,6 +50,11 @@ slide [-t rotation_seconds] [-o background_opacity(0..255)] [-b blur_radius] -p | |
| * qt5-image-formats-plugins | ||
| * libexif | ||
|
|
||
| ## if *.heic support wanted | ||
| * libheif | ||
| * qt-heif-image-plugin (alas is not a part of Qt jet, have to be compiled, see instuctions below) | ||
| * cmake | ||
|
|
||
| Ubuntu/Raspbian: | ||
|
|
||
| ``` | ||
|
|
@@ -75,6 +80,18 @@ Install binaries | |
| ``` | ||
| sudo make install | ||
| ``` | ||
| Build Qt plugin for *.heic (Iphone) files | ||
|
|
||
| ``` | ||
| git clone https://github.com/jakar/qt-heif-image-plugin.git | ||
| cd qt-heif-image-plugin | ||
| mkdir -p build | ||
| cd build | ||
| cmake .. | ||
| make | ||
| sudo make install | ||
| ``` | ||
|
|
||
|
Comment on lines
+83
to
+94
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this necessary only to compile from source or as well to just run it? Can I use slide without heic support if I leave this out? |
||
|
|
||
| ### macOS | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,249 @@ | ||
| #include "exifhelper.h" | ||
| #include <QVariant> | ||
| #include <QDateTime> | ||
| #include <QLocale> | ||
| #include <QFileInfo> | ||
| #include <stdlib.h> | ||
| #include <iostream> | ||
| #include <libheif/heif_cxx.h> | ||
|
|
||
| ExifHelper::ExifHelper(): | ||
| m_exifData(NULL), | ||
| m_isHeif(false) | ||
| { | ||
|
|
||
| } | ||
| ExifHelper::~ExifHelper(){ | ||
| if(m_exifData) | ||
| exif_data_free(m_exifData); | ||
| } | ||
|
|
||
| void ExifHelper::setImage(const std::string path){ | ||
| m_path=path.c_str(); | ||
| if(m_exifData){ | ||
| exif_data_free(m_exifData); | ||
| } | ||
| if(isHeif(path)){ | ||
| m_exifData=getExifDataFromHeif(path); | ||
| m_isHeif=true; | ||
| }else{ | ||
| m_exifData=exif_data_new_from_file(path.c_str()); | ||
| m_isHeif=false; | ||
| } | ||
|
|
||
| if(m_exifData){ | ||
| m_byteOrder=exif_data_get_byte_order(m_exifData); | ||
| } | ||
| } | ||
|
|
||
| ExifData *ExifHelper::getExifData(){ | ||
| return(m_exifData); | ||
| } | ||
|
|
||
| int ExifHelper::getImageRotation() | ||
| { | ||
| if(m_isHeif) return 0; //if not, heic image will be rotated 2 times, courtesy of libheif? | ||
| int orientation = 0; | ||
| if (m_exifData) | ||
| { | ||
| ExifEntry *exifEntry = exif_data_get_entry(m_exifData, EXIF_TAG_ORIENTATION); | ||
|
|
||
| if (exifEntry) | ||
| { | ||
| orientation = exif_get_short(exifEntry->data, m_byteOrder); | ||
| // std::cout << m_path.toStdString() << " orientation " << orientation<< "\n"; | ||
| } | ||
| } | ||
|
|
||
| int degrees = 0; | ||
| switch(orientation) { | ||
| case 8: | ||
| degrees = 270; | ||
| break; | ||
| case 3: | ||
| degrees = 180; | ||
| break; | ||
| case 6: | ||
| degrees = 90; | ||
| break; | ||
| } | ||
|
|
||
| return degrees; | ||
| } | ||
|
|
||
|
|
||
|
|
||
| const QString ExifHelper::getImageInfo(){ | ||
| QString txt("Path: "); | ||
| txt=txt+m_path+"\n"; | ||
| if (m_exifData) | ||
| { | ||
|
|
||
| txt=txt+"XxY: "+getExifXDimension()+"x"+getExifYDimension()+"\n"; | ||
| txt=txt+"XxY resolution: "+getExifXResolution()+"x"+getExifYResolution()+"\n"; | ||
| txt=txt+"date: "+getExifDate()+"\n"; | ||
| txt=txt+"camera: "+getExifCamera()+"\n"; | ||
| txt=txt+getExifGPS(); | ||
|
|
||
| }else{ | ||
| txt=txt+"No exif data found :("; | ||
| } | ||
|
|
||
| return(txt); | ||
| } | ||
|
|
||
| const QString ExifHelper::getExifXResolution(){ | ||
| QString txt(""); | ||
| if(m_exifData){ | ||
| ExifEntry *exifEntry = exif_data_get_entry(m_exifData, EXIF_TAG_X_RESOLUTION); | ||
| if (exifEntry) | ||
| { | ||
| txt=txt+QString::number(exif_get_long(exifEntry->data, m_byteOrder)); | ||
| } | ||
| } | ||
| return txt; | ||
| } | ||
|
|
||
|
|
||
| const QString ExifHelper::getExifYResolution(){ | ||
| QString txt(""); | ||
| if(m_exifData){ | ||
| ExifEntry *exifEntry = exif_data_get_entry(m_exifData, EXIF_TAG_Y_RESOLUTION); | ||
| if (exifEntry) | ||
| { | ||
| txt=txt+QString::number(exif_get_long(exifEntry->data, m_byteOrder)); | ||
| } | ||
| } | ||
| return txt; | ||
| } | ||
|
|
||
| const QString ExifHelper::getExifXDimension(){ | ||
| QString txt(""); | ||
| if(m_exifData){ | ||
| ExifEntry *exifEntry = exif_data_get_entry(m_exifData, EXIF_TAG_PIXEL_X_DIMENSION); | ||
| if (exifEntry) | ||
| { | ||
| txt=txt+QString::number(exif_get_long(exifEntry->data, m_byteOrder)); | ||
| } | ||
| } | ||
| return txt; | ||
| } | ||
|
|
||
| const QString ExifHelper::getExifYDimension(){ | ||
| QString txt(""); | ||
| if(m_exifData){ | ||
| ExifEntry *exifEntry = exif_data_get_entry(m_exifData, EXIF_TAG_PIXEL_Y_DIMENSION); | ||
| if (exifEntry) | ||
| { | ||
| txt=txt+QString::number(exif_get_long(exifEntry->data, m_byteOrder)); | ||
| } | ||
| } | ||
| return txt; | ||
| } | ||
|
|
||
| const QString ExifHelper::getExifDate(){ | ||
| QString dateTime; | ||
| if (m_exifData) | ||
| { | ||
| ExifEntry *exifEntry = exif_data_get_entry(m_exifData, EXIF_TAG_DATE_TIME_ORIGINAL); | ||
| if (exifEntry) | ||
| { | ||
| dateTime = getExifAscii(exifEntry); | ||
| } | ||
| QString exifDateFormat = "yyyy:MM:dd hh:mm:ss"; | ||
| QDateTime exifDateTime = QDateTime::fromString(dateTime, exifDateFormat); | ||
| return QLocale::system().toString(exifDateTime); | ||
| } | ||
| return dateTime; | ||
| } | ||
|
|
||
| const QString ExifHelper::getExifGPS(){ | ||
| QString txt(""); | ||
| if(m_exifData){ | ||
| ExifEntry *exifEntry = exif_content_get_entry(m_exifData->ifd[EXIF_IFD_GPS], (ExifTag)EXIF_TAG_GPS_LATITUDE_REF); | ||
| if(exifEntry) | ||
| { | ||
| //txt=txt+" "+((getExifAscii(exifEntry)[0]=='N')?"+":"-"); | ||
| txt=txt+getExifAscii(exifEntry)+" "; | ||
| } | ||
| exifEntry = exif_content_get_entry(m_exifData->ifd[EXIF_IFD_GPS], (ExifTag)EXIF_TAG_GPS_LATITUDE); | ||
| if(exifEntry){ | ||
| txt=txt+QString::number(getExifGeoCooValue(exifEntry->data,m_byteOrder),'f',4)+"°; "; | ||
| } | ||
| exifEntry = exif_content_get_entry(m_exifData->ifd[EXIF_IFD_GPS], (ExifTag)EXIF_TAG_GPS_LONGITUDE_REF); | ||
| if(exifEntry){ | ||
| //txt=txt+" "+((getExifAscii(exifEntry)[0]=='E')?"+":"-"); | ||
| txt=txt+" "+getExifAscii(exifEntry)+" "; | ||
| } | ||
| exifEntry = exif_content_get_entry(m_exifData->ifd[EXIF_IFD_GPS], (ExifTag)EXIF_TAG_GPS_LONGITUDE); | ||
| if(exifEntry){ | ||
| txt=txt+QString::number(getExifGeoCooValue(exifEntry->data,m_byteOrder),'f',4)+"°; "; | ||
| } | ||
| exifEntry = exif_content_get_entry(m_exifData->ifd[EXIF_IFD_GPS], (ExifTag)EXIF_TAG_GPS_ALTITUDE); | ||
| if(exifEntry){ | ||
| txt=txt+QString::number(getExifRationalValue(exifEntry->data,m_byteOrder),'f',2); | ||
| } | ||
| exifEntry = exif_content_get_entry(m_exifData->ifd[EXIF_IFD_GPS], (ExifTag)EXIF_TAG_GPS_ALTITUDE_REF); | ||
| if(exifEntry){ | ||
| if(*(exifEntry->data)==0) | ||
| { | ||
| txt=txt+"m ASL"; //Meters Above Sea Level | ||
| }else{ | ||
| txt=txt+"m BSL"; //Meters Below Sea Level? | ||
| } | ||
| } | ||
| } | ||
| return txt; | ||
| } | ||
|
|
||
| const QString ExifHelper::getExifCamera(){ | ||
| QString txt(""); | ||
| if(m_exifData){ | ||
| ExifEntry *exifEntry = exif_data_get_entry(m_exifData, EXIF_TAG_MAKE); | ||
| if (exifEntry) | ||
| { | ||
| txt=txt+getExifAscii(exifEntry).toUpper()+", "; | ||
| } | ||
| exifEntry = exif_data_get_entry(m_exifData, EXIF_TAG_MODEL); | ||
| if (exifEntry) | ||
| { | ||
| txt=txt+getExifAscii(exifEntry); | ||
| } | ||
| } | ||
| return txt; | ||
| } | ||
|
|
||
| const QString ExifHelper::getExifAscii(ExifEntry *e){ | ||
| char data[e->size]; | ||
| strncpy(data,(char*)e->data,e->size); | ||
| return QVariant(data).toString(); | ||
| } | ||
| double ExifHelper::getExifRationalValue(const unsigned char *e, ExifByteOrder o){ | ||
| ExifRational r(exif_get_rational(e,o)); | ||
| return (r.numerator/(double)r.denominator); | ||
| } | ||
| double ExifHelper::getExifGeoCooValue(const unsigned char *e, ExifByteOrder o){ | ||
| return( getExifRationalValue(e,o)+ | ||
| getExifRationalValue(e+sizeof(ExifRational),o)/60+ | ||
| getExifRationalValue(e+2*sizeof(ExifRational),o)/3600 | ||
| ); | ||
| } | ||
|
|
||
| bool ExifHelper::isHeif(const std::string path){ | ||
| //TODO use libheif method heif_check_filetype(), as soon as raspi has libheif version =>1.4 | ||
| QFileInfo fileInfo(path.c_str()); | ||
| if(fileInfo.suffix().toLower()=="heic") return true; | ||
| return false; | ||
| } | ||
|
|
||
| ExifData* ExifHelper::getExifDataFromHeif(const std::string path){ | ||
| heif::Context ctx; | ||
| ctx.read_from_file(path); | ||
| heif::ImageHandle handle(ctx.get_primary_image_handle()); | ||
| std::vector<heif_item_id> ids(handle.get_list_of_metadata_block_IDs("Exif")); | ||
| if(ids.empty()) return NULL; | ||
| std::vector<uint8_t> data(handle.get_metadata(ids[0])); | ||
| const unsigned char *p(&data[4]); //first 4 bytes apparently offset to tiff data | ||
| ExifData *ptr(exif_data_new_from_data(p,data.size()-4)); | ||
| return ptr; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| #ifndef EXIFHELPER_H | ||
| #define EXIFHELPER_H | ||
|
|
||
| #include <libexif/exif-data.h> | ||
| #include <QString> | ||
|
|
||
|
|
||
| class ExifHelper | ||
| { | ||
| public: | ||
| ExifHelper(); | ||
| virtual ~ExifHelper(); | ||
|
|
||
| void setImage(const std::string path); | ||
| ExifData *getExifData(); | ||
| int getImageRotation(); | ||
| const QString getImageInfo(); | ||
| const QString getExifXResolution(); | ||
| const QString getExifYResolution(); | ||
| const QString getExifXDimension(); | ||
| const QString getExifYDimension(); | ||
| const QString getExifDate(); | ||
| const QString getExifGPS(); | ||
| const QString getExifCamera(); | ||
|
|
||
| private: | ||
| bool isHeif(const std::string path); | ||
| ExifData * getExifDataFromHeif(const std::string path); | ||
| const QString getExifAscii(ExifEntry *e); | ||
| double getExifRationalValue(const unsigned char *e, ExifByteOrder o); | ||
| double getExifGeoCooValue(const unsigned char *e, ExifByteOrder o); | ||
|
|
||
| ExifData *m_exifData; | ||
| bool m_isHeif; | ||
| ExifByteOrder m_byteOrder; | ||
| QString m_path; | ||
|
|
||
| }; | ||
|
|
||
| #endif // EXIFHELPER_H |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.