mirror of
https://gitlab.gnome.org/GNOME/gimp.git
synced 2025-07-04 09:53:25 +00:00
plug-ins: Fix regression on importing RGB FITS
The developers of SiriL sent me some RGB FITS images that rendered incorrectly
after d4f42076
. These must be read in as
planes rather than individual rows.
This commit is contained in:
parent
84fb879973
commit
03ea666fc8
1 changed files with 50 additions and 27 deletions
|
@ -502,8 +502,12 @@ load_image (GFile *file,
|
||||||
NULL);
|
NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If RGB FITS image, we need to increase the size by the number of channels */
|
/* If RGB FITS image, we need to read in the whole image so we can convert
|
||||||
pixels = (gdouble *) malloc (width * sizeof (gdouble) * channels);
|
* the planes format to RGB */
|
||||||
|
if (hdu.naxis == 2)
|
||||||
|
pixels = (gdouble *) malloc (width * sizeof (gdouble) * channels);
|
||||||
|
else
|
||||||
|
pixels = (gdouble *) malloc (width * height * sizeof (gdouble) * channels);
|
||||||
|
|
||||||
if (! image)
|
if (! image)
|
||||||
{
|
{
|
||||||
|
@ -543,41 +547,60 @@ load_image (GFile *file,
|
||||||
show_fits_errors (status);
|
show_fits_errors (status);
|
||||||
|
|
||||||
/* Read pixel values in */
|
/* Read pixel values in */
|
||||||
for (fpixel[1] = height; fpixel[1] >= 1; fpixel[1]--)
|
if (hdu.naxis == 2)
|
||||||
{
|
{
|
||||||
gdouble *temp =
|
for (fpixel[1] = height; fpixel[1] >= 1; fpixel[1]--)
|
||||||
(gdouble *) malloc (width * sizeof (gdouble) * channels);
|
|
||||||
|
|
||||||
if (fits_read_pix (ifp, TDOUBLE, fpixel, row_length, &replace_val,
|
|
||||||
pixels, NULL, &status))
|
|
||||||
break;
|
|
||||||
|
|
||||||
if (datamin < datamax)
|
|
||||||
{
|
{
|
||||||
for (gint ii = 0; ii < row_length; ii++)
|
if (fits_read_pix (ifp, TDOUBLE, fpixel, row_length, &replace_val,
|
||||||
pixels[ii] = (pixels[ii] - datamin) / (datamax - datamin);
|
pixels, NULL, &status))
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (datamin < datamax)
|
||||||
|
{
|
||||||
|
for (gint ii = 0; ii < row_length; ii++)
|
||||||
|
pixels[ii] = (pixels[ii] - datamin) / (datamax - datamin);
|
||||||
|
}
|
||||||
|
|
||||||
|
gegl_buffer_set (buffer,
|
||||||
|
GEGL_RECTANGLE (0, height - fpixel[1],
|
||||||
|
width, 1), 0,
|
||||||
|
format, pixels, GEGL_AUTO_ROWSTRIDE);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else if (hdu.naxisn[2] && hdu.naxisn[2] == 3)
|
||||||
|
{
|
||||||
|
gint total_size = width * height * channels;
|
||||||
|
|
||||||
if (hdu.naxisn[2] && hdu.naxisn[2] == 3) /* Packed RGB format */
|
fits_read_img (ifp, TDOUBLE, 1, total_size, &replace_val,
|
||||||
|
pixels, NULL, &status);
|
||||||
|
|
||||||
|
if (! status)
|
||||||
{
|
{
|
||||||
/* Cover planes to RGB format */
|
gdouble *temp;
|
||||||
for (gint ii = 0; ii < (row_length / 3); ii++)
|
|
||||||
|
temp = (gdouble *) malloc (width * height * sizeof (gdouble) * channels);
|
||||||
|
|
||||||
|
if (datamin < datamax)
|
||||||
|
{
|
||||||
|
for (gint ii = 0; ii < total_size; ii++)
|
||||||
|
pixels[ii] = (pixels[ii] - datamin) / (datamax - datamin);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (gint ii = 0; ii < (total_size / 3); ii++)
|
||||||
{
|
{
|
||||||
temp[(ii * 3)] = pixels[ii];
|
temp[(ii * 3)] = pixels[ii];
|
||||||
temp[(ii * 3) + 1] = pixels[ii + (row_length / 3)];
|
temp[(ii * 3) + 1] = pixels[ii + (total_size / 3)];
|
||||||
temp[(ii * 3) + 2] = pixels[ii + ((row_length / 3) * 2)];
|
temp[(ii * 3) + 2] = pixels[ii + ((total_size / 3) * 2)];
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
temp = pixels;
|
|
||||||
}
|
|
||||||
|
|
||||||
gegl_buffer_set (buffer,
|
gegl_buffer_set (buffer, GEGL_RECTANGLE (0, 0, width, height), 0,
|
||||||
GEGL_RECTANGLE (0, height - fpixel[1],
|
format, temp, GEGL_AUTO_ROWSTRIDE);
|
||||||
width, 1), 0,
|
|
||||||
format, temp, GEGL_AUTO_ROWSTRIDE);
|
if (temp)
|
||||||
|
g_free (temp);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (status)
|
if (status)
|
||||||
show_fits_errors (status);
|
show_fits_errors (status);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue