Commit 7c5142f6 authored by Halla Rempt's avatar Halla Rempt
Browse files

Add classes to interpret the psd resource objects.

Begin with the image resolution object.
parent 55db9cbd
......@@ -26,6 +26,7 @@
const int MAX_CHANNELS = 56;
typedef qint32 Fixed; /* Represents a fixed point implied decimal */
/**
* Image color/depth modes
......
......@@ -18,13 +18,16 @@
#include "psd_resource_block.h"
#include <QIODevice>
#include <QBuffer>
#include <kis_debug.h>
#include "psd_utils.h"
#include "psd_resource_section.h"
PSDResourceBlock::PSDResourceBlock()
: identifier(PSDResourceSection::UNKNOWN)
, resource(0)
{
}
......@@ -76,6 +79,172 @@ bool PSDResourceBlock::read(QIODevice* io)
return false;
}
switch (identifier) {
case PSDResourceSection::MAC_PRINT_INFO:
resource = new MAC_PRINT_INFO_1001;
break;
case PSDResourceSection::RESN_INFO:
resource = new RESN_INFO_1005;
break;
case PSDResourceSection::ALPHA_NAMES:
resource = new ALPHA_NAMES_1006;
break;
case PSDResourceSection::DISPLAY_INFO:
resource = new DISPLAY_INFO_1007;
break;
case PSDResourceSection::CAPTION:
resource = new CAPTION_1008;
break;
case PSDResourceSection::BORDER_INFO:
resource = new BORDER_INFO_1009;
break;
case PSDResourceSection::BACKGROUND_COL:
resource = new BACKGROUND_COL_1010;
break;
case PSDResourceSection::PRINT_FLAGS:
resource = new PRINT_FLAGS_1011;
break;
case PSDResourceSection::GREY_HALFTONE:
resource = new GREY_HALFTONE_1012;
break;
case PSDResourceSection::COLOR_HALFTONE:
resource = new COLOR_HALFTONE_1013;
break;
case PSDResourceSection::DUOTONE_HALFTONE:
resource = new DUOTONE_HALFTONE_1014;
break;
case PSDResourceSection::GREY_XFER:
resource = new GREY_XFER_1015;
break;
case PSDResourceSection::COLOR_XFER:
resource = new COLOR_XFER_1016;
break;
case PSDResourceSection::DUOTONE_XFER:
resource = new DUOTONE_XFER_1017;
break;
case PSDResourceSection::DUOTONE_INFO:
resource = new DUOTONE_INFO_1018;
break;
case PSDResourceSection::EFFECTIVE_BW:
resource = new EFFECTIVE_BW_1019;
break;
case PSDResourceSection::EPS_OPT:
resource = new EPS_OPT_1021;
break;
case PSDResourceSection::QUICK_MASK:
resource = new QUICK_MASK_1022;
break;
case PSDResourceSection::LAYER_STATE:
resource = new LAYER_STATE_1024;
break;
case PSDResourceSection::WORKING_PATH:
resource = new WORKING_PATH_1025;
break;
case PSDResourceSection::LAYER_GROUP:
resource = new LAYER_GROUP_1026;
break;
case PSDResourceSection::IPTC_NAA_DATA:
resource = new IPTC_NAA_DATA_1028;
break;
case PSDResourceSection::IMAGE_MODE_RAW:
resource = new IMAGE_MODE_RAW_1029;
break;
case PSDResourceSection::JPEG_QUAL:
resource = new JPEG_QUAL_1030;
break;
case PSDResourceSection::GRID_GUIDE:
resource = new GRID_GUIDE_1032;
break;
case PSDResourceSection::THUMB_RES:
resource = new THUMB_RES_1033;
break;
case PSDResourceSection::COPYRIGHT_FLG:
resource = new COPYRIGHT_FLG_1034;
break;
case PSDResourceSection::URL:
resource = new URL_1035;
break;
case PSDResourceSection::THUMB_RES2:
resource = new THUMB_RES2_1036;
break;
case PSDResourceSection::GLOBAL_ANGLE:
resource = new GLOBAL_ANGLE_1037;
break;
case PSDResourceSection::COLOR_SAMPLER:
resource = new COLOR_SAMPLER_1038;
break;
case PSDResourceSection::ICC_PROFILE:
resource = new ICC_PROFILE_1039;
break;
case PSDResourceSection::WATERMARK:
resource = new WATERMARK_1040;
break;
case PSDResourceSection::ICC_UNTAGGED:
resource = new ICC_UNTAGGED_1041;
break;
case PSDResourceSection::EFFECTS_VISIBLE:
resource = new EFFECTS_VISIBLE_1042;
break;
case PSDResourceSection::SPOT_HALFTONE:
resource = new SPOT_HALFTONE_1043;
break;
case PSDResourceSection::DOC_IDS:
resource = new DOC_IDS_1044;
break;
case PSDResourceSection::ALPHA_NAMES_UNI:
resource = new ALPHA_NAMES_UNI_1045;
break;
case PSDResourceSection::IDX_COL_TAB_CNT:
resource = new IDX_COL_TAB_CNT_1046;
break;
case PSDResourceSection::IDX_TRANSPARENT:
resource = new IDX_TRANSPARENT_1047;
break;
case PSDResourceSection::GLOBAL_ALT:
resource = new GLOBAL_ALT_1049;
break;
case PSDResourceSection::SLICES:
resource = new SLICES_1050;
break;
case PSDResourceSection::WORKFLOW_URL_UNI:
resource = new WORKFLOW_URL_UNI_1051;
break;
case PSDResourceSection::JUMP_TO_XPEP:
resource = new JUMP_TO_XPEP_1052;
break;
case PSDResourceSection::ALPHA_ID:
resource = new ALPHA_ID_1053;
break;
case PSDResourceSection::URL_LIST_UNI:
resource = new URL_LIST_UNI_1054;
break;
case PSDResourceSection::VERSION_INFO:
resource = new VERSION_INFO_1057;
break;
case PSDResourceSection::EXIF_DATA:
resource = new EXIF_DATA_1058;
break;
case PSDResourceSection::XMP_DATA:
resource = new XMP_DATA_1060;
break;
case PSDResourceSection::PATH_INFO_FIRST:
resource = new PATH_INFO_FIRST_2000;
break;
case PSDResourceSection::PATH_INFO_LAST:
resource = new PATH_INFO_LAST_2998;
break;
case PSDResourceSection::CLIPPING_PATH:
resource = new CLIPPING_PATH_2999;
break;
case PSDResourceSection::PRINT_FLAGS_2:
resource = new PRINT_FLAGS_2_10000;
break;
default:
;
}
resource->interpretBlock(data);
return valid();
}
......@@ -104,3 +273,22 @@ bool PSDResourceBlock::valid()
return true;
}
bool RESN_INFO_1005::interpretBlock(QByteArray data)
{
// the resolution we set on the image should be dpi; we can also set the unit on the KoDocument.
QBuffer buf(&data);
bool retval = (psdread(&buf, &hRes)
&& psdread(&buf, &hResUnit)
&& psdread(&buf, &widthUnit)
&& psdread(&buf, &vRes)
&& psdread(&buf, &vRes)
&& psdread(&buf, &vResUnit)
&& psdread(&buf, &heightUnit));
return retval;
}
bool RESN_INFO_1005::valid()
{
return true;
}
......@@ -21,9 +21,21 @@
class QIODevice;
#include <QString>
#include "kis_annotation.h"
#include "psd.h"
#include "psd_resource_section.h"
/**
* @brief The PSDResourceInterpreter class interprets the data in a psd resource block
*/
class PSDInterpretedResource
{
public:
virtual ~PSDInterpretedResource() {};
virtual bool interpretBlock(QByteArray /*data*/) { return true; }
virtual bool valid() { return true; }
};
/**
* Contains the unparsed contents of the image resource blocks
......@@ -36,6 +48,10 @@ class PSDResourceBlock //: public KisAnnotation
public:
PSDResourceBlock();
~PSDResourceBlock()
{
delete resource;
}
bool read(QIODevice* io);
bool write(QIODevice* io);
......@@ -46,7 +62,387 @@ public:
quint32 dataSize;
QByteArray data;
PSDInterpretedResource *resource;
QString error;
};
#endif // PSD_RESOURCE_BLOCK_H
/* 0x03e9 - Optional - Mac print manager print info record */
class MAC_PRINT_INFO_1001 : public PSDInterpretedResource
{
};
/* 0x03ed - ResolutionInfo structure */
class RESN_INFO_1005 : public PSDInterpretedResource
{
virtual bool interpretBlock(QByteArray data);
bool valid();
Fixed hRes;
quint16 hResUnit;
quint16 widthUnit;
Fixed vRes;
quint16 vResUnit;
quint16 heightUnit;
};
/* 0x03ee - Alpha channel names */
class ALPHA_NAMES_1006 : public PSDInterpretedResource
{
};
/* 0x03ef - DisplayInfo structure */
class DISPLAY_INFO_1007 : public PSDInterpretedResource
{
};
/* 0x03f0 - Optional - Caption string */
class CAPTION_1008 : public PSDInterpretedResource
{
};
/* 0x03f1 - Border info */
class BORDER_INFO_1009 : public PSDInterpretedResource
{
};
/* 0x03f2 - Background colour */
class BACKGROUND_COL_1010 : public PSDInterpretedResource
{
};
/* 0x03f3 - Print flags */
class PRINT_FLAGS_1011 : public PSDInterpretedResource
{
};
/* 0x03f4 - Greyscale and multichannel halftoning info */
class GREY_HALFTONE_1012 : public PSDInterpretedResource
{
};
/* 0x03f5 - Colour halftoning info */
class COLOR_HALFTONE_1013 : public PSDInterpretedResource
{
};
/* 0x03f6 - Duotone halftoning info */
class DUOTONE_HALFTONE_1014 : public PSDInterpretedResource
{
};
/* 0x03f7 - Greyscale and multichannel transfer functions */
class GREY_XFER_1015 : public PSDInterpretedResource
{
};
/* 0x03f8 - Colour transfer functions */
class COLOR_XFER_1016 : public PSDInterpretedResource
{
};
/* 0x03f9 - Duotone transfer functions */
class DUOTONE_XFER_1017 : public PSDInterpretedResource
{
};
/* 0x03fa - Duotone image information */
class DUOTONE_INFO_1018 : public PSDInterpretedResource
{
};
/* 0x03fb - Effective black & white values for dot range */
class EFFECTIVE_BW_1019 : public PSDInterpretedResource
{
};
/* 0x03fd - EPS options */
class EPS_OPT_1021 : public PSDInterpretedResource
{
};
/* 0x03fe - Quick mask info */
class QUICK_MASK_1022 : public PSDInterpretedResource
{
};
/* 0x0400 - Layer state info */
class LAYER_STATE_1024 : public PSDInterpretedResource
{
};
/* 0x0401 - Working path (not saved) */
class WORKING_PATH_1025 : public PSDInterpretedResource
{
};
/* 0x0402 - Layers group info */
class LAYER_GROUP_1026 : public PSDInterpretedResource
{
};
/* 0x0404 - IPTC-NAA record (IMV4.pdf) */
class IPTC_NAA_DATA_1028 : public PSDInterpretedResource
{
};
/* 0x0405 - Image mode for raw format files */
class IMAGE_MODE_RAW_1029 : public PSDInterpretedResource
{
};
/* 0x0406 - JPEG quality */
class JPEG_QUAL_1030 : public PSDInterpretedResource
{
};
/* 0x0408 - Grid & guide info */
class GRID_GUIDE_1032 : public PSDInterpretedResource
{
};
/* 0x0409 - Thumbnail resource */
class THUMB_RES_1033 : public PSDInterpretedResource
{
};
/* 0x040a - Copyright flag */
class COPYRIGHT_FLG_1034 : public PSDInterpretedResource
{
};
/* 0x040b - URL string */
class URL_1035 : public PSDInterpretedResource
{
};
/* 0x040c - Thumbnail resource */
class THUMB_RES2_1036 : public PSDInterpretedResource
{
};
/* 0x040d - Global angle */
class GLOBAL_ANGLE_1037 : public PSDInterpretedResource
{
};
/* 0x040e - Colour samplers resource */
class COLOR_SAMPLER_1038 : public PSDInterpretedResource
{
};
/* 0x040f - ICC Profile */
class ICC_PROFILE_1039 : public PSDInterpretedResource
{
};
/* 0x0410 - Watermark */
class WATERMARK_1040 : public PSDInterpretedResource
{
};
/* 0x0411 - Do not use ICC profile flag */
class ICC_UNTAGGED_1041 : public PSDInterpretedResource
{
};
/* 0x0412 - Show / hide all effects layers */
class EFFECTS_VISIBLE_1042 : public PSDInterpretedResource
{
};
/* 0x0413 - Spot halftone */
class SPOT_HALFTONE_1043 : public PSDInterpretedResource
{
};
/* 0x0414 - Document specific IDs */
class DOC_IDS_1044 : public PSDInterpretedResource
{
};
/* 0x0415 - Unicode alpha names */
class ALPHA_NAMES_UNI_1045 : public PSDInterpretedResource
{
};
/* 0x0416 - Indexed colour table count */
class IDX_COL_TAB_CNT_1046 : public PSDInterpretedResource
{
};
/* 0x0417 - Index of transparent colour (if any) */
class IDX_TRANSPARENT_1047 : public PSDInterpretedResource
{
};
/* 0x0419 - Global altitude */
class GLOBAL_ALT_1049 : public PSDInterpretedResource
{
};
/* 0x041a - Slices */
class SLICES_1050 : public PSDInterpretedResource
{
};
/* 0x041b - Workflow URL - Unicode string */
class WORKFLOW_URL_UNI_1051 : public PSDInterpretedResource
{
};
/* 0x041c - Jump to XPEP (?) */
class JUMP_TO_XPEP_1052 : public PSDInterpretedResource
{
};
/* 0x041d - Alpha IDs */
class ALPHA_ID_1053 : public PSDInterpretedResource
{
};
/* 0x041e - URL list - unicode */
class URL_LIST_UNI_1054 : public PSDInterpretedResource
{
};
/* 0x0421 - Version info */
class VERSION_INFO_1057 : public PSDInterpretedResource
{
};
/* 0x0422 - Exif data block */
class EXIF_DATA_1058 : public PSDInterpretedResource
{
};
/* 0x0424 - XMP data block */
class XMP_DATA_1060 : public PSDInterpretedResource
{
};
/* 0x07d0 - First path info block */
class PATH_INFO_FIRST_2000 : public PSDInterpretedResource