Skip to content
Snippets Groups Projects
Commit 1d4e37c4 authored by Martin Nilsson's avatar Martin Nilsson
Browse files

Moved the EXIF parsing version of JPEG decoder to exif_decode and keep decode/_decode as before.

parent 9b0de96d
No related branches found
No related tags found
No related merge requests found
......@@ -5,12 +5,9 @@
inherit @module@;
static object exif_flip_jpeg(object img, mapping exif)
protected Image.Image exif_flip_jpeg(Image.Image img, mapping exif)
{
if (!exif)
return img;
//Stdio.stderr->write("JPEG/EXIF: Orientation %O\n", exif->Orientation);
// FIXME: Can we use jpegtransform for any of this?
switch (exif->Orientation)
{
case "1": /* default orientation */
......@@ -51,54 +48,44 @@ static object exif_flip_jpeg(object img, mapping exif)
return img;
}
object decode(string data, mapping|void options)
{
//Stdio.stderr->write("Image.JPEG overloaded decode.\r\n\n");
object img = ::decode(data, options || ([ ]) );
if (!img) // early exit if error
return img;
mapping exif = Standards.EXIF.get_properties(Stdio.FakeFile(data));
return exif_flip_jpeg(img, exif);
}
mapping _decode(string data, mapping|void options)
//! Decodes the image as @[_decode] would and then proceeds to decode
//! any EXIF information in the image. If it contain any Orientation
//! information the image will be flipped/rotated according to it. The
//! EXIF data will be returned as a mapping under the key
//! @expr{"exif"@}. If an error is encountered during the processing
//! of EXIF information, the backtrace will be returned under the key
//! @expr{"error"@}.
mapping exif_decode(string data, mapping|void options)
{
//Stdio.stderr->write("Image.JPEG overloaded _decode.\r\n\n");
mapping m = ::_decode(data, options || ([ ]) );
if (!m) // early exit if error
return m;
mapping exif = Standards.EXIF.get_properties(Stdio.FakeFile(data));
m->image = exif_flip_jpeg(m->image, exif);
if ((< "5", "6", "7", "8" >)[exif->Orientation])
{
/* If the image was flipped 90 or 270 degrees, we need to
* exchange the x/y metadata information.
*/
m->xsize = m->image->xsize;
m->ysize = m->image->ysize;
int tmp = m->x_density;
m->x_density = m->y_density;
m->y_density = tmp;
}
mapping exif = ([]);
mixed err = catch {
exif = Standards.EXIF.get_properties(Stdio.FakeFile(data)) || ([]);
m->image = exif_flip_jpeg(m->image, exif);
if ((< "5", "6", "7", "8" >)[exif->Orientation])
{
/* If the image was flipped 90 or 270 degrees, we need to
* exchange the x/y metadata information.
*/
m->xsize = m->image->xsize;
m->ysize = m->image->ysize;
int tmp = m->x_density;
m->x_density = m->y_density;
m->y_density = tmp;
}
};
if(err)
exif->error = err;
m->exif = exif;
return m;
}
mapping raw_decode(string data, mapping|void options)
{
// Compatibility function to bypass the overloading of _decode.
//Stdio.stderr->write("Image.JPEG overloaded _decode.\r\n\n");
return ::_decode(data, options || ([ ]) );
}
#else
constant this_program_does_not_exist = 1;
#endif // constant(@module@)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment