MCPcopy Create free account
hub / github.com/Exiv2/exiv2 / doWriteMetadata

Method doWriteMetadata

src/psdimage.cpp:327–545  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

325} // PsdImage::writeMetadata
326
327void PsdImage::doWriteMetadata(BasicIo& outIo) {
328 if (!io_->isopen())
329 throw Error(ErrorCode::kerInputDataReadFailed);
330 if (!outIo.isopen())
331 throw Error(ErrorCode::kerImageWriteFailed);
332
333#ifdef EXIV2_DEBUG_MESSAGES
334 std::cout << "Exiv2::PsdImage::doWriteMetadata: Writing PSD file " << io_->path() << "\n";
335 std::cout << "Exiv2::PsdImage::doWriteMetadata: tmp file created " << outIo.path() << "\n";
336#endif
337
338 // Ensure that this is the correct image type
339 if (!isPsdType(*io_, true)) {
340 if (io_->error() || io_->eof())
341 throw Error(ErrorCode::kerInputDataReadFailed);
342 throw Error(ErrorCode::kerNoImageInInputData);
343 }
344
345 io_->seek(0, BasicIo::beg); // rewind
346
347 DataBuf lbuf(4096);
348 byte buf[8];
349
350 // Get Photoshop header from original file
351 byte psd_head[26];
352 if (io_->read(psd_head, 26) != 26)
353 throw Error(ErrorCode::kerNotAnImage, "Photoshop");
354
355 // Write Photoshop header data out to new PSD file
356 if (outIo.write(psd_head, 26) != 26)
357 throw Error(ErrorCode::kerImageWriteFailed);
358
359 // Read colorDataLength from original PSD
360 if (io_->read(buf, 4) != 4)
361 throw Error(ErrorCode::kerNotAnImage, "Photoshop");
362
363 uint32_t colorDataLength = getULong(buf, bigEndian);
364
365 // Write colorDataLength
366 ul2Data(buf, colorDataLength, bigEndian);
367 if (outIo.write(buf, 4) != 4)
368 throw Error(ErrorCode::kerImageWriteFailed);
369#ifdef EXIV2_DEBUG_MESSAGES
370 std::cerr << std::dec << "colorDataLength: " << colorDataLength << "\n";
371#endif
372 // Copy colorData
373 size_t readTotal = 0;
374 while (readTotal < colorDataLength) {
375 size_t toRead =
376 (colorDataLength - readTotal) < lbuf.size() ? static_cast<size_t>(colorDataLength) - readTotal : lbuf.size();
377 if (io_->read(lbuf.data(), toRead) != toRead)
378 throw Error(ErrorCode::kerNotAnImage, "Photoshop");
379 readTotal += toRead;
380 if (outIo.write(lbuf.c_data(), toRead) != toRead)
381 throw Error(ErrorCode::kerImageWriteFailed);
382 }
383 if (outIo.error())
384 throw Error(ErrorCode::kerImageWriteFailed);

Callers

nothing calls this directly

Calls 15

ErrorFunction · 0.85
isPsdTypeFunction · 0.85
getULongFunction · 0.85
ul2DataFunction · 0.85
us2DataFunction · 0.85
isopenMethod · 0.80
eofMethod · 0.80
seekMethod · 0.80
dataMethod · 0.80
c_dataMethod · 0.80
tellMethod · 0.80
populateFakeDataMethod · 0.80

Tested by

no test coverage detected