summaryrefslogtreecommitdiff
path: root/src/qcam/dng_writer.cpp
AgeCommit message (Collapse)Author
2020-08-25meson: Remove -Wno-unused-parameterLaurent Pinchart
We build libcamera with -Wno-unused-parameter and this doesn't cause much issue internally. However, it prevents catching unused parameters in inline functions defined in public headers. This can lead to compilation warnings for applications compiled without -Wno-unused-parameter. To catch those issues, remove -Wno-unused-parameter and fix all the related warnings with [[maybe_unused]]. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2020-08-05libcamera: camera: Rename name() to id()Niklas Söderlund
Rename Camera::name() to camera::id() to better describe what it represents, a unique and stable ID for the camera. While at it improve the documentation for the camera ID to describe it needs to be stable for a camera between resets of the system. Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-07-25libcamera: qcam: Improve colour information in DNG filesDavid Plowman
This patch improves the colour information recorded in DNG files using the ColourCorrectionMatrix metadata for the image. Note that we are not supplying a full calibration using two illuminants, nonetheless the single matrix here appears to be respected by a number of tools. Signed-off-by: David Plowman <david.plowman@raspberrypi.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-06-18qcam: Replace explicit DRM FourCCs with libcamera formatsLaurent Pinchart
Use the new pixel format constants to replace usage of macros from drm_fourcc.h. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2020-06-16qcam: dng_writer: Record creation time in the EXIF directoryNiklas Söderlund
If the EXIF directory is empty due to no metadata being available tools such as tiffinfo complains that the directory is malformed. TIFFFetchDirectory: Sanity check on directory count failed, this is probably not a valid IFD offset. TIFFReadCustomDirectory: Failed to read custom directory at offset 0. Always record the creation time in the EXIF directory instead of adding complexity to skip creating the EXIF directory if there is no metadata to record. This ensures there are at least some entries in the EXIF directory and that makes tiffinfo happy. Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-06-15qcam: dng_writer: Add support for IPU3 Bayer formatsNiklas Söderlund
Add support for the Bayer formats produced on the IPU3. The format uses a memory layout that is hard to repack and keep the 10-bit sample size, therefore scale the samples to 16-bit when creating the scanlines. Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-05-04qcam: dng_writer: Write EXIF IFD as custom directoryLaurent Pinchart
The EXIF IFD is incorrectly chained to IFD 0 in addition to being a referenced as a sub IFD through the EXIFIFD tag. While the libtiff API doesn't clearly document why this happens, inspection of the TIFFWriteDirectory() source code show that the function treats the IFD being written as containing an image, which isn't correct for the EXIF IFD. Use TIFFWriteCustomDirectory() instead, which fixes the problem. The resulting DNG file can now be opened with darktable in addition to rawtherapee. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2020-05-03qcam: dng_writer: Remove colon from \todoNiklas Söderlund
Todo statements should not end with a colon, remove it. Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-05-03qcam: dng_writer: Generate thumbnail in RGB formatLaurent Pinchart
While the DNG specification supports greyscale ("BlackIsZero") for thumbnails, RawTherapee seems to have trouble reading them. Generate thumbnails in RGB instead (but still with greyscale content, to avoid having to interpolate colour components). Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2020-05-03qcam: dng_writer: Populate DNG tags from metadataLaurent Pinchart
Populate the DNG black level, ISO speed rating and exposure time from metadata. The ISO speed rating and exposure time are standardized as EXIF tags, not TIFF tags, and require a separate EXIF IFD. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2020-05-03qcam: dng_writer: Output thumbnailLaurent Pinchart
Generate a greyscale, 1/16 resolution thumbnail and add it to the DNG file. This requires shuffling the RAW image generation as the thumbnail has to be stored in the main IFD as per the DNG and TIFF/EP specifications. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2020-05-03qcam: dng_writer: Name arguments to packScanline()Laurent Pinchart
Name arguments to the FormatInfo::packScanline function pointer to make it easier to understand its usage when reading the function declaration. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2020-05-03qcam: Pass request metadata to DNG writerLaurent Pinchart
The DNG writer will use the metadata to populate DNG tags. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2020-05-03qcam: dng_writer: Fix missing field nameNiklas Söderlund
While reformatting the table the field name was missed for one entry, add it. Fixes: db7235b7141aa4e2 ("qcam: Add DNGWriter") Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-05-02qcam: Add DNGWriterNiklas Söderlund
Add an initial DNG file writer. The writer can only deal with a small set of pixel formats. The generated file is consumable by standard tools. The writer needs to be extended to write more metadata to the generated file. Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
lass="hl opt">(metadata_); metadata_ = clone_camera_metadata(other.getMetadata()); valid_ = metadata_ != nullptr; return *this; } std::tuple<size_t, size_t> CameraMetadata::usage() const { size_t currentEntryCount = get_camera_metadata_entry_count(metadata_); size_t currentDataCount = get_camera_metadata_data_count(metadata_); return { currentEntryCount, currentDataCount }; } bool CameraMetadata::getEntry(uint32_t tag, camera_metadata_ro_entry_t *entry) const { if (find_camera_metadata_ro_entry(metadata_, tag, entry)) return false; return true; } /* * \brief Resize the metadata container, if necessary * \param[in] count Number of entries to add to the container * \param[in] size Total size of entries to add, in bytes * \return True if resize was successful or unnecessary, false otherwise */ bool CameraMetadata::resize(size_t count, size_t size) { if (!valid_) return false; if (!count && !size) return true; size_t currentEntryCount = get_camera_metadata_entry_count(metadata_); size_t currentEntryCapacity = get_camera_metadata_entry_capacity(metadata_); size_t newEntryCapacity = currentEntryCapacity < currentEntryCount + count ? currentEntryCapacity * 2 : currentEntryCapacity; size_t currentDataCount = get_camera_metadata_data_count(metadata_); size_t currentDataCapacity = get_camera_metadata_data_capacity(metadata_); size_t newDataCapacity = currentDataCapacity < currentDataCount + size ? currentDataCapacity * 2 : currentDataCapacity; if (newEntryCapacity > currentEntryCapacity || newDataCapacity > currentDataCapacity) { camera_metadata_t *oldMetadata = metadata_; metadata_ = allocate_camera_metadata(newEntryCapacity, newDataCapacity); if (!metadata_) { metadata_ = oldMetadata; return false; } LOG(CameraMetadata, Info) << "Resized: old entry capacity " << currentEntryCapacity << ", old data capacity " << currentDataCapacity << ", new entry capacity " << newEntryCapacity << ", new data capacity " << newDataCapacity; append_camera_metadata(metadata_, oldMetadata); free_camera_metadata(oldMetadata); resized_ = true; } return true; } template<> bool CameraMetadata::entryContains(uint32_t tag, uint8_t value) const { camera_metadata_ro_entry_t entry; if (!getEntry(tag, &entry)) return false; for (unsigned int i = 0; i < entry.count; i++) { if (entry.data.u8[i] == value) return true; } return false; } bool CameraMetadata::hasEntry(uint32_t tag) const { camera_metadata_ro_entry_t entry; return getEntry(tag, &entry); } bool CameraMetadata::addEntry(uint32_t tag, const void *data, size_t count, size_t elementSize) { if (!valid_) return false; if (!resize(1, count * elementSize)) { LOG(CameraMetadata, Error) << "Failed to resize"; valid_ = false; return false; } if (!add_camera_metadata_entry(metadata_, tag, data, count)) return true; const char *name = get_camera_metadata_tag_name(tag); if (name) LOG(CameraMetadata, Error) << "Failed to add tag " << name; else LOG(CameraMetadata, Error) << "Failed to add unknown tag " << tag; valid_ = false; return false; } bool CameraMetadata::updateEntry(uint32_t tag, const void *data, size_t count, size_t elementSize) { if (!valid_) return false; camera_metadata_entry_t entry; int ret = find_camera_metadata_entry(metadata_, tag, &entry); if (ret) { const char *name = get_camera_metadata_tag_name(tag); LOG(CameraMetadata, Error) << "Failed to update tag " << (name ? name : "<unknown>") << ": not present"; return false; } if (camera_metadata_type_size[entry.type] != elementSize) { const char *name = get_camera_metadata_tag_name(tag); LOG(CameraMetadata, Fatal) << "Invalid element size for tag " << (name ? name : "<unknown>"); return false; } size_t oldSize = calculate_camera_metadata_entry_data_size(entry.type, entry.count); size_t newSize = calculate_camera_metadata_entry_data_size(entry.type, count); size_t sizeIncrement = newSize - oldSize > 0 ? newSize - oldSize : 0; if (!resize(0, sizeIncrement)) { LOG(CameraMetadata, Error) << "Failed to resize"; valid_ = false; return false; } ret = update_camera_metadata_entry(metadata_, entry.index, data, count, nullptr); if (!ret) return true; const char *name = get_camera_metadata_tag_name(tag); LOG(CameraMetadata, Error) << "Failed to update tag " << (name ? name : "<unknown>"); valid_ = false; return false; } camera_metadata_t *CameraMetadata::getMetadata() { return valid_ ? metadata_ : nullptr; } const camera_metadata_t *CameraMetadata::getMetadata() const { return valid_ ? metadata_ : nullptr; }