Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
123 changes: 88 additions & 35 deletions src/Database/ImgIndex.php
Original file line number Diff line number Diff line change
Expand Up @@ -977,54 +977,107 @@ public function getDataMidPoint($start, $end, $mid, $sourceId) {
}

/**
* Extract metadata from JP2 image file's XML header
* Extract metadata from JP2 image file's XML header.
*
* @param string $image_filepath Full path to JP2 image file
*
* @return array A subset of the information stored in the jp2 header
* @return array A subset of the information stored in the JP2 header
*/
public function extractJP2MetaInfo($image_filepath) {

include_once HV_ROOT_DIR.'/../src/Image/JPEG2000/JP2ImageXMLBox.php';
include_once HV_ROOT_DIR
. '/../src/Image/JPEG2000/JP2ImageXMLBox.php';

try {
$xmlBox = new Image_JPEG2000_JP2ImageXMLBox($image_filepath);

$dimensions = $xmlBox->getImageDimensions();
$refPixel = $xmlBox->getRefPixelCoords();
$imageScale = (float) $xmlBox->getImagePlateScale();
$dsun = (float) $xmlBox->getDSun();
$rsun = (float) $xmlBox->getRSun();
$sunCenterOffsetParams = $xmlBox->getSunCenterOffsetParams();
$layeringOrder = $xmlBox->getLayeringOrder();
$rotation = $xmlBox->getRotation();
$offsets = $xmlBox->getCRValOffsets();
$xmlBox = new Image_JPEG2000_JP2ImageXMLBox(
$image_filepath
);

// Normalize image scale
$normalizedScale = $imageScale * ($dsun / HV_CONSTANT_AU);
$dimensions = $xmlBox->getImageDimensions();
$refPixel = $xmlBox->getRefPixelCoords();
$imageScale = (float) $xmlBox->getImagePlateScale();
$wcs = $xmlBox->getWCSMetadata();

$dsun = (float) $xmlBox->getDSun();
$rsun = (float) $xmlBox->getRSun();

$sunCenterOffsetParams =
$xmlBox->getSunCenterOffsetParams();

$layeringOrder = $xmlBox->getLayeringOrder();
$rotation = $xmlBox->getRotation();
$offsets = $xmlBox->getCRValOffsets();

/*
* Normalize angular scales to one astronomical unit.
*
* The legacy scalar scale is retained. New WCS-aware clients
* additionally receive independent X/Y scales and the PC/CD
* matrices.
*/
$distanceCorrection = $dsun / HV_CONSTANT_AU;

$normalizedScale =
$imageScale * $distanceCorrection;

$normalizedWcs = $wcs;

$normalizedWcs['scaleX'] =
$wcs['scaleX'] * $distanceCorrection;

$normalizedWcs['scaleY'] =
$wcs['scaleY'] * $distanceCorrection;

$normalizedWcs['cd'] = array(
array(
$wcs['cd'][0][0] * $distanceCorrection,
$wcs['cd'][0][1] * $distanceCorrection
),
array(
$wcs['cd'][1][0] * $distanceCorrection,
$wcs['cd'][1][1] * $distanceCorrection
)
);

$meta = array(
"scale" => $normalizedScale,
"scaleCorrection" => $imageScale / $normalizedScale,
"width" => (int) $dimensions[0],
"height" => (int) $dimensions[1],
"refPixelX" => (float) $refPixel[0],
"refPixelY" => (float) $refPixel[1],
"offsetX" => (float) $offsets[0],
"offsetY" => (float) $offsets[1],
"rotation" => $rotation,
"rsun" => (float) $rsun,
"dsun" => $dsun,
"sunCenterOffsetParams" => $sunCenterOffsetParams,
"layeringOrder" => $layeringOrder
'scale' => $normalizedScale,

'scaleCorrection' =>
$imageScale / $normalizedScale,

'width' => (int) $dimensions[0],
'height' => (int) $dimensions[1],

'refPixelX' => (float) $refPixel[0],
'refPixelY' => (float) $refPixel[1],

'offsetX' => (float) $offsets[0],
'offsetY' => (float) $offsets[1],

'rotation' => $rotation,

/*
* Additional backward-compatible WCS object.
*/
'wcs' => $normalizedWcs,

'rsun' => $rsun,
'dsun' => $dsun,

'sunCenterOffsetParams' =>
$sunCenterOffsetParams,

'layeringOrder' => $layeringOrder
);
}
catch (Exception $e) {
} catch (Exception $e) {
throw new Exception(
sprintf("Unable to process XML Header for %s: %s",
$image_filepath,
$e->getMessage()
), 13);
sprintf(
'Unable to process XML Header for %s: %s',
$image_filepath,
$e->getMessage()
),
13
);
}

return $meta;
Expand Down
22 changes: 22 additions & 0 deletions src/Image/ImageType/SPICEImage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
/**
* Image_ImageType_SPICEImage class definition
*
* @category Image
* @package Helioviewer
* @author Salim Hachemaoui
* @license http://www.mozilla.org/MPL/MPL-1.1.html Mozilla Public License 1.1
* @link https://github.com/Helioviewer-Project
*/

require_once HV_ROOT_DIR.'/../src/Image/HelioviewerImage.php';

/**
* Handles Solar Orbiter SPICE images.
*
* SPICE images are rendered in grayscale without applying a color table.
*/
class Image_ImageType_SPICEImage extends Image_HelioviewerImage
{
}
?>
Loading
Loading