Skip to content
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

GTiff Reading and Writing #5618

Open
wants to merge 122 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
122 commits
Select commit Hold shift + click to select a range
e2e946a
replaced custom min/max with std::max/std::min
Kelvinrr Apr 29, 2024
4fbdb2e
left a gdal reference in
Kelvinrr Apr 29, 2024
55b6a6d
Initial changes for a GdalIoHandler and creating an external DN cube
acpaquette May 2, 2024
7faadbe
added write + tests
Kelvinrr May 3, 2024
71fadbf
Initial move away two flags on the cube to using the LabelAttachment …
acpaquette May 3, 2024
4582ff2
Addressed PR feedback
acpaquette May 8, 2024
6b45531
Added external gdal support to cube
acpaquette May 8, 2024
c026c13
Changed Tiff type to GTiff
acpaquette May 8, 2024
b8e14af
Renamed imageIoHandler to ImageIoHandler
acpaquette May 8, 2024
0d41bfd
Added pixeltype to gdaliohandler constructor
acpaquette May 6, 2024
a6d157a
Added gdal pixel type translation and missing special pixels for vari…
acpaquette May 8, 2024
fc8e4e8
Small fixes to get things working
acpaquette May 8, 2024
04dd5f6
Removed prints and added -1s back to read and write
acpaquette May 8, 2024
0da457b
Changed gdal reads to use the raw buffer and correctly apply the ISIS…
acpaquette May 8, 2024
d124b0f
Added initial pixel conversions and tests for writing
acpaquette May 8, 2024
0f75950
Final tests for pixel type reading and writing
acpaquette May 8, 2024
09b5c8d
Added tiff fixtures
acpaquette May 9, 2024
9e080b6
Transfered pixel type to gdal handler in cube
acpaquette May 9, 2024
61c4217
Silenced unsued return warning
acpaquette May 9, 2024
0bb5d8c
Reused file handler in TiffFixture
acpaquette May 9, 2024
5f923ac
added virtual band checks
Kelvinrr May 10, 2024
604c808
Added default compression for tiffs
acpaquette May 13, 2024
5ce9a20
Removed max again
acpaquette Nov 20, 2024
3e4adf9
Opened up the environment to get a work env
acpaquette Nov 20, 2024
24029ea
Fixed boolean comparisons against enum
acpaquette Nov 20, 2024
ea06217
Initial stab at fixing the buffer copy
acpaquette May 16, 2024
cb2abb3
Adds msk file writting for tiffs
acpaquette May 16, 2024
3a92ae0
Added boundary check for buffers
acpaquette May 16, 2024
3a610fb
Added fixture function to write a M x N x O tiff
acpaquette May 23, 2024
4467612
Reverted commented out Index access function Exceptions
acpaquette May 23, 2024
9963208
Default tiff DNs to the noDataValue
acpaquette May 23, 2024
5c247b3
Cleaned up buffer boundary handling for reads and writes
acpaquette May 23, 2024
6820edc
Added gdal io tests for reading outside of the image
acpaquette May 23, 2024
656477f
Updated shadow functional tests
acpaquette May 23, 2024
56d0150
Properly handled pointers for mac and linux
acpaquette May 24, 2024
14081bb
Removed commented out line
acpaquette May 24, 2024
ea92118
Addressed OS dependent shadow failures
acpaquette May 25, 2024
aa82731
Removed read contraints on ecubes
acpaquette Dec 11, 2024
0ed2884
Moved CubeIoHandler getters into public space
acpaquette Dec 11, 2024
84afea7
Moved CubeIoHandler getters into public space
acpaquette Dec 11, 2024
abe4f1a
Made getDataFile protected
acpaquette Dec 11, 2024
bfd4cd0
Made realDataFileName public on cube
acpaquette Dec 11, 2024
21185c1
Added new cube tests as gtests
acpaquette Dec 12, 2024
f644dc7
Added CubeBsqHandlerTests
acpaquette Dec 12, 2024
bb5177f
Removed old Cube unittests
acpaquette Dec 12, 2024
a8b3204
Removed cube truth
acpaquette Dec 12, 2024
cf30bb9
Handled gdal warnings in GdalIoHandler and its tests
acpaquette Dec 12, 2024
8788d09
Merge branch 'new_cube_tests' into gdal_io
acpaquette Dec 12, 2024
27c1b9c
Fixed compiler warnings in TiffFixture
acpaquette Dec 12, 2024
6a84388
Reverted data cube truncation
acpaquette Dec 12, 2024
e69b3a1
replaced custom min/max with std::max/std::min
Kelvinrr Apr 29, 2024
c4aa3e1
left a gdal reference in
Kelvinrr Apr 29, 2024
4aaa9ca
Initial changes for a GdalIoHandler and creating an external DN cube
acpaquette May 2, 2024
5f3790e
added write + tests
Kelvinrr May 3, 2024
0e92d08
Initial move away two flags on the cube to using the LabelAttachment …
acpaquette May 3, 2024
53299fc
Addressed PR feedback
acpaquette May 8, 2024
1c9fdf7
Added external gdal support to cube
acpaquette May 8, 2024
33fd96f
Changed Tiff type to GTiff
acpaquette May 8, 2024
fd40102
Renamed imageIoHandler to ImageIoHandler
acpaquette May 8, 2024
1a2136c
Added pixeltype to gdaliohandler constructor
acpaquette May 6, 2024
ba75d83
Added gdal pixel type translation and missing special pixels for vari…
acpaquette May 8, 2024
f4e9b13
Small fixes to get things working
acpaquette May 8, 2024
5efaa46
Removed prints and added -1s back to read and write
acpaquette May 8, 2024
603288f
Changed gdal reads to use the raw buffer and correctly apply the ISIS…
acpaquette May 8, 2024
5a2e460
Added initial pixel conversions and tests for writing
acpaquette May 8, 2024
aa3ce42
Final tests for pixel type reading and writing
acpaquette May 8, 2024
4667f7f
Added tiff fixtures
acpaquette May 9, 2024
fe167db
Transfered pixel type to gdal handler in cube
acpaquette May 9, 2024
efef488
Silenced unsued return warning
acpaquette May 9, 2024
f90714c
Reused file handler in TiffFixture
acpaquette May 9, 2024
171fbe7
added virtual band checks
Kelvinrr May 10, 2024
9b02c24
Added default compression for tiffs
acpaquette May 13, 2024
dbdd089
Removed max again
acpaquette Nov 20, 2024
54fcfb9
Opened up the environment to get a work env
acpaquette Nov 20, 2024
f491c63
Fixed boolean comparisons against enum
acpaquette Nov 20, 2024
1c99e94
Initial stab at fixing the buffer copy
acpaquette May 16, 2024
6220841
Adds msk file writting for tiffs
acpaquette May 16, 2024
49e2853
Added boundary check for buffers
acpaquette May 16, 2024
7c4a839
Added fixture function to write a M x N x O tiff
acpaquette May 23, 2024
063c211
Reverted commented out Index access function Exceptions
acpaquette May 23, 2024
f4da201
Default tiff DNs to the noDataValue
acpaquette May 23, 2024
8ef05af
Cleaned up buffer boundary handling for reads and writes
acpaquette May 23, 2024
fbb5535
Added gdal io tests for reading outside of the image
acpaquette May 23, 2024
619d24a
Updated shadow functional tests
acpaquette May 23, 2024
2b99b7b
Properly handled pointers for mac and linux
acpaquette May 24, 2024
bebe17f
Removed commented out line
acpaquette May 24, 2024
e030f8b
Addressed OS dependent shadow failures
acpaquette May 25, 2024
258cba0
Removed read contraints on ecubes
acpaquette Dec 11, 2024
8cced48
Handled gdal warnings in GdalIoHandler and its tests
acpaquette Dec 12, 2024
57d7add
Fixed compiler warnings in TiffFixture
acpaquette Dec 12, 2024
a6bbff3
Reverted data cube truncation
acpaquette Dec 12, 2024
9d5ddc9
gdal json pvl parsing
Kelvinrr May 15, 2024
a73d3d9
Update Pvl.cpp
Kelvinrr May 20, 2024
29b864d
Fixed gdal json to pvl parsing
acpaquette Dec 13, 2024
8af2fb0
Updated cube tests with tiff read/write changes
acpaquette Dec 13, 2024
e473cfd
Moved Tiff creation into a function on Cube and made Tiff Cube metada…
acpaquette Dec 16, 2024
1621834
Added PVL to Json export for GDAL metadata
Kelvinrr Jun 24, 2024
6c4fa34
Fixed PVLKeyword toJson writing arrays
acpaquette Dec 30, 2024
5d5fc68
Added string conversion for GTiff
acpaquette Dec 30, 2024
56aae0b
Extracted PVL read json lambda into static function
acpaquette Dec 30, 2024
8236bbe
Enforced Cube carry/manage GdalDataset object and made GdalIoHandler …
acpaquette Dec 30, 2024
ec3945f
Fixed tiff fixtures alpha bands
acpaquette Dec 30, 2024
862ae33
Seperated ISD spice contructor and init function from default init fu…
acpaquette Jan 6, 2025
8e12a87
Fixed blob reading and writing from hex
acpaquette Jan 6, 2025
fcc569d
Fixed error message when reading a gdal blob
acpaquette Jan 6, 2025
66d68b8
Fixed setting dataset ownership correctly on file constructor
acpaquette Jan 6, 2025
ad30e77
Fixed closing the dataset if we don't find the USGS metadata
acpaquette Jan 6, 2025
cdc4fa2
Fixed cube test expected label size
acpaquette Jan 6, 2025
3d1004d
Changed cube blob reading apps to access the blobs via the cube
acpaquette Jan 6, 2025
e785e0e
Merge branch 'temp_gdal_pvl' into gdal_io
acpaquette Jan 6, 2025
c0885ba
Small fixes
acpaquette Jan 7, 2025
d46d1f5
Fixed issue with cam2map requesting buffers completely outside of the…
acpaquette Jan 7, 2025
dab8493
Applied cube label reading to catlab
acpaquette Jan 10, 2025
cc55b31
Added blob read exception for GdalRead
acpaquette Jan 10, 2025
1c948ed
Exposed IException vector length
acpaquette Jan 10, 2025
c5ab602
Handled GDALs nodatavalue
acpaquette Jan 10, 2025
a5d0237
Moved GDAL pvl label construction into the Cube
acpaquette Jan 10, 2025
7f906ec
Commented out mask creation
acpaquette Jan 10, 2025
84506aa
Forced label reading to come from the cube in ctxcal
acpaquette Jan 10, 2025
cdcccc3
Fixed data ownership when reading metadata from GTiff
acpaquette Jan 10, 2025
243e0a0
Finalized mapping group generation from spatial reference
acpaquette Jan 17, 2025
3594d90
Fix reading URLs in qview and blob reading
acpaquette Jan 17, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ dependencies:
- ale =0.10.0,<1
- aom
- armadillo
- boost >=1.78.0,<1.79
- boost-cpp >=1.78.0,<1.79
- boost >=1.76.0,<1.82
- boost-cpp >=1.76.0,<1.82
- blas
- usgs-astrogeology::bullet
- bz2file
Expand All @@ -23,6 +23,7 @@ dependencies:
- ffmpeg
- geos >=3.12, <3.13
- geotiff
- gdal >=3.5 ,<3.9.0a0
- gmp
- graphviz
- conda-forge::gsl >=2.6, <2.7
Expand All @@ -35,10 +36,10 @@ dependencies:
- kalasiris
- krb5
- libgdal >=3.7,<3.8
- libopencv >=4.7,<4.8
- libopencv >=4.5,<4.8
- libpng >=1.6.34,<1.7
- libprotobuf
- libtiff >=4.5,<4.6
- libtiff >=4.5,<4.8
- libxml2
- make
- mesalib
Expand All @@ -48,17 +49,17 @@ dependencies:
- nlohmann_json=3.11.2
- ninja >=1.7.2,<1.8
- nn
- opencv >=4.7,<4.8
- opencv >=4.5,<4.8
- openssl >=3.1.2,<3.2
- pcl >=1.13,<1.14
- plio
- protobuf
- python >=3.10
- python_abi >=3.10
- python >=3.9
- python_abi >=3.9
- pytest
- rclone
- qhull
- qt-main>=5.15.8, <5.16
- qt-main>=5.15, <5.16
- qwt <6.3.0
- sqlite >=3.46.0,<3.47
- suitesparse <7.7.0
Expand Down
2 changes: 1 addition & 1 deletion gtest
Submodule gtest updated 41 files
+1 −1 CMakeLists.txt
+4 −4 CONTRIBUTING.md
+8 −8 README.md
+1 −1 ci/linux-presubmit.sh
+7 −7 docs/advanced.md
+39 −18 docs/faq.md
+0 −6 docs/gmock_cook_book.md
+2 −2 docs/gmock_for_dummies.md
+11 −11 docs/primer.md
+1 −1 docs/reference/assertions.md
+2 −1 docs/reference/mocking.md
+1 −1 docs/reference/testing.md
+10 −10 googlemock/CMakeLists.txt
+3 −3 googlemock/README.md
+1 −7 googlemock/include/gmock/gmock-actions.h
+4 −5 googlemock/include/gmock/gmock-function-mocker.h
+2 −2 googlemock/include/gmock/gmock-matchers.h
+7 −8 googlemock/include/gmock/gmock.h
+1 −1 googlemock/src/gmock-matchers.cc
+0 −9 googlemock/test/gmock-matchers-comparisons_test.cc
+1 −1 googlemock/test/gmock-spec-builders_test.cc
+13 −13 googletest/CMakeLists.txt
+2 −2 googletest/README.md
+19 −19 googletest/cmake/internal_utils.cmake
+10 −9 googletest/include/gtest/gtest-message.h
+7 −29 googletest/include/gtest/gtest-printers.h
+5 −4 googletest/include/gtest/gtest.h
+3 −1 googletest/include/gtest/internal/gtest-death-test-internal.h
+6 −5 googletest/include/gtest/internal/gtest-internal.h
+1 −3 googletest/include/gtest/internal/gtest-param-util.h
+23 −47 googletest/include/gtest/internal/gtest-port.h
+1 −1 googletest/src/gtest-death-test.cc
+1 −1 googletest/src/gtest-filepath.cc
+1 −1 googletest/src/gtest-internal-inl.h
+10 −37 googletest/src/gtest-port.cc
+3 −5 googletest/src/gtest.cc
+3 −3 googletest/test/googletest-port-test.cc
+0 −16 googletest/test/googletest-printers-test.cc
+41 −23 googletest/test/gtest_help_test.py
+1 −1 googletest/test/gtest_unittest.cc
+4 −4 googletest_deps.bzl
3 changes: 2 additions & 1 deletion isis/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ find_package(CSM 3.0.3.3 REQUIRED)
find_package(CSPICE 65 REQUIRED)
find_package(Eigen REQUIRED)
find_package(Embree 3.13.0 REQUIRED)
find_package(GDAL REQUIRED CONFIG)
find_package(GeoTIFF 2 REQUIRED)
SET(GSL_ROOT_DIR $ENV{CONDA_PREFIX})
find_package(GSL 2.2.1 REQUIRED)
Expand Down Expand Up @@ -353,7 +354,7 @@ foreach (_variableName ${_variableNames})
endforeach()

# add target based linkages to ALLLIBS variable
list(APPEND ALLLIBS pantor::inja sensorutilities protobuf::libprotobuf embree)
list(APPEND ALLLIBS pantor::inja sensorutilities protobuf::libprotobuf embree GDAL::GDAL)

# Sometimes we add the same lib more than once (especially with LIBDIRS)
list(REMOVE_DUPLICATES ALLLIBDIRS)
Expand Down
6 changes: 3 additions & 3 deletions isis/src/apollo/apps/apollopanstitcher/apollopanstitcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -715,11 +715,11 @@ namespace Isis {
att.setFileFormat( panC[0]->format() );
att.setByteOrder( panC[0]->byteOrder() );
att.setPixelType( panC[0]->pixelType() );
if (panC[0]->labelsAttached()) {
att.setLabelAttachment(AttachedLabel);
if (panC[0]->labelsAttached() == Cube::AttachedLabel) {
att.setLabelAttachment(Cube::AttachedLabel);
}
else {
att.setLabelAttachment(DetachedLabel);
att.setLabelAttachment(Cube::DetachedLabel);
}

//define an output cube
Expand Down
4 changes: 2 additions & 2 deletions isis/src/base/apps/cathist/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ void IsisMain() {
}

// Extract history from file
Blob historyBlob("IsisCube", "History", fromfile.expanded());
History hist(historyBlob);
Cube cube(fromfile);
History hist = cube.readHistory();
Pvl pvl = hist.ReturnHist();

// Print full history
Expand Down
3 changes: 2 additions & 1 deletion isis/src/base/apps/catlab/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ void IsisMain() {
QString file = ui.GetCubeName("FROM");

// Extract label from file
Pvl label(file);
Cube cube(file);
Pvl label = *cube.label();

// Output to file if entered
if(ui.WasEntered("TO")) {
Expand Down
5 changes: 3 additions & 2 deletions isis/src/base/apps/catoriglab/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ void IsisMain() {
UserInterface &ui = Application::GetUserInterface();
QString file = ui.GetCubeName("FROM");

Pvl fromLabel(file);
Cube fromCube(file);
Pvl fromLabel = *(fromCube.label());
if ( fromLabel.hasObject("OriginalLabel") ) {
OriginalLabel origLab(file);
OriginalLabel origLab = fromCube.readOriginalLabel();
Pvl pvl = origLab.ReturnLabels();
if (ui.IsInteractive()) {
Application::GuiLog(pvl);
Expand Down
2 changes: 1 addition & 1 deletion isis/src/base/apps/crop/crop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ namespace Isis {
}

// Read the table into a table object
Table table(obj["Name"], from);
Table table = cube->readTable(obj["Name"]);

// We are not going to bother with line/sample associations; they apply
// only to the alpha cube at this time. I'm leaving this code here for the
Expand Down
2 changes: 1 addition & 1 deletion isis/src/base/apps/noproj/noproj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ namespace Isis {
CubeAttributeOutput cao;

// Can we do a regular label? Didn't work on 12-15-2006
cao.setLabelAttachment(Isis::DetachedLabel);
cao.setLabelAttachment(Cube::DetachedLabel);
FileName matchCubeFile = FileName::createTempFile("$Temporary/match.cub");
QString matchCubeFileNoExt = matchCubeFile.path() + "/" + matchCubeFile.baseName();

Expand Down
2 changes: 1 addition & 1 deletion isis/src/base/apps/shadow/ShadowFunctor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ namespace Isis {


Portal portal(3, 3, m_inputDem->pixelType(), -0.5, -0.5);
portal.SetPosition(sample, line, input.Band());
portal.SetPosition(sample + 1, line + 1, input.Band());

if (!portal.CopyOverlapFrom(input)) {
m_inputDem->read(portal);
Expand Down
2 changes: 0 additions & 2 deletions isis/src/base/apps/spiceinit/spiceinit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,6 @@ namespace Isis {
}
}
icube->deleteGroup("CsmInfo");

p.WriteHistory(*icube);
p.EndProcess();
}
Expand Down Expand Up @@ -592,7 +591,6 @@ namespace Isis {
icube->putGroup(originalKernels);
return false;
}

return true;
}

Expand Down
3 changes: 2 additions & 1 deletion isis/src/base/apps/tabledump/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ void IsisMain() {
UserInterface &ui = Application::GetUserInterface();
FileName file = ui.GetCubeName("FROM");
QString tableName = ui.GetString("NAME");
Table table(tableName, file.expanded());
Cube fromCube(file);
Table table = fromCube.readTable(tableName);

// Set the character to separate the entries
QString delimit;
Expand Down
132 changes: 126 additions & 6 deletions isis/src/base/objs/Blob/Blob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ find files of those names at the top level of this repository. **/
#include <cstring>
#include <fstream>
#include <sstream>
#include <filesystem>
#include <gdal_priv.h>

#include <QDebug>

Expand All @@ -17,7 +19,11 @@ find files of those names at the top level of this repository. **/
#include "Message.h"
#include "Pvl.h"

namespace fs = std::filesystem;
using json = nlohmann::json;
using ordered_json = nlohmann::ordered_json;
using namespace std;

namespace Isis {
/**
* Constructs a Blob object using a name and type.
Expand Down Expand Up @@ -244,6 +250,33 @@ namespace Isis {
}
}

void Blob::ReadGdal(GDALDataset *dataset) {
try {
std::string key = QString(p_type + "_" + p_blobName).toStdString();
const char *jsonblobStr = dataset->GetMetadataItem(key.c_str(), "USGS");
if (jsonblobStr == nullptr) {
QString msg = "The key [" + QString::fromStdString(key) + "] does not exist on the geodata set.";
throw IException( IException::Io, msg, _FILEINFO_);
}
ordered_json jsonblob = ordered_json::parse(jsonblobStr);
std::string blobData = jsonblob[key]["Data"];
jsonblob[key].erase("Data");

Pvl pvl;
Pvl::readObject(pvl, jsonblob);

p_blobName = QString::fromStdString(jsonblob[key]["Name"]);
p_type = QString::fromStdString(jsonblob[key]["_container_name"]);

Find(pvl);
ReadData(blobData);
}
catch(exception &e) {
QString msg = "Failed to read blob [" + p_blobName + "]: " + e.what();
throw IException(IException::Io, msg, _FILEINFO_);
}
}

/**
* This method reads Pvl values from a specified file.
*
Expand All @@ -255,7 +288,7 @@ namespace Isis {
void Blob::Read(const QString &file, const std::vector<PvlKeyword> keywords) {
// Expand the filename
QString temp(FileName(file).expanded());

// Get the pvl
Pvl pvl;
try {
Expand Down Expand Up @@ -405,6 +438,46 @@ namespace Isis {
p_buffer = buffer;
}

void Blob::WriteGdal(GDALDataset *dataset) {
try {
WriteInit();
Pvl pvl;
pvl.addObject(p_blobPvl);
ostringstream os;
os << pvl << endl;
os.seekp(0, std::ios::end);

stringstream stream;
WriteData(stream);
PvlObject &blobObj = pvl.findObject(p_type);

blobObj["Bytes"] = toString(p_nbytes);
blobObj["StartByte"] = toString(1);
if(blobObj.hasKeyword("Data")) {
blobObj["Data"] = QString::fromStdString(stream.str());
}
else {
blobObj += PvlKeyword("Data", QString::fromStdString(stream.str()));
}

if(blobObj.hasKeyword("Name")) {
blobObj["Name"] = p_blobName;
}
else {
blobObj += PvlKeyword("Name", p_blobName);
}

// update metadata
string jsonblobstr = pvl.toJson().dump();
string key = this->Type().toStdString() + "_" + this->Name().toStdString();
dataset->SetMetadataItem(key.c_str(), jsonblobstr.c_str(), "USGS");
}
catch(exception &e) {
cout << "Failed to write blob [" + p_blobName + "]: " << e.what() << endl;
}
}


/**
* Write the blob data out to a file.
*
Expand All @@ -415,7 +488,7 @@ namespace Isis {
* @throws IException::Io - Error creating file
*/
void Blob::Write(const QString &file) {
// Determine the size of the label and write it out
// Determine the size of the label and write it out
try {
WriteInit();
Pvl pvl;
Expand Down Expand Up @@ -456,6 +529,7 @@ namespace Isis {
}
}


/**
* Write the blob data out to a Pvl object.
* @param pvl The pvl object to update
Expand All @@ -464,10 +538,10 @@ namespace Isis {
* the name of the file
*/
void Blob::Write(Pvl &pvl, std::fstream &stm,
const QString &detachedFileName, bool overwrite) {
const QString &detachedFileName, bool overwrite, bool inline_data) {

// Handle 64-bit I/O
WriteInit();

// Find out where they wanted to write the blob
streampos sbyte = stm.tellp();
sbyte += 1;
Expand All @@ -482,11 +556,9 @@ namespace Isis {
p_blobPvl += PvlKeyword("^" + p_type, detachedFileName);
}


p_blobPvl["StartByte"] = toString((BigInt)sbyte);
p_blobPvl["Bytes"] = toString(p_nbytes);


// See if the blob is already in the file
bool found = false;
if (overwrite) {
Expand Down Expand Up @@ -570,6 +642,54 @@ namespace Isis {
}


/**
* Writes blob data to a stream
*
* @param stream Output steam blob data will be written to
*
* @throws IException::Io - Error writing data to stream
*/
void Blob::WriteData(std::stringstream &stream) {
stream << std::hex;
int copy;
for (int i = 0; i < p_nbytes; ++i) {
memcpy(&copy, &p_buffer[i], 1);
stream << std::setw(2) << std::setfill('0') << copy;
}

if (!stream.good()) {
QString msg = "Error writing data to " + p_type + " [" + p_blobName + "]";
throw IException(IException::Io, msg, _FILEINFO_);
}
}


/**
* Writes blob data to a stream
*
* @param stream Output steam blob data will be written to
*
* @throws IException::Io - Error writing data to stream
*/
void Blob::ReadData(string &hexdata) {
// Read the binary data
if (p_buffer != NULL) delete [] p_buffer;
p_buffer = new char[p_nbytes];

// Loop through the hex string and bytes, hex is two characters at a time
for (size_t i=0,j=0; i < p_nbytes; i++,j+=2) {
string byteString = hexdata.substr(j, 2);

int byteValue = static_cast<int>(
stoi(byteString, nullptr, 16));

// Add the byte to the byte array
p_buffer[i] = byteValue;
}
}



/**
* Checks pvl object and returns whether or not it is a Blob
*
Expand Down
Loading
Loading