File indexing completed on 2024-05-12 15:59:38
0001 /* 0002 * SPDX-FileCopyrightText: 2014 Boudewijn Rempt <boud@valdyas.org> 0003 * SPDX-FileCopyrightText: 2021 L. E. Segovia <amy@amyspark.me> 0004 * 0005 * SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 #ifndef PSD_ADDITIONAL_LAYER_INFO_BLOCK_H 0008 #define PSD_ADDITIONAL_LAYER_INFO_BLOCK_H 0009 0010 #include "kritapsd_export.h" 0011 0012 #include <QBitArray> 0013 #include <QByteArray> 0014 #include <QDomDocument> 0015 #include <QIODevice> 0016 #include <QString> 0017 #include <QVector> 0018 #include <functional> 0019 0020 #include <kis_types.h> 0021 #include <kis_global.h> 0022 0023 #include <kis_node.h> 0024 #include <kis_paint_device.h> 0025 #include <kis_generator_registry.h> 0026 #include <KisGlobalResourcesInterface.h> 0027 #include <KoStopGradient.h> 0028 #include <KoSegmentGradient.h> 0029 #include <psd.h> 0030 0031 #include <asl/kis_asl_xml_writer.h> 0032 0033 #include "psd_header.h" 0034 0035 // additional layer information 0036 0037 // LEVELS 0038 // Level record 0039 struct KRITAPSD_EXPORT psd_layer_level_record { 0040 quint16 input_floor {0}; // (0...253) 0041 quint16 input_ceiling {2}; // (2...255) 0042 quint16 output_floor {0}; // 255). Matched to input floor. 0043 quint16 output_ceiling {0}; // (0...255) 0044 float gamma {0.0}; // Short integer from 10...999 representing 0.1...9.99. Applied to all image data. 0045 }; 0046 0047 // Levels settings files are loaded and saved in the Levels dialog. 0048 struct KRITAPSD_EXPORT psd_layer_levels { 0049 psd_layer_level_record record[29]; // 29 sets of level records, each level containing 5 qint8 integers 0050 // Photoshop CS (8.0) Additional information 0051 // At the end of the Version 2 file is the following information: 0052 quint16 extra_level_count {0}; // Count of total level record structures. Subtract the legacy number of level record structures, 29, to determine how many are 0053 // remaining in the file for reading. 0054 psd_layer_level_record *extra_record {nullptr}; // Additianol level records according to count 0055 quint8 lookup_table[3][256]; 0056 }; 0057 0058 // CURVES 0059 // The following is the data for each curve specified by count above 0060 struct KRITAPSD_EXPORT psd_layer_curves_data { 0061 quint16 channel_index {0}; // Before each curve is a channel index. 0062 quint16 point_count {0}; // Count of points in the curve (qint8 integer from 2...19) 0063 quint16 output_value[19]; // All coordinates have range 0 to 255 0064 quint16 input_value[19]; 0065 }; 0066 0067 // Curves file format 0068 struct KRITAPSD_EXPORT psd_layer_curves { 0069 quint16 curve_count {0}; // Count of curves in the file. 0070 psd_layer_curves_data *curve {nullptr}; 0071 quint8 lookup_table[3][256]; 0072 }; 0073 0074 // BRIGHTNESS AND CONTRAST 0075 struct KRITAPSD_EXPORT psd_layer_brightness_contrast { 0076 qint8 brightness {0}; 0077 qint8 contrast {0}; 0078 qint8 mean_value {0}; // for brightness and contrast 0079 qint8 Lab_color {0}; 0080 quint8 lookup_table[256]; 0081 }; 0082 0083 // COLOR BALANCE 0084 struct KRITAPSD_EXPORT psd_layer_color_balance { 0085 qint8 cyan_red[3]; // (-100...100). shadows, midtones, highlights 0086 qint8 magenta_green[3]; 0087 qint8 yellow_blue[3]; 0088 bool preserve_luminosity {false}; 0089 quint8 lookup_table[3][256]; 0090 }; 0091 0092 // HUE/SATURATION 0093 // Hue/Saturation settings files are loaded and saved in Photoshop¡¯s Hue/Saturation dialog 0094 struct KRITAPSD_EXPORT psd_layer_hue_saturation { 0095 quint8 hue_or_colorization {0}; // 0 = Use settings for hue-adjustment; 1 = Use settings for colorization. 0096 qint8 colorization_hue {0}; // Photoshop 5.0: The actual values are stored for the new version. Hue is - 180...180, Saturation is 0...100, and Lightness is 0097 // -100...100. 0098 qint8 colorization_saturation {0}; // Photoshop 4.0: Three qint8 integers Hue, Saturation, and Lightness from ¨C100...100. 0099 qint8 colorization_lightness {0}; // The user interface represents hue as ¨C180...180, saturation as 0...100, and Lightness as -100...1000, as the traditional 0100 // HSB color wheel, with red = 0. 0101 qint8 master_hue {0}; // Master hue, saturation and lightness values. 0102 qint8 master_saturation {0}; 0103 qint8 master_lightness {0}; 0104 qint8 range_values[6][4]; // For RGB and CMYK, those values apply to each of the six hextants in the HSB color wheel: those image pixels nearest to red, 0105 // yellow, green, cyan, blue, or magenta. These numbers appear in the user interface from ¨C60...60, however the slider will 0106 // reflect each of the possible 201 values from ¨C100...100. 0107 qint8 setting_values[6][3]; // For Lab, the first four of the six values are applied to image pixels in the four Lab color quadrants, yellow, green, blue, 0108 // and magenta. The other two values are ignored ( = 0). The values appear in the user interface from ¨C90 to 90. 0109 quint8 lookup_table[6][360]; 0110 }; 0111 0112 // SELECTIVE COLOR 0113 // Selective Color settings files are loaded and saved in Photoshop¡¯s Selective Color dialog. 0114 struct KRITAPSD_EXPORT psd_layer_selective_color { 0115 quint16 correction_method {0}; // 0 = Apply color correction in relative mode; 1 = Apply color correction in absolute mode. 0116 qint8 cyan_correction[10]; // Amount of cyan correction. Short integer from ¨C100...100. 0117 qint8 magenta_correction[10]; // Amount of magenta correction. Short integer from ¨C100...100. 0118 qint8 yellow_correction[10]; // Amount of yellow correction. Short integer from ¨C100...100. 0119 qint8 black_correction[10]; // Amount of black correction. Short integer from ¨C100...100. 0120 }; 0121 0122 // THRESHOLD 0123 struct KRITAPSD_EXPORT psd_layer_threshold { 0124 quint16 level {1}; // (1...255) 0125 }; 0126 0127 // INVERT 0128 // no parameter 0129 0130 // POSTERIZE 0131 struct KRITAPSD_EXPORT psd_layer_posterize { 0132 quint16 levels {2}; // (2...255) 0133 quint8 lookup_table[256]; 0134 }; 0135 0136 // CHANNEL MIXER 0137 struct KRITAPSD_EXPORT psd_layer_channel_mixer { 0138 bool monochrome {false}; 0139 qint8 red_cyan[4]; // RGB or CMYK color plus constant for the mixer settings. 4 * 2 bytes of color with 2 bytes of constant. 0140 qint8 green_magenta[4]; // (-200...200) 0141 qint8 blue_yellow[4]; 0142 qint8 black[4]; 0143 qint8 constant[4]; 0144 }; 0145 0146 // PHOTO FILTER 0147 struct KRITAPSD_EXPORT psd_layer_photo_filter { 0148 qint32 x_color {0}; // 4 bytes each for XYZ color 0149 qint32 y_color {0}; 0150 qint32 z_color {0}; 0151 qint32 density {0}; // (1...100) 0152 bool preserve_luminosity {true}; 0153 }; 0154 0155 #include <kis_psd_layer_style.h> 0156 0157 struct KRITAPSD_EXPORT psd_layer_solid_color { 0158 KoColor fill_color; 0159 const KoColorSpace *cs {nullptr}; 0160 0161 // Used by ASL callback; 0162 void setColor(const KoColor &color) { 0163 fill_color = color; 0164 if (fill_color.colorSpace()->colorModelId() == cs->colorModelId()) { 0165 fill_color.setProfile(cs->profile()); 0166 } 0167 } 0168 QDomDocument getFillLayerConfig() { 0169 KisFilterConfigurationSP cfg; 0170 cfg = KisGeneratorRegistry::instance()->value("color")->defaultConfiguration(KisGlobalResourcesInterface::instance()); 0171 QVariant v; 0172 v.setValue(fill_color); 0173 cfg->setProperty("color", v); 0174 QDomDocument doc; 0175 doc.setContent(cfg->toXML()); 0176 return doc; 0177 } 0178 0179 bool loadFromConfig(KisFilterConfigurationSP cfg) { 0180 if (cfg->name() != "color") { 0181 return false; 0182 } 0183 fill_color = cfg->getColor("color"); 0184 return true; 0185 } 0186 0187 QDomDocument getASLXML() { 0188 KisAslXmlWriter w; 0189 w.enterDescriptor("", "", "null"); 0190 if (cs) { 0191 w.writeColor("Clr ", fill_color.convertedTo(cs)); 0192 } else { 0193 w.writeColor("Clr ", fill_color); 0194 } 0195 0196 w.leaveDescriptor(); 0197 0198 return w.document(); 0199 } 0200 }; 0201 0202 struct KRITAPSD_EXPORT psd_layer_gradient_fill { 0203 double angle {0.0}; 0204 QString style {QString("linear")}; 0205 QString repeat {QString("none")}; 0206 double scale {100.0}; 0207 bool reverse {false}; // Is gradient reverse 0208 bool dithered {false}; // Is gradient dithered 0209 bool align_with_layer {false}; 0210 QPointF offset; 0211 QDomDocument gradient; 0212 int imageWidth {1}; // Set when loading. 0213 int imageHeight {1}; 0214 0215 // Used by ASL callback; 0216 void setGradient(const KoAbstractGradientSP &newGradient) { 0217 QDomDocument document; 0218 QDomElement gradientElement = document.createElement("gradient"); 0219 gradientElement.setAttribute("name", newGradient->name()); 0220 0221 if (dynamic_cast<KoStopGradient*>(newGradient.data())) { 0222 KoStopGradient *gradient = dynamic_cast<KoStopGradient*>(newGradient.data()); 0223 gradient->toXML(document, gradientElement); 0224 } else if (dynamic_cast<KoSegmentGradient*>(newGradient.data())) { 0225 KoSegmentGradient *gradient = dynamic_cast<KoSegmentGradient*>(newGradient.data()); 0226 gradient->toXML(document, gradientElement); 0227 } 0228 0229 document.appendChild(gradientElement); 0230 gradient = document; 0231 } 0232 0233 void setDither(bool Dthr) { 0234 dithered = Dthr; 0235 } 0236 0237 void setReverse(bool Rvrs) { 0238 reverse = Rvrs; 0239 } 0240 0241 void setAngle(float Angl) { 0242 angle = Angl; 0243 } 0244 0245 void setType(const QString type) { 0246 repeat = "none"; 0247 if (type == "Lnr "){ 0248 style = "linear"; 0249 } else if (type == "Rdl "){ 0250 style = "radial"; 0251 } else if (type == "Angl"){ 0252 style = "conical"; 0253 } else if (type == "Rflc"){ 0254 style = "bilinear"; 0255 repeat ="alternate"; 0256 } else { 0257 style = "square"; // diamond??? 0258 } 0259 } 0260 0261 void setAlignWithLayer(bool align) { 0262 align_with_layer = align; 0263 } 0264 0265 void setScale(float Scl) { 0266 scale = Scl; 0267 } 0268 0269 void setOffset(QPointF Ofst) { 0270 offset = Ofst; 0271 } 0272 0273 QDomDocument getFillLayerConfig() { 0274 KisFilterConfigurationSP cfg; 0275 cfg = KisGeneratorRegistry::instance()->value("gradient")->defaultConfiguration(KisGlobalResourcesInterface::instance()); 0276 cfg->setProperty("gradient", gradient.toString()); 0277 cfg->setProperty("dither", dithered); 0278 cfg->setProperty("reverse", reverse); 0279 0280 cfg->setProperty("shape", style); 0281 cfg->setProperty("repeat", repeat); 0282 0283 cfg->setProperty("end_position_coordinate_system", "polar"); 0284 0285 cfg->setProperty("end_position_distance_units", "percent_of_width"); 0286 cfg->setProperty("start_position_x_units", "percent_of_width"); 0287 cfg->setProperty("start_position_y_units", "percent_of_height"); 0288 0289 // angle seems to go from -180 to +180; 0290 double fixedAngle = fmod(360.0 + angle, 360.0); 0291 0292 double scaleModifier = 1.0; 0293 0294 if (style == "square") { 0295 fixedAngle = fmod((45.0 + fixedAngle), 360.0); 0296 0297 scaleModifier = cos(kisDegreesToRadians(45.0)); 0298 double halfAngle = fmod(fabs(fixedAngle), 180.0); 0299 scaleModifier *= 1/cos(kisDegreesToRadians(45.0 - fmod(halfAngle, 45.0) )); 0300 if (halfAngle >= 45.0 && halfAngle < 135.0) { 0301 scaleModifier = (scaleModifier) * (imageHeight / imageWidth); 0302 } 0303 0304 } else { 0305 double halfAngle = fmod(fabs(fixedAngle), 180.0); 0306 scaleModifier *= 1/cos(kisDegreesToRadians(halfAngle)); 0307 if (halfAngle >= 45.0 && halfAngle < 135.0) { 0308 scaleModifier = (scaleModifier) * (imageHeight / imageWidth); 0309 } 0310 0311 } 0312 0313 cfg->setProperty("end_position_angle", fixedAngle); 0314 0315 if (style == "linear") { 0316 // linear has the problem that in Krita it rotates around the top-left, 0317 // while in psd it rotates around the middle. 0318 QPointF center(imageWidth*0.5, imageHeight*0.5); 0319 0320 QTransform rotate; 0321 rotate.rotate(fixedAngle); 0322 QTransform tf = QTransform::fromTranslate(-center.x(), -center.y()) 0323 * rotate * QTransform::fromTranslate(center.x(), center.y()); 0324 QPointF topleft = tf.inverted().map(QPointF(0.0, 0.0)); 0325 double xPercentage = (topleft.x()/double(imageWidth)) * 100.0; 0326 double yPercentage = (topleft.y()/double(imageHeight)) * 100.0; 0327 0328 cfg->setProperty("end_position_distance", scale * scaleModifier); 0329 cfg->setProperty("start_position_x", xPercentage + offset.x()); 0330 cfg->setProperty("start_position_y", yPercentage + offset.y()); 0331 } else { 0332 cfg->setProperty("end_position_distance", scale * 0.5 * fabs(scaleModifier)); 0333 cfg->setProperty("start_position_x", (50.0)+offset.x()); 0334 cfg->setProperty("start_position_y", (50.0)+offset.y()); 0335 } 0336 0337 QDomDocument doc; 0338 doc.setContent(cfg->toXML()); 0339 return doc; 0340 } 0341 0342 bool loadFromConfig(KisFilterConfigurationSP cfg) { 0343 if (cfg->name() != "gradient") { 0344 return false; 0345 } 0346 0347 bool res = false; 0348 0349 res = gradient.setContent(cfg->getString("gradient", "")); 0350 0351 dithered = cfg->getBool("dither"); 0352 reverse = cfg->getBool("reverse"); 0353 align_with_layer = false; // not supported. 0354 0355 style = cfg->getString("shape", "linear"); 0356 repeat = cfg->getString("repeat", "none"); 0357 0358 bool polar = (cfg->getString("end_position_coordinate_system") == "polar"); 0359 0360 QPointF start(cfg->getDouble("start_position_x", 0.0), cfg->getDouble("start_position_y", 0.0)); 0361 if (polar) { 0362 angle = cfg->getDouble("end_position_angle", 0.0); 0363 scale = cfg->getDouble("end_position_distance", 100.0); 0364 } else { 0365 // assume carthesian 0366 QPointF end(cfg->getDouble("end_position_x", 1.0), cfg->getDouble("end_position_y", 1.0)); 0367 // calculate angle and scale. 0368 double width = start.x() - end.x(); 0369 double height = start.y() - end.y(); 0370 angle = fmod(360.0 + kisRadiansToDegrees(atan2(width, height)), 360.0); 0371 scale = sqrt((width*width) + (height*height)); 0372 } 0373 0374 0375 if (style == "linear") { 0376 QPointF center(imageWidth*0.5, imageHeight*0.5); 0377 0378 QTransform rotate; 0379 rotate.rotate(angle); 0380 QTransform tf = QTransform::fromTranslate(-center.x(), -center.y()) 0381 * rotate * QTransform::fromTranslate(center.x(), center.y()); 0382 QPointF topleft = tf.inverted().map(QPointF(0.0, 0.0)); 0383 double xPercentage = (topleft.x()/double(imageWidth)) * 100.0; 0384 double yPercentage = (topleft.y()/double(imageHeight)) * 100.0; 0385 offset = QPointF((start.x() - xPercentage), (start.y() - yPercentage)); 0386 } else { 0387 scale = scale*2; 0388 offset = QPointF((start.x() - 50.0), (start.y() - 50.0)); 0389 } 0390 0391 double scaleModifier = 1.0; 0392 if (style == "square") { 0393 scaleModifier = cos(kisDegreesToRadians(45.0)); 0394 double halfAngle = fmod(fabs(angle), 180.0); 0395 scaleModifier *= 1/cos(kisDegreesToRadians(45.0 - fmod(halfAngle, 45.0) )); 0396 if (halfAngle >= 45.0 && halfAngle < 135.0) { 0397 scaleModifier = (scaleModifier) * (imageHeight / imageWidth); 0398 } 0399 0400 angle = angle - 45.0; 0401 if (angle < 0) { 0402 angle = 360.0 - angle; 0403 } 0404 0405 } else { 0406 double halfAngle = fmod(fabs(angle), 180.0); 0407 scaleModifier *= 1/cos(kisDegreesToRadians(halfAngle)); 0408 if (halfAngle >= 45.0 && halfAngle < 135.0) { 0409 scaleModifier = (scaleModifier) * (imageHeight / imageWidth); 0410 } 0411 0412 } 0413 0414 if (angle > 180) { 0415 angle = (0.0 - fmod(angle, 180.0)); 0416 } 0417 0418 scale /= fabs(scaleModifier); 0419 0420 0421 return res; 0422 } 0423 0424 QDomDocument getASLXML() { 0425 KisAslXmlWriter w; 0426 w.enterDescriptor("", "", "null"); 0427 0428 if (!gradient.isNull()) { 0429 const QDomElement gradientElement = gradient.firstChildElement(); 0430 if (!gradientElement.isNull()) { 0431 const QString gradientType = gradientElement.attribute("type"); 0432 if (gradientType == "stop") { 0433 const KoStopGradient *grad = new KoStopGradient(KoStopGradient::fromXML(gradientElement)); 0434 if (grad && grad->valid()) { 0435 w.writeStopGradient("Grad", grad); 0436 } 0437 } else if (gradientType == "segment") { 0438 const KoSegmentGradient *grad = new KoSegmentGradient(KoSegmentGradient::fromXML(gradientElement)); 0439 if (grad && grad->valid()) { 0440 w.writeSegmentGradient("Grad", grad); 0441 } 0442 } 0443 } 0444 } 0445 w.writeBoolean("Dthr", dithered); 0446 w.writeBoolean("Rvrs", reverse); 0447 w.writeUnitFloat("Angl", "#Ang", angle); 0448 0449 QString type = "Lnr "; 0450 if (style == "linear"){ 0451 type = "Lnr "; 0452 } else if (style == "radial") { 0453 type = "Rdl "; 0454 } else if (style == "conical"){ 0455 type = "Angl"; 0456 } else if (style == "bilinear"){ 0457 type = "Rflc"; 0458 } else if (style == "square") { 0459 type = "Dmnd"; 0460 } 0461 0462 w.writeEnum("Type", "GrdT", type); 0463 w.writeBoolean("Algn", align_with_layer); 0464 w.writeUnitFloat("Scl ", "#Prc", scale); 0465 w.writePoint("Ofst", offset); 0466 0467 w.leaveDescriptor(); 0468 0469 return w.document(); 0470 } 0471 }; 0472 0473 struct KRITAPSD_EXPORT psd_layer_pattern_fill { 0474 double angle {0.0}; 0475 double scale {1.0}; 0476 QPointF offset; 0477 QString patternName; 0478 QString patternID; 0479 KoPatternSP pattern; 0480 bool align_with_layer {false}; 0481 0482 void setAngle(float Angl) { 0483 angle = Angl; 0484 } 0485 void setScale(float Scl) { 0486 scale = Scl; 0487 } 0488 void setOffset(QPointF phase) { 0489 offset = phase; 0490 } 0491 0492 void setPatternRef(const QString Idnt, const QString name) { 0493 patternName = name; 0494 patternID = Idnt; 0495 } 0496 0497 void setAlignWithLayer(bool align) { 0498 align_with_layer = align; 0499 } 0500 0501 QDomDocument getFillLayerConfig() const { 0502 KisFilterConfigurationSP cfg; 0503 cfg = KisGeneratorRegistry::instance()->value("pattern")->defaultConfiguration(KisGlobalResourcesInterface::instance()); 0504 0505 cfg->setProperty("pattern", patternName); 0506 cfg->setProperty("fileName", QString(patternID + ".pat")); 0507 cfg->setProperty("md5", ""); // Zero out MD5, PSD patterns are looked up by UUID in filename 0508 0509 //angle is flipped for patterns in Krita. 0510 double fixedAngle = 360.0 - fmod(360.0 + angle, 360.0); 0511 0512 cfg->setProperty("transform_scale_x", scale / 100); 0513 cfg->setProperty("transform_scale_y", scale / 100); 0514 cfg->setProperty("transform_rotation_z", fixedAngle); 0515 0516 cfg->setProperty("transform_offset_x", offset.x()); 0517 cfg->setProperty("transform_offset_y", offset.y()); 0518 QDomDocument doc; 0519 doc.setContent(cfg->toXML()); 0520 return doc; 0521 } 0522 0523 bool loadFromConfig(KisFilterConfigurationSP cfg) { 0524 if (cfg->name() != "pattern") { 0525 return false; 0526 } 0527 0528 const QString patternMD5 = cfg->getString("md5", ""); 0529 const QString patternNameTemp = cfg->getString("pattern", "Grid01.pat"); 0530 const QString patternFileName = cfg->getString("fileName", ""); 0531 0532 KoResourceLoadResult res = KisGlobalResourcesInterface::instance()->source(ResourceType::Patterns).bestMatchLoadResult(patternMD5, patternFileName, patternNameTemp); 0533 pattern = res.resource<KoPattern>(); 0534 0535 patternName = cfg->getString("pattern", ""); 0536 0537 // Pattern ID needs the pattern to be saved first. 0538 0539 align_with_layer = false; 0540 0541 scale = cfg->getDouble("transform_scale_x", 1.0) * 100; 0542 0543 angle = 360.0 - cfg->getDouble("transform_rotation_z", 0.0); 0544 if (angle > 180) { 0545 angle = (180.0 - angle); 0546 } 0547 0548 offset = QPointF(cfg->getInt("transform_offset_x", 0), cfg->getInt("transform_offset_y", 0)); 0549 0550 return true; 0551 } 0552 0553 QDomDocument getASLXML() { 0554 KisAslXmlWriter w; 0555 w.enterDescriptor("", "", "null"); 0556 0557 // pattern ref 0558 w.enterDescriptor("Ptrn", "", "Ptrn"); 0559 0560 w.writeText("Nm ", patternName); 0561 if (patternID.isEmpty()) { 0562 qWarning() << "This pattern cannot be saved: No pattern UUID available."; 0563 return QDomDocument(); 0564 } 0565 w.writeText("Idnt", patternID); 0566 w.leaveDescriptor(); 0567 0568 // end 0569 0570 w.writeBoolean("Algn", align_with_layer); 0571 w.writeUnitFloat("Scl ", "#Prc", scale); 0572 w.writeUnitFloat("Angl", "#Ang", angle); 0573 w.writePoint("phase", offset); 0574 0575 w.leaveDescriptor(); 0576 0577 return w.document(); 0578 } 0579 }; 0580 0581 struct KRITAPSD_EXPORT psd_layer_type_face { 0582 qint8 mark {0}; // Mark value 0583 qint32 font_type {0}; // Font type data 0584 qint8 font_name[256]; // Pascal string of font name 0585 qint8 font_family_name[256]; // Pascal string of font family name 0586 qint8 font_style_name[256]; // Pascal string of font style name 0587 qint8 script {0}; // Script value 0588 qint32 number_axes_vector {0}; // Number of design axes vector to follow 0589 qint32 *vector {nullptr}; // Design vector value 0590 }; 0591 0592 struct KRITAPSD_EXPORT psd_layer_type_style { 0593 qint8 mark {0}; // Mark value 0594 qint8 face_mark {0}; // Face mark value 0595 qint32 size {0}; // Size value 0596 qint32 tracking {0}; // Tracking value 0597 qint32 kerning {0}; // Kerning value 0598 qint32 leading {0}; // Leading value 0599 qint32 base_shift {0}; // Base shift value 0600 bool auto_kern {false}; // Auto kern on/off 0601 bool rotate {false}; // Rotate up/down 0602 }; 0603 0604 struct KRITAPSD_EXPORT psd_layer_type_line { 0605 qint32 char_count {0}; // Character count value 0606 qint8 orientation {0}; // Orientation value 0607 qint8 alignment {0}; // Alignment value 0608 qint8 actual_char {0}; // Actual character as a double byte character 0609 qint8 style {0}; // Style value 0610 }; 0611 0612 struct KRITAPSD_EXPORT psd_layer_type_tool { 0613 double transform_info[6]; // 6 * 8 double precision numbers for the transform information 0614 qint8 faces_count {0}; // Count of faces 0615 psd_layer_type_face *face {nullptr}; 0616 qint8 styles_count {0}; // Count of styles 0617 psd_layer_type_style *style {nullptr}; 0618 qint8 type {0}; // Type value 0619 qint32 scaling_factor {0}; // Scaling factor value 0620 qint32 character_count {0}; // Character count value 0621 qint32 horz_place {0}; // Horizontal placement 0622 qint32 vert_place {0}; // Vertical placement 0623 qint32 select_start {0}; // Select start value 0624 qint32 select_end {0}; // Select end value 0625 qint8 lines_count {0}; // Line count 0626 psd_layer_type_line *line {nullptr}; 0627 QColor color; 0628 bool anti_alias {false}; // Anti alias on/off 0629 }; 0630 0631 /** 0632 * @brief The PsdAdditionalLayerInfoBlock class implements the Additional Layer Information block 0633 * 0634 * See: https://www.adobe.com/devnet-apps/photoshop/fileformatashtml/#50577409_71546 0635 */ 0636 class KRITAPSD_EXPORT PsdAdditionalLayerInfoBlock 0637 { 0638 public: 0639 PsdAdditionalLayerInfoBlock(const PSDHeader &header); 0640 0641 using ExtraLayerInfoBlockHandler = std::function<bool(QIODevice &)>; 0642 using UserMaskInfoBlockHandler = std::function<bool(QIODevice &)>; 0643 0644 void setExtraLayerInfoBlockHandler(ExtraLayerInfoBlockHandler handler); 0645 void setUserMaskInfoBlockHandler(UserMaskInfoBlockHandler handler); 0646 0647 bool read(QIODevice &io); 0648 bool write(QIODevice &io, KisNodeSP node); 0649 0650 void writeLuniBlockEx(QIODevice &io, const QString &layerName); 0651 void writeLsctBlockEx(QIODevice &io, psd_section_type sectionType, bool isPassThrough, const QString &blendModeKey); 0652 void writeLfx2BlockEx(QIODevice &io, const QDomDocument &stylesXmlDoc, bool useLfxsLayerStyleFormat); 0653 void writePattBlockEx(QIODevice &io, const QDomDocument &patternsXmlDoc); 0654 void writeLclrBlockEx(QIODevice &io, const quint16 &labelColor); 0655 0656 void writeFillLayerBlockEx(QIODevice &io, const QDomDocument &fillConfig, psd_fill_type type); 0657 0658 bool valid(); 0659 0660 const PSDHeader &m_header; 0661 QString error; 0662 QStringList keys; // List of all the keys that we've seen 0663 0664 QString unicodeLayerName; 0665 QDomDocument layerStyleXml; 0666 QVector<QDomDocument> embeddedPatterns; 0667 quint16 labelColor{0}; // layer color. 0668 0669 QDomDocument fillConfig; 0670 psd_fill_type fillType {psd_fill_solid_color}; 0671 0672 psd_section_type sectionDividerType; 0673 QString sectionDividerBlendMode; 0674 0675 private: 0676 template<psd_byte_order byteOrder = psd_byte_order::psdBigEndian> 0677 void readImpl(QIODevice &io); 0678 0679 template<psd_byte_order byteOrder = psd_byte_order::psdBigEndian> 0680 void writeLuniBlockExImpl(QIODevice &io, const QString &layerName); 0681 0682 template<psd_byte_order byteOrder = psd_byte_order::psdBigEndian> 0683 void writeLsctBlockExImpl(QIODevice &io, psd_section_type sectionType, bool isPassThrough, const QString &blendModeKey); 0684 0685 template<psd_byte_order byteOrder = psd_byte_order::psdBigEndian> 0686 void writeLfx2BlockExImpl(QIODevice &io, const QDomDocument &stylesXmlDoc, bool useLfxsLayerStyleFormat); 0687 0688 template<psd_byte_order byteOrder = psd_byte_order::psdBigEndian> 0689 void writePattBlockExImpl(QIODevice &io, const QDomDocument &patternsXmlDoc); 0690 0691 template<psd_byte_order byteOrder = psd_byte_order::psdBigEndian> 0692 void writeLclrBlockExImpl(QIODevice &io, const quint16 &lclr); 0693 0694 template<psd_byte_order byteOrder = psd_byte_order::psdBigEndian> 0695 void writeFillLayerBlockExImpl(QIODevice &io, const QDomDocument &fillConfig, psd_fill_type type); 0696 0697 private: 0698 ExtraLayerInfoBlockHandler m_layerInfoBlockHandler; 0699 UserMaskInfoBlockHandler m_userMaskBlockHandler; 0700 }; 0701 0702 #endif // PSD_ADDITIONAL_LAYER_INFO_BLOCK_H