示例#1
0
void CFunc::GetAlpha(BOOL& src, BOOL& dst) const
{
   src = dst = FALSE;
   CMyString sDescr = DescrName();
   CMyString srcStr = firstChanStr(sDescr);
   CMyString dstStr = firstChanStr(sDescr);
   src = alphaChannel(srcStr);
   if (dstStr.IsEmpty())
      dst = src;
   else
      dst = alphaChannel(dstStr);
}
PassOwnPtrWillBeRawPtr<InterpolableValue> ColorStyleInterpolation::colorToInterpolableValue(const CSSValue& value)
{
    ASSERT(value.isPrimitiveValue());
    const CSSPrimitiveValue& primitive = toCSSPrimitiveValue(value);
    RGBA32 color;
    if (primitive.isValueID()) {
        if (CSSPropertyParser::isSystemColor(primitive.getValueID())) {
            color = LayoutTheme::theme().systemColor(primitive.getValueID()).rgb();
        } else {
            Color colorFromID;
            colorFromID.setNamedColor(getValueName(primitive.getValueID()));
            color = colorFromID.rgb();
        }
    } else {
        color = primitive.getRGBA32Value();
    }

    int alpha = alphaChannel(color);

    OwnPtrWillBeRawPtr<InterpolableList> list = InterpolableList::create(4);
    list->set(0, InterpolableNumber::create(redChannel(color) * alpha));
    list->set(1, InterpolableNumber::create(greenChannel(color) * alpha));
    list->set(2, InterpolableNumber::create(blueChannel(color) * alpha));
    list->set(3, InterpolableNumber::create(alpha));

    return list->clone();
}
示例#3
0
static Color blendWithOpacity(const Color& color, float opacity)
{
    RGBA32 rgba = color.rgb();
    // See Color::getRGBA() to know how to extract alpha from color.
    float alpha = alphaChannel(rgba) / 255.;
    float effectiveAlpha = alpha * opacity;
    return Color(colorWithOverrideAlpha(rgba, effectiveAlpha));
}
示例#4
0
void ObjectScene::syncQuad(Kite::KQuadCom *Quad) {
	auto pixItem = (QGraphicsPixmapItem *)Quad->getSceneItem();

	Kite::KRectF32 brect;
	Quad->getBoundingRect(brect);

	if (!Quad->getAtlasTextureArray().str.empty()) {
		Kite::KAtlasTextureArray *tarray = nullptr;
		emit(tarray = (Kite::KAtlasTextureArray *)requestResource(Quad->getAtlasTextureArray().str.c_str()));

		if (tarray) {
			auto atex = tarray->getItem(Quad->getTextureArrayIndex());
			if (atex) {
				Kite::KTexture *tex = atex->getTexture();
				if (tex) {
					Kite::KImage image;
					tex->getImage(image);
					QImage qimage(image.getPixelsData(), image.getWidth(), image.getHeight(), QImage::Format::Format_RGBA8888);
					auto procimgae = qimage.copy(Quad->getAtlasItem().xpos, Quad->getAtlasItem().ypos,
																	  Quad->getAtlasItem().width, Quad->getAtlasItem().height)
														  .mirrored(Quad->getAtlasItem().getFlipH(), !Quad->getAtlasItem().getFlipV())
														  .scaled(Quad->getWidth(), Quad->getHeight());

					//blend
					if (Quad->getBlendColor() != Kite::KColor(Kite::Colors::WHITE)) {
						QColor col(Quad->getBlendColor().getR(), Quad->getBlendColor().getG(),
								   Quad->getBlendColor().getB(), Quad->getBlendColor().getA());

						auto alpha = procimgae.alphaChannel();
						for (int x = 0; x != procimgae.width(); ++x) {
							for (int y(0); y != procimgae.height(); ++y) {
								if (qAlpha(procimgae.pixel(x, y)) == 0) continue; // transparrent pixels

								QColor icol(procimgae.pixel(x, y));
								icol.setRed(BLEND_Multiply(icol.red(), col.red()));
								icol.setBlue(BLEND_Multiply(icol.blue(), col.blue()));
								icol.setGreen(BLEND_Multiply(icol.green(), col.green()));
								procimgae.setPixel(x, y, icol.rgb());
							}
						}
						procimgae.setAlphaChannel(alpha);
					}

					pixItem->setPixmap(QPixmap::fromImage(procimgae));
					pixItem->setOpacity(Quad->getBlendColor().getGLA());
					return;
				}
			}
		}
	}
	
	QPixmap pm(Quad->getWidth(), Quad->getHeight());
	pm.fill(QColor(Quad->getBlendColor().getR(), Quad->getBlendColor().getG(), Quad->getBlendColor().getB(), Quad->getBlendColor().getA()));
	pixItem->setPixmap(pm);
	pixItem->setOpacity(Quad->getBlendColor().getGLA());
}
示例#5
0
Color colorFromPremultipliedARGB(RGBA32 pixelColor)
{
    int alpha = alphaChannel(pixelColor);
    if (alpha && alpha < 255) {
        return Color::createUnchecked(
            redChannel(pixelColor) * 255 / alpha,
            greenChannel(pixelColor) * 255 / alpha,
            blueChannel(pixelColor) * 255 / alpha,
            alpha);
    } else
        return Color(pixelColor);
}
bool CanvasRenderingContext2DState::shouldDrawShadows() const
{
    return alphaChannel(m_shadowColor) && (m_shadowBlur || !m_shadowOffset.isZero());
}
示例#7
0
bool ImageHandler::getSessionItemImage(SessionItem* pItem, QBuffer& buffer, const QString& format, int band, int* pBbox)
{
   if (format.isEmpty())
   {
      return false;
   }
   bool success = true;
   QImage image;
   Layer* pLayer = dynamic_cast<Layer*>(pItem);
   View* pView = dynamic_cast<View*>(pItem);
   if (pLayer != NULL)
   {
      SpatialDataView* pSDView = dynamic_cast<SpatialDataView*>(pLayer->getView());
      if (pSDView != NULL)
      {
         UndoLock ulock(pSDView);
         DimensionDescriptor cur;
         DisplayMode mode;
         RasterLayer* pRasterLayer = dynamic_cast<RasterLayer*>(pLayer);
         if (band >= 0 && pRasterLayer != NULL)
         {
            RasterElement* pRaster = pRasterLayer->getDisplayedRasterElement(GRAY);
            DimensionDescriptor bandDesc =
               static_cast<RasterDataDescriptor*>(pRaster->getDataDescriptor())->getActiveBand(band);
            cur = pRasterLayer->getDisplayedBand(GRAY);
            mode = pRasterLayer->getDisplayMode();
            pRasterLayer->setDisplayedBand(GRAY, bandDesc);
            pRasterLayer->setDisplayMode(GRAYSCALE_MODE);
         }
         int bbox[4] = {0, 0, 0, 0};
         ColorType transparent(255, 255, 254);
         success = pSDView->getLayerImage(pLayer, image, transparent, bbox);
         if (pBbox != NULL)
         {
            memcpy(pBbox, bbox, sizeof(bbox));
         }
         QImage alphaChannel(image.size(), QImage::Format_Indexed8);
         if (image.hasAlphaChannel())
         {
            alphaChannel = image.alphaChannel();
         }
         else
         {
            alphaChannel.fill(0xff);
         }
         QRgb transColor = COLORTYPE_TO_QCOLOR(transparent).rgb();
         for (int y = 0; y < image.height(); y++)
         {
            for (int x = 0; x < image.width(); x++)
            {
               if (image.pixel(x, y) == transColor)
               {
                  alphaChannel.setPixel(x, y, 0x00);
               }
            }
         }
         image.setAlphaChannel(alphaChannel);
         if (mode.isValid())
         {
            pRasterLayer->setDisplayedBand(GRAY, cur);
            pRasterLayer->setDisplayMode(mode);
         }
      }
   }
   else if (pView != NULL)
   {
      success = pView->getCurrentImage(image);
   }
   else
   {
      success = false;
   }
   if (success)
   {
      buffer.open(QIODevice::WriteOnly);
      QImageWriter writer(&buffer, format.toAscii());
      success = writer.write(image);
   }
   return success;
}