add xmp injection and disable some log messages

This commit is contained in:
2017-09-27 23:02:39 +01:00
parent 90ec0b6f7b
commit 2c0007c3c1
7 changed files with 59 additions and 9 deletions

View File

@@ -832,6 +832,7 @@ void ui::Canvas::export_equirectangular(std::string data_path)
jpge::params params;
params.m_quality = 100;
bool saved = jpge::compress_image_to_jpeg_file(name, m_latlong.getWidth(), m_latlong.getHeight(), 4, latlong_data.get(), params);
inject_xmp(name);
//int ret = stbi_write_png(name, m_latlong.getWidth(), m_latlong.getHeight(), 4, latlong_data.get(), m_latlong.stride());
#ifdef __IOS__
image = [UIImage imageWithContentsOfFile:[NSString stringWithUTF8String:name]];
@@ -849,6 +850,54 @@ void ui::Canvas::export_equirectangular(std::string data_path)
glActiveTexture(GL_TEXTURE0);
}
void ui::Canvas::inject_xmp(std::string jpg_path)
{
static const char xmp[] =
"http://ns.adobe.com/xap/1.0/\0" R"(<?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?>
<x:xmpmeta xmlns:x="adobe:ns:meta/" xmptk="SAMSUNG 360CAM">
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<rdf:Description rdf:about="" xmlns:GPano="http://ns.google.com/photos/1.0/panorama/">
<GPano:ProjectionType>equirectangular</GPano:ProjectionType>
<GPano:UsePanoramaViewer>True</GPano:UsePanoramaViewer>
<GPano:CroppedAreaLeftPixels>0</GPano:CroppedAreaLeftPixels>
<GPano:CroppedAreaTopPixels>0</GPano:CroppedAreaTopPixels>
<GPano:PoseHeadingDegrees>0</GPano:PoseHeadingDegrees>
<GPano:PosePitchDegrees>0</GPano:PosePitchDegrees>
<GPano:PoseRollDegrees>0</GPano:PoseRollDegrees>
<GPano:StitchingSoftware>PanoPainter</GPano:StitchingSoftware>
</rdf:Description>
</rdf:RDF>
</x:xmpmeta>
<?xpacket end="r"?>)";
FILE* fp = fopen(jpg_path.c_str(), "rb");
fseek(fp, 0, SEEK_END);
long len = ftell(fp);
fseek(fp, 0, SEEK_SET);
unsigned char* jpeg_data = (unsigned char*)malloc(len);
fread(jpeg_data, len, 1, fp);
fclose(fp);
fp = fopen(jpg_path.c_str(), "wb");
int i = 0;
while (i < len && !(jpeg_data[i] == 0xff && jpeg_data[i + 1] == 0xd8)) i++;
i += 2;
unsigned char* xmp_section = (unsigned char*)malloc(sizeof(xmp) + 4);
xmp_section[0] = 0xff;
xmp_section[1] = 0xe1;
xmp_section[2] = ((int)sizeof(xmp) + 2) >> 8;
xmp_section[3] = ((int)sizeof(xmp) + 2) >> 0;
memcpy(xmp_section + 4, xmp, sizeof(xmp));
fwrite(jpeg_data, 1, i, fp);
fwrite(xmp_section, 1, sizeof(xmp) + 4, fp);
fwrite(jpeg_data + i, 1, len - i, fp);
fclose(fp);
}
void ui::Canvas::export_anim(std::string data_path)
{
// save viewport and clear color states