Example #1
0
QImage ComponentTransferEffect::processImage(const QImage &image, const KoFilterEffectRenderContext &context) const
{
    QImage result = image;

#if QT_VERSION >= 0x040700
    const QRgb *src = (const QRgb*)image.constBits();
#else
    const QRgb *src = (const QRgb*)image.bits();
#endif
    QRgb *dst = (QRgb*)result.bits();
    int w = result.width();

    qreal sa, sr, sg, sb;
    qreal da, dr, dg, db;
    int pixel;

    const QRect roi = context.filterRegion().toRect();
    const int minRow = roi.top();
    const int maxRow = roi.bottom();
    const int minCol = roi.left();
    const int maxCol = roi.right();

    for (int row = minRow; row <= maxRow; ++row) {
        for (int col = minCol; col <= maxCol; ++col) {
            pixel = row * w + col;
            const QRgb &s = src[pixel];

            sa = fromIntColor[qAlpha(s)];
            sr = fromIntColor[qRed(s)];
            sg = fromIntColor[qGreen(s)];
            sb = fromIntColor[qBlue(s)];
            // the matrix is applied to non-premultiplied color values
            // so we have to convert colors by dividing by alpha value
            if (sa > 0.0 && sa < 1.0) {
                sr /= sa;
                sb /= sa;
                sg /= sa;
            }

            dr = transferChannel(ChannelR, sr);
            dg = transferChannel(ChannelG, sg);
            db = transferChannel(ChannelB, sb);
            da = transferChannel(ChannelA, sa);

            da *= 255.0;

            // set pre-multiplied color values on destination image
            dst[pixel] = qRgba(static_cast<quint8>(qBound(qreal(0.0), dr * da, qreal(255.0))),
                               static_cast<quint8>(qBound(qreal(0.0), dg * da, qreal(255.0))),
                               static_cast<quint8>(qBound(qreal(0.0), db * da, qreal(255.0))),
                               static_cast<quint8>(qBound(qreal(0.0), da, qreal(255.0))));
        }
    }

    return result;
}
Example #2
0
void CAddonCallbacksPVR::PVRTransferChannelEntry(void *addonData, const ADDON_HANDLE handle, const PVR_CHANNEL *channel)
{
  if (!handle)
  {
    CLog::Log(LOGERROR, "PVR - %s - invalid handler data", __FUNCTION__);
    return;
  }

  CPVRClient *client                     = GetPVRClient(addonData);
  CPVRChannelGroupInternal *xbmcChannels = static_cast<CPVRChannelGroupInternal *>(handle->dataAddress);
  if (!channel || !client || !xbmcChannels)
  {
    CLog::Log(LOGERROR, "PVR - %s - invalid handler data", __FUNCTION__);
    return;
  }

  /* transfer this entry to the internal channels group */
  CPVRChannelPtr transferChannel(new CPVRChannel(*channel, client->GetID()));
  xbmcChannels->UpdateFromClient(transferChannel);
}