Skip to content

Commit

Permalink
fix stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
qbnu committed Jun 17, 2023
1 parent 3aa0b7c commit a271ed3
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 40 deletions.
25 changes: 0 additions & 25 deletions src/JPEGView/EXIFDisplayCtl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,6 @@ static int GetFileNameHeight(HDC dc) {
return size.cy;
}

static GPSCoordinate* GetGPSCoordinate(double coord) {
double degrees = (int)coord;
double minutes = (int)abs(60 * (coord - degrees));
double seconds = 3600 * abs(coord - degrees) - 60 * minutes;
return new GPSCoordinate(NULL, degrees, minutes, seconds);
}

static CString CreateGPSString(GPSCoordinate* latitude, GPSCoordinate* longitude) {
const int BUFF_SIZE = 96;
TCHAR buff[BUFF_SIZE];
Expand All @@ -32,15 +25,6 @@ static CString CreateGPSString(GPSCoordinate* latitude, GPSCoordinate* longitude
return CString(buff);
}

static CString CreateGPSString(double latitude, double longitude) {
GPSCoordinate* lat = GetGPSCoordinate(latitude);
GPSCoordinate* lon = GetGPSCoordinate(longitude);
CString ret = CreateGPSString(lat, lon);
delete lat;
delete lon;
return ret;
}

static CString CreateGPSURL(GPSCoordinate* latitude, GPSCoordinate* longitude) {
double lng = longitude->Degrees + longitude->Minutes / 60 + longitude->Seconds / (60 * 60);
if (_tcsicmp(longitude->GetReference(), _T("W")) == 0)
Expand All @@ -64,15 +48,6 @@ static CString CreateGPSURL(GPSCoordinate* latitude, GPSCoordinate* longitude) {
return mapProvider;
}

static CString CreateGPSURL(double latitude, double longitude) {
GPSCoordinate* lat = GetGPSCoordinate(latitude);
GPSCoordinate* lon = GetGPSCoordinate(longitude);
CString ret = CreateGPSURL(lat, lon);
delete lat;
delete lon;
return ret;
}

CEXIFDisplayCtl::CEXIFDisplayCtl(CMainDlg* pMainDlg, CPanel* pImageProcPanel) : CPanelController(pMainDlg, false) {
m_bVisible = CSettingsProvider::This().ShowFileInfo();
m_nFileNameHeight = 0;
Expand Down
4 changes: 4 additions & 0 deletions src/JPEGView/EXIFReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,10 @@ void CEXIFReader::ReadGPSData(uint8* pTIFFHeader, uint8* pTagGPSIFD, int nApp1Si
uint8* pTagAltitude = FindTag(pGPSIFD, pLastGPS, 0x6, bLittleEndian);
if (pTagAltitude != NULL) {
m_dAltitude = ReadDoubleTag(pTagAltitude, pTIFFHeader, bLittleEndian);
uint8* pTagAltitudeRef = FindTag(pGPSIFD, pLastGPS, 0x5, bLittleEndian);
if (pTagAltitudeRef != NULL && *(pTagAltitudeRef + 8) == 1) {
m_dAltitude *= -1;
}
}
}

Expand Down
13 changes: 9 additions & 4 deletions src/JPEGView/RAWWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ CJPEGImage* RawReader::ReadImage(LPCTSTR strFileName, bool& bOutOfMemory)
RawProcessor.free_image();
CRawMetadata* metadata = new CRawMetadata(RawProcessor.imgdata.idata.make, RawProcessor.imgdata.idata.model, RawProcessor.imgdata.other.timestamp,
RawProcessor.imgdata.color.flash_used != 0.0f, RawProcessor.imgdata.other.iso_speed, RawProcessor.imgdata.other.shutter,
RawProcessor.imgdata.other.focal_len, RawProcessor.imgdata.other.aperture, RawProcessor.imgdata.sizes.flip, width, height);
RawProcessor.imgdata.other.focal_len, RawProcessor.imgdata.other.aperture, RawProcessor.imgdata.sizes.flip, width, height,
RawProcessor.imgdata.other.parsed_gps.latitude, RawProcessor.imgdata.other.parsed_gps.latref, RawProcessor.imgdata.other.parsed_gps.longitude,
RawProcessor.imgdata.other.parsed_gps.longref, RawProcessor.imgdata.other.parsed_gps.altitude, RawProcessor.imgdata.other.parsed_gps.altref);
if (pPixelData)
Image = new CJPEGImage(width, height, pPixelData, NULL, colors, 0, IF_CameraRAW, false, 0, 1, 0, NULL, false, metadata);
} else {
Expand All @@ -56,16 +58,19 @@ CJPEGImage* RawReader::ReadImage(LPCTSTR strFileName, bool& bOutOfMemory)
{
CRawMetadata* metadata = new CRawMetadata(RawProcessor.imgdata.idata.make, RawProcessor.imgdata.idata.model, RawProcessor.imgdata.other.timestamp,
RawProcessor.imgdata.color.flash_used != 0.0f, RawProcessor.imgdata.other.iso_speed, RawProcessor.imgdata.other.shutter,
RawProcessor.imgdata.other.focal_len, RawProcessor.imgdata.other.aperture, RawProcessor.imgdata.sizes.flip, width, height);
RawProcessor.imgdata.other.focal_len, RawProcessor.imgdata.other.aperture, RawProcessor.imgdata.sizes.flip, width, height,
RawProcessor.imgdata.other.parsed_gps.latitude, RawProcessor.imgdata.other.parsed_gps.latref, RawProcessor.imgdata.other.parsed_gps.longitude,
RawProcessor.imgdata.other.parsed_gps.longref, RawProcessor.imgdata.other.parsed_gps.altitude, RawProcessor.imgdata.other.parsed_gps.altref);

Image = new CJPEGImage(width, height, pPixelData, Helpers::FindEXIFBlock(thumb->data, thumb->data_size), colors,
Image = new CJPEGImage(width, height, pPixelData, NULL /* Helpers::FindEXIFBlock(thumb->data, thumb->data_size) */, colors,
Helpers::CalculateJPEGFileHash(thumb->data, thumb->data_size), IF_JPEG_Embedded, false, 0, 1, 0, NULL, false, metadata);

Image->SetJPEGComment(Helpers::GetJPEGComment(thumb->data, thumb->data_size));
Image->SetJPEGChromoSampling(eChromoSubSampling);
}
RawProcessor.dcraw_clear_mem(thumb);
}
// RawProcessor.recycle();

return Image;
}
}
35 changes: 24 additions & 11 deletions src/JPEGView/RawMetadata.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once


#include "EXIFReader.h"

// Metadata read from camera RAW images
class CRawMetadata
Expand All @@ -18,17 +18,17 @@ class CRawMetadata
int GetOrientation() { return m_orientatation; }
int GetWidth() { return m_width; }
int GetHeight() { return m_height; }
double GetGPSLatitude() { return m_latitude; }
double GetGPSLongitude() { return m_longitude; }
GPSCoordinate* GetGPSLatitude() { return m_pLatitude; }
GPSCoordinate* GetGPSLongitude() { return m_pLongitude; }
double GetGPSAltitude() { return m_altitude; }
bool IsGPSInformationPresent() { return m_latitude != UNKNOWN_DOUBLE_VALUE && m_longitude != UNKNOWN_DOUBLE_VALUE; }
bool IsGPSAltitudePresent() { return m_altitude != UNKNOWN_DOUBLE_VALUE; }
bool IsGPSInformationPresent() { return m_pLatitude != NULL && m_pLongitude != NULL; }
bool IsGPSAltitudePresent() { return m_altitude != CEXIFReader::UNKNOWN_DOUBLE_VALUE; }

constexpr static double UNKNOWN_DOUBLE_VALUE = 283740261.192864;

// Note: Orientation is in cdraw format ('flip' global variable in cdraw_mod.cpp)
CRawMetadata(char* manufacturer, char* model, time_t acquisitionTime, bool flashFired, double isoSpeed, double exposureTime, double focalLength,
double aperture, int orientation, int width, int height, double latitude = UNKNOWN_DOUBLE_VALUE, double longitude = UNKNOWN_DOUBLE_VALUE, double altitude = UNKNOWN_DOUBLE_VALUE)
double aperture, int orientation, int width, int height, float* latitude = NULL, char latref = 0, float* longitude = NULL, char longref = 0,
double altitude = CEXIFReader::UNKNOWN_DOUBLE_VALUE, char altref = 0)
{
m_manufacturer = CString(manufacturer);
m_model = CString(model);
Expand All @@ -40,9 +40,14 @@ class CRawMetadata
m_orientatation = orientation;
m_width = width;
m_height = height;
m_latitude = latitude;
m_longitude = longitude;
m_altitude = altitude;
char zeros[3 * sizeof(float)] = { 0 };
if (latitude != NULL && longitude != NULL && !(memcmp(latitude, zeros, 3 * sizeof(float)) == 0 && memcmp(longitude, zeros, 3 * sizeof(float)) == 0)) {
m_pLatitude = new GPSCoordinate((LPCTSTR)latref, latitude[0], latitude[1], latitude[2]);
m_pLongitude = new GPSCoordinate((LPCTSTR)longref, longitude[0], longitude[1], longitude[2]);
} else {
m_pLatitude = m_pLongitude = NULL;
}
m_altitude = altref == 1 ? -altitude : altitude;

LONGLONG time = (LONGLONG)acquisitionTime * 10000000 + 116444736000000000;
FILETIME fileTime;
Expand All @@ -51,6 +56,12 @@ class CRawMetadata
::FileTimeToSystemTime(&fileTime, &m_acquisitionTime);
}

~CRawMetadata(void) {
delete m_pLatitude;
delete m_pLongitude;
}


private:
CString m_manufacturer;
CString m_model;
Expand All @@ -62,6 +73,8 @@ class CRawMetadata
int m_orientatation;
int m_width, m_height;
SYSTEMTIME m_acquisitionTime;
double m_latitude, m_longitude, m_altitude;
GPSCoordinate* m_pLatitude;
GPSCoordinate* m_pLongitude;
double m_altitude;
};

0 comments on commit a271ed3

Please sign in to comment.