Example #1
0
KisNodeListSP KisInputOutputMapper::inputNodes(InputLayerMode inputMode)
{
/*
    ACTIVE_LAYER,
    ALL_LAYERS,
    ACTIVE_LAYER_BELOW_LAYER,
    ACTIVE_LAYER_ABOVE_LAYER,
    ALL_VISIBLE_LAYERS,
    ALL_INVISIBLE_LAYERS,
    ALL_VISIBLE_LAYERS_DECR,
    ALL_INVISIBLE_DECR,
    ALL_DECR
*/

    KisNodeListSP result(new QList< KisNodeSP >());
    switch (inputMode)
    {
        case ACTIVE_LAYER:
        {
            result->append(m_activeNode);
            break;// drop down in case of one more layer modes
        }
        case ACTIVE_LAYER_BELOW_LAYER:
        {
            result->append(m_activeNode);
            result->append(m_activeNode->prevSibling());
            break;
        }
        case ACTIVE_LAYER_ABOVE_LAYER:
        {
            result->append(m_activeNode);
            result->append(m_activeNode->nextSibling());
            break;
        }
        case ALL_VISIBLE_LAYERS:
        case ALL_INVISIBLE_LAYERS:
        case ALL_VISIBLE_LAYERS_DECR:
        case ALL_INVISIBLE_DECR:
        {
            dbgPlugins << "Not implemented";
            break;
        }
        case ALL_LAYERS:
        {
            allLayers(result);
            break;
        }
        case ALL_DECR:
        {
            allInversedOrderedLayers(result);
        }
        default:
        {
            Q_ASSERT(false); // why here??
            break;
        }
    }
    return result;
}
Example #2
0
PsdStatus PsdFile::readLayers(const uint8_t *&ptr, const uint8_t *end)
{
    if (ptr > mMapped.get().getEndAddress())
        return PsdStatusFileOutOfRange;

    PsdStatus status;
    deque<PsdLayerGroup *> groups;
    PsdLayerGroup *group = NULL;
    PsdLayers allLayers(new vector<shared_ptr<PsdLayer> >());
    allLayers->reserve(mLayersCount);
    mLayers.reset(new vector<shared_ptr<PsdLayer> >);
    mLayers->reserve(mLayersCount / 2 + 1);

    // read the header of each layer and construct the layer group tree
    for (uint16_t i = 0; i < mLayersCount && ptr < end; i++) {
        shared_ptr<PsdLayer> layer(new PsdLayer(this));

        status = layer->readMeta(ptr, end);
        if (status != PsdStatusOK)
            return status;

        allLayers->push_back(layer);

        LOG_DEBUG("layer: %s\n", layer->getName());
        if (layer->getType() == PsdLayer::LayerTypeGroup) {
            if (layer->mIsEndOfGroup) {
                group = new PsdLayerGroup(this);
                groups.push_back(group);
            } else if (group) {
                group->mName = layer->mName;
                groups.pop_back();

                if (groups.empty()) {
                    // No group in the stack, push to the root group
                    mLayers->push_back(shared_ptr<PsdLayer>(group));
                    group = NULL;
                } else {
                    // Otherwise, push to the top group on the stack
                    groups.back()->mLayers->push_back(shared_ptr<PsdLayer>(group));
                    group = groups.back();
                }
            } else {
                LOG_ALWAYS("A group layer is found but no end-of-group layer exists. Ignoring this layer.");
            }
        } else {
            if (group)
                group->mLayers->push_back(layer);
            else
                mLayers->push_back(layer);
        }
        ptr = layer->mAdditionalInfoBlock.getEndAddress();
    }
    if (!groups.empty())
        return PsdStatusLayerGroupNotComplete;

    LOG_DEBUG("Layer image data start: %u\n", uint32_t(ptr - mMapped.get().mAddress));

    // loop over all layers to obtain the address and length of per-layer image data
    vector<shared_ptr<PsdLayer> >::iterator iter = allLayers->begin(), layersEnd = allLayers->end();
    for (; iter != layersEnd; iter++) {
        PsdLayer *layer = iter->get();

        if (ptr + layer->mImageDataBlock.mLength > end)
            return PsdStatusFileOutOfRange;
        LOG_DEBUG("Layer image data: %u\n", uint32_t(ptr - mMapped.get().mAddress));
        layer->mImageDataBlock.mAddress = ptr;
        ptr += layer->mImageDataBlock.mLength;
    }

    LOG_DEBUG("Layer image data end: %u\n", uint32_t(ptr - mMapped.get().mAddress));

    return PsdStatusOK;
}