Skip to content

Commit

Permalink
start point for saving meta data in PNGs (issue #8)
Browse files Browse the repository at this point in the history
- we could save georeferencing information
- or even a complete JSON output of all used parameters!
  • Loading branch information
der-stefan committed Aug 13, 2020
1 parent c811410 commit 7b7d0a3
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 11 deletions.
18 changes: 16 additions & 2 deletions src/imagewriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
#include <iostream>
#include <string>

using namespace std;


#define DEFAULT_JPEG_QUALITY 90

Expand All @@ -65,9 +67,21 @@ ImageWriter::ImageWriter(const std::string &filename, ImageType imagetype,
default:
#ifdef HAVE_LIBPNG
case IMAGETYPE_PNG:
m_png_ptr =
png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
m_png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
m_info_ptr = png_create_info_struct(m_png_ptr);
// write metadata
m_text_ptr[0].key = strdup("Title");
m_text_ptr[0].text = strdup("SPLAT!");
m_text_ptr[0].compression = PNG_TEXT_COMPRESSION_NONE;
m_text_ptr[1].key = strdup("projection");
m_text_ptr[1].text = strdup("EPSG:4326");
m_text_ptr[1].compression = PNG_TEXT_COMPRESSION_NONE;
m_text_ptr[2].key = strdup("bounds");
bounds_str = ("[["+to_string(m_south)+","+to_string(m_west)+"],["+to_string(m_north)+","+to_string(m_east)+"]]").c_str();
sprintf(bounds, "%s", bounds_str.c_str());
m_text_ptr[2].text = bounds;
m_text_ptr[2].compression = PNG_TEXT_COMPRESSION_NONE;
png_set_text(m_png_ptr, m_info_ptr, m_text_ptr, PNG_NTEXT);
png_init_io(m_png_ptr, m_fp);
png_set_IHDR(m_png_ptr, m_info_ptr, m_width, m_height,
8, /* 8 bits per color or 24 bits per pixel for RGB */
Expand Down
4 changes: 4 additions & 0 deletions src/imagewriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,12 @@ class ImageWriter {
unsigned char *m_imgline_alpha = NULL;

#ifdef HAVE_LIBPNG
#define PNG_NTEXT 4
png_structp m_png_ptr = NULL;
png_infop m_info_ptr = NULL;
png_text m_text_ptr[PNG_NTEXT] = {0};
std::string bounds_str;
char bounds[80];
#endif
#ifdef HAVE_LIBGDAL
GDALDriver *poDriver;
Expand Down
20 changes: 11 additions & 9 deletions src/json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#include <fstream>
#include <bits/stdc++.h>

using namespace std;

Json::Json(const ElevationMap &em, const SplatRun &sr)
: path(sr.arraysize, sr.ppd), em(em), sr(sr) {}

Expand All @@ -28,18 +30,18 @@ Json::Json(const ElevationMap &em, const SplatRun &sr)
/* read in argv[] as an associative array.
* You can now access the list e.g. by args["o"] which will not fail if the argument is not set
*
* std::map<std::string, std::string>::iterator i;
* map<string, string>::iterator i;
* for (i=args.begin(); i != args.end(); i++) {
* std::cout << i->first << ": " << i->second << std::endl;
* cout << i->first << ": " << i->second << endl;
* }
*/
//typedef std::map<std::string,std::string> arg_t;
//typedef map<string,string> arg_t;
/* arg_t args;
std::string curr_arg = "";
string curr_arg = "";
int curr_arg_i = 0;
for(int i=0; i<argc; i++) { // step through argv[] array
std::string arg = argv[i];
string arg = argv[i];
if(arg.find("-") == 0) { // check if current argument has leading "-"
curr_arg = arg.erase(0,1); // remove leading "-" and save as new array entry
curr_arg_i = i; // save position for multiple parameters
Expand All @@ -61,7 +63,7 @@ Json::Json(const ElevationMap &em, const SplatRun &sr)
// === unsorted end ===


void Json::WriteJSON(arg_t args, Site tx_site, Lrp lrp, std::string mapfile) {
void Json::WriteJSON(arg_t args, Site tx_site, Lrp lrp, string mapfile) {
int x;
char report_name[80];

Expand All @@ -73,7 +75,7 @@ void Json::WriteJSON(arg_t args, Site tx_site, Lrp lrp, std::string mapfile) {
report_name[x] == 47)
report_name[x] = '_';

std::ofstream reportfile(report_name);
ofstream reportfile(report_name);

reportfile << "{\n";
reportfile << "\t\"splat\": \"" << sr.splat_version.c_str() << "\",\n";
Expand Down Expand Up @@ -104,7 +106,7 @@ void Json::WriteJSON(arg_t args, Site tx_site, Lrp lrp, std::string mapfile) {
reportfile << "\t},\n";
reportfile << "\t\"arguments\": {\n";

std::map<std::string, std::string>::iterator i;
map<string, string>::iterator i;
int pos = 0;
int len = args.size();
for (i=args.begin(); i != args.end(); i++, pos++) {
Expand All @@ -121,7 +123,7 @@ void Json::WriteJSON(arg_t args, Site tx_site, Lrp lrp, std::string mapfile) {

reportfile.close();

std::cout << "\nJSON file written to: " << report_name;
cout << "\nJSON file written to: " << report_name;

fflush(stdout);
}

0 comments on commit 7b7d0a3

Please sign in to comment.