void PSDColorModeBlockTest::testLoadingIndexed() { QString filename = QString(FILES_DATA_DIR) + "/sources/100x100indexed.psd"; QFile f(filename); f.open(QIODevice::ReadOnly); PSDHeader header; header.read(&f); QVERIFY(header.colormode == Indexed); PSDColorModeBlock colorModeBlock(header.colormode); bool retval = colorModeBlock.read(&f); Q_ASSERT(retval); Q_UNUSED(retval); Q_ASSERT(colorModeBlock.valid()); }
void PSDHeaderTest::testLoading() { QString filename = QString(FILES_DATA_DIR) + "/sources/1.psd"; QFile f(filename); f.open(QIODevice::ReadOnly); PSDHeader header; header.read(&f); QVERIFY(header.signature == QString("8BPS")); QVERIFY(header.version == 1); QVERIFY(header.nChannels == 3); QVERIFY(header.width == 100 ); QVERIFY(header.height == 100); QVERIFY(header.channelDepth == 16); QVERIFY(header.colormode == RGB); }
KisImageBuilder_Result PSDLoader::decode(const KUrl& uri) { // open the file QFile f(uri.toLocalFile()); if (!f.exists()) { return KisImageBuilder_RESULT_NOT_EXIST; } if (!f.open(QIODevice::ReadOnly)) { return KisImageBuilder_RESULT_FAILURE; } dbgFile << "pos:" << f.pos(); PSDHeader header; if (!header.read(&f)) { dbgFile << "failed reading header: " << header.error; return KisImageBuilder_RESULT_FAILURE; } dbgFile << header; dbgFile << "Read header. pos:" << f.pos(); PSDColorModeBlock colorModeBlock(header.colormode); if (!colorModeBlock.read(&f)) { dbgFile << "failed reading colormode block: " << colorModeBlock.error; return KisImageBuilder_RESULT_FAILURE; } dbgFile << "Read color mode block. pos:" << f.pos(); PSDResourceSection resourceSection; if (!resourceSection.read(&f)) { dbgFile << "failed reading resource section: " << resourceSection.error; return KisImageBuilder_RESULT_FAILURE; } dbgFile << "Read resource section. pos:" << f.pos(); PSDLayerSection layerSection(header); if (!layerSection.read(&f)) { dbgFile << "failed reading layer section: " << layerSection.error; return KisImageBuilder_RESULT_FAILURE; } // XXX: add all the image resource blocks as annotations to the image dbgFile << "Read layer section. " << layerSection.nLayers << "layers. pos:" << f.pos(); // Get the right colorspace QPair<QString, QString> colorSpaceId = psd_colormode_to_colormodelid(header.colormode, header.channelDepth); if (colorSpaceId.first.isNull()) return KisImageBuilder_RESULT_UNSUPPORTED_COLORSPACE; // Get the icc profile! const KoColorProfile* profile = 0; if (resourceSection.resources.contains(PSDResourceSection::ICC_PROFILE)) { ICC_PROFILE_1039 *iccProfileData = dynamic_cast<ICC_PROFILE_1039*>(resourceSection.resources[PSDResourceSection::ICC_PROFILE]->resource); if (iccProfileData ) { profile = KoColorSpaceRegistry::instance()->createColorProfile(colorSpaceId.first, colorSpaceId.second, iccProfileData->icc); dbgFile << "Loaded ICC profile" << profile->name(); } } // Create the colorspace const KoColorSpace* cs = KoColorSpaceRegistry::instance()->colorSpace(colorSpaceId.first, colorSpaceId.second, profile); if (!cs) { return KisImageBuilder_RESULT_UNSUPPORTED_COLORSPACE; } // Creating the KisImageWSP m_image = new KisImage(m_doc->createUndoStore(), header.width, header.height, cs, "built image"); Q_CHECK_PTR(m_image); m_image->lock(); // set the correct resolution if (resourceSection.resources.contains(PSDResourceSection::RESN_INFO)) { RESN_INFO_1005 *resInfo = dynamic_cast<RESN_INFO_1005*>(resourceSection.resources[PSDResourceSection::RESN_INFO]->resource); if (resInfo) { m_image->setResolution(POINT_TO_INCH(resInfo->hRes), POINT_TO_INCH(resInfo->vRes)); // let's skip the unit for now; we can only set that on the KoDocument, and krita doesn't use it. } } // Preserve the duotone colormode block for saving back to psd if (header.colormode == DuoTone) { KisAnnotationSP annotation = new KisAnnotation("DuotoneColormodeBlock", i18n("Duotone Colormode Block"), colorModeBlock.data); m_image->addAnnotation(annotation); } // read the projection into our single layer if (layerSection.nLayers == 0) { dbgFile << "Position" << f.pos() << "Going to read the projection into the first layer, which Photoshop calls 'Background'"; KisPaintLayerSP layer = new KisPaintLayer(m_image, i18n("Background"), OPACITY_OPAQUE_U8); KisTransaction("", layer -> paintDevice()); PSDImageData imageData(&header); imageData.read(&f, layer->paintDevice()); //readLayerData(&f, layer->paintDevice(), f.pos(), QRect(0, 0, header.width, header.height)); m_image->addNode(layer, m_image->rootLayer()); } else { // read the channels for the various layers for(int i = 0; i < layerSection.nLayers; ++i) { // XXX: work out the group layer structure in Photoshop, as well as the adjustment layers PSDLayerRecord* layerRecord = layerSection.layers.at(i); dbgFile << "Going to read channels for layer" << i << layerRecord->layerName; KisPaintLayerSP layer = new KisPaintLayer(m_image, layerRecord->layerName, layerRecord->opacity); layer->setCompositeOp(psd_blendmode_to_composite_op(layerRecord->blendModeKey)); if (!layerRecord->readPixelData(&f, layer->paintDevice())) { dbgFile << "failed reading channels for layer: " << layerRecord->layerName << layerRecord->error; return KisImageBuilder_RESULT_FAILURE; } m_image->addNode(layer, m_image->rootLayer()); layer->setVisible(layerRecord->visible); } } m_image->unlock(); return KisImageBuilder_RESULT_OK; }