void ImageBuffer::putByteArray(Multiply multiplied, ByteArray* source, const IntSize& sourceSize, const IntRect& sourceRect, const IntPoint& destPoint) { if (!m_context->isAcceleratedContext()) { m_data.putData(source, sourceSize, sourceRect, destPoint, internalSize(), m_context->isAcceleratedContext(), multiplied == Unmultiplied); return; } #if USE(IOSURFACE_CANVAS_BACKING_STORE) // Make a copy of the source to ensure the bits don't change before being drawn IntSize sourceCopySize(sourceRect.width(), sourceRect.height()); OwnPtr<ImageBuffer> sourceCopy = ImageBuffer::create(sourceCopySize, 1, ColorSpaceDeviceRGB, Unaccelerated); if (!sourceCopy) return; sourceCopy->m_data.putData(source, sourceSize, sourceRect, IntPoint(-sourceRect.x(), -sourceRect.y()), sourceCopy->internalSize(), sourceCopy->context()->isAcceleratedContext(), multiplied == Unmultiplied); // Set up context for using drawImage as a direct bit copy CGContextRef destContext = context()->platformContext(); CGContextSaveGState(destContext); CGContextConcatCTM(destContext, AffineTransform(CGContextGetCTM(destContext)).inverse()); wkCGContextResetClip(destContext); CGContextSetInterpolationQuality(destContext, kCGInterpolationNone); CGContextSetAlpha(destContext, 1.0); CGContextSetBlendMode(destContext, kCGBlendModeCopy); CGContextSetShadowWithColor(destContext, CGSizeZero, 0, 0); // Draw the image in CG coordinate space IntPoint destPointInCGCoords(destPoint.x() + sourceRect.x(), internalSize().height() - (destPoint.y()+sourceRect.y()) - sourceRect.height()); IntRect destRectInCGCoords(destPointInCGCoords, sourceCopySize); RetainPtr<CGImageRef> sourceCopyImage(AdoptCF, sourceCopy->copyNativeImage()); CGContextDrawImage(destContext, destRectInCGCoords, sourceCopyImage.get()); CGContextRestoreGState(destContext); #endif }
NativeImagePtr ImageBuffer::copyNativeImage(BackingStoreCopy copyBehavior) const { CGImageRef image = 0; if (!m_context->isAcceleratedContext()) { switch (copyBehavior) { case DontCopyBackingStore: image = CGImageCreate(internalSize().width(), internalSize().height(), 8, 32, m_data.m_bytesPerRow.unsafeGet(), m_data.m_colorSpace, m_data.m_bitmapInfo, m_data.m_dataProvider.get(), 0, true, kCGRenderingIntentDefault); break; case CopyBackingStore: image = CGBitmapContextCreateImage(context()->platformContext()); break; default: ASSERT_NOT_REACHED(); break; } } #if USE(IOSURFACE_CANVAS_BACKING_STORE) else { image = wkIOSurfaceContextCreateImage(context()->platformContext()); #if defined(BUILDING_ON_LION) m_data.m_lastFlushTime = currentTimeMS(); #endif } #endif return image; }
PassRefPtr<ByteArray> ImageBuffer::getPremultipliedImageData(const IntRect& rect) const { if (m_context->isAcceleratedContext()) { CGContextFlush(context()->platformContext()); #if defined(BUILDING_ON_LION) m_data.m_lastFlushTime = currentTimeMS(); #endif } return m_data.getData(rect, internalSize(), m_context->isAcceleratedContext(), false); }
PassRefPtr<Uint8ClampedArray> ImageBuffer::getPremultipliedImageData(const IntRect& rect, CoordinateSystem coordinateSystem) const { if (m_context->isAcceleratedContext()) { CGContextFlush(context()->platformContext()); #if defined(BUILDING_ON_LION) m_data.m_lastFlushTime = currentTimeMS(); #endif } return m_data.getData(rect, internalSize(), m_context->isAcceleratedContext(), false, coordinateSystem == LogicalCoordinateSystem ? m_resolutionScale : 1); }
PassRefPtr<Uint8ClampedArray> ImageBuffer::getPremultipliedImageData(const IntRect& rect, CoordinateSystem coordinateSystem) const { if (context().isAcceleratedContext()) flushContext(); IntRect srcRect = rect; if (coordinateSystem == LogicalCoordinateSystem) srcRect.scale(m_resolutionScale); return m_data.getData(srcRect, internalSize(), context().isAcceleratedContext(), false, 1); }
String ImageBuffer::toDataURL(const String& mimeType, const double* quality) const { ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType)); RetainPtr<CGImageRef> image; RetainPtr<CFStringRef> uti = utiFromMIMEType(mimeType); ASSERT(uti); RefPtr<ByteArray> arr; if (CFEqual(uti.get(), jpegUTI())) { // JPEGs don't have an alpha channel, so we have to manually composite on top of black. arr = getPremultipliedImageData(IntRect(IntPoint(0, 0), internalSize())); unsigned char *data = arr->data(); for (int i = 0; i < internalSize().width() * internalSize().height(); i++) data[i * 4 + 3] = 255; // The image is already premultiplied, so we just need to make it opaque. RetainPtr<CGDataProviderRef> dataProvider; dataProvider.adoptCF(CGDataProviderCreateWithData(0, data, 4 * internalSize().width() * internalSize().height(), 0)); if (!dataProvider) return "data:,"; image.adoptCF(CGImageCreate(internalSize().width(), internalSize().height(), 8, 32, 4 * internalSize().width(), CGColorSpaceCreateDeviceRGB(), kCGBitmapByteOrderDefault | kCGImageAlphaLast, dataProvider.get(), 0, false, kCGRenderingIntentDefault)); } else image.adoptCF(copyNativeImage(CopyBackingStore)); if (!image) return "data:,"; return CGImageToDataURL(image.get(), mimeType, quality); }
void ImageBuffer::putByteArray(Multiply multiplied, Uint8ClampedArray* source, const IntSize& sourceSize, const IntRect& sourceRect, const IntPoint& destPoint, CoordinateSystem coordinateSystem) { if (!context().isAcceleratedContext()) { IntRect scaledSourceRect = sourceRect; IntSize scaledSourceSize = sourceSize; if (coordinateSystem == LogicalCoordinateSystem) { scaledSourceRect.scale(m_resolutionScale); scaledSourceSize.scale(m_resolutionScale); } m_data.putData(source, scaledSourceSize, scaledSourceRect, destPoint, internalSize(), false, multiplied == Unmultiplied, 1); return; } #if USE(IOSURFACE_CANVAS_BACKING_STORE) // Make a copy of the source to ensure the bits don't change before being drawn IntSize sourceCopySize(sourceRect.width(), sourceRect.height()); // FIXME (149431): Should this ImageBuffer be unconditionally unaccelerated? Making it match the context seems to break putData(). std::unique_ptr<ImageBuffer> sourceCopy = ImageBuffer::create(sourceCopySize, Unaccelerated, 1, ColorSpaceDeviceRGB); if (!sourceCopy) return; sourceCopy->m_data.putData(source, sourceSize, sourceRect, IntPoint(-sourceRect.x(), -sourceRect.y()), sourceCopy->internalSize(), sourceCopy->context().isAcceleratedContext(), multiplied == Unmultiplied, 1); // Set up context for using drawImage as a direct bit copy CGContextRef destContext = context().platformContext(); CGContextSaveGState(destContext); if (coordinateSystem == LogicalCoordinateSystem) CGContextConcatCTM(destContext, AffineTransform(wkGetUserToBaseCTM(destContext)).inverse()); else CGContextConcatCTM(destContext, AffineTransform(CGContextGetCTM(destContext)).inverse()); CGContextResetClip(destContext); CGContextSetInterpolationQuality(destContext, kCGInterpolationNone); CGContextSetAlpha(destContext, 1.0); CGContextSetBlendMode(destContext, kCGBlendModeCopy); CGContextSetShadowWithColor(destContext, CGSizeZero, 0, 0); // Draw the image in CG coordinate space FloatSize scaledDestSize = scaleSizeToUserSpace(coordinateSystem == LogicalCoordinateSystem ? logicalSize() : internalSize(), m_data.backingStoreSize, internalSize()); IntPoint destPointInCGCoords(destPoint.x() + sourceRect.x(), scaledDestSize.height() - (destPoint.y() + sourceRect.y()) - sourceRect.height()); IntRect destRectInCGCoords(destPointInCGCoords, sourceCopySize); CGContextClipToRect(destContext, destRectInCGCoords); RetainPtr<CGImageRef> sourceCopyImage = sourceCopy->copyNativeImage(); FloatRect backingStoreInDestRect = FloatRect(FloatPoint(destPointInCGCoords.x(), destPointInCGCoords.y() + sourceCopySize.height() - (int)CGImageGetHeight(sourceCopyImage.get())), FloatSize(CGImageGetWidth(sourceCopyImage.get()), CGImageGetHeight(sourceCopyImage.get()))); CGContextDrawImage(destContext, backingStoreInDestRect, sourceCopyImage.get()); CGContextRestoreGState(destContext); #endif }
void ImageBuffer::draw(GraphicsContext* destContext, ColorSpace styleColorSpace, const FloatRect& destRect, const FloatRect& srcRect, CompositeOperator op, bool useLowQualityScale) { UNUSED_PARAM(useLowQualityScale); ColorSpace colorSpace = (destContext == m_context) ? ColorSpaceDeviceRGB : styleColorSpace; RetainPtr<CGImageRef> image; if (destContext == m_context || destContext->isAcceleratedContext()) image.adoptCF(copyNativeImage(CopyBackingStore)); // Drawing into our own buffer, need to deep copy. else image.adoptCF(copyNativeImage(DontCopyBackingStore)); FloatRect adjustedSrcRect = srcRect; adjustedSrcRect.scale(m_resolutionScale, m_resolutionScale); destContext->drawNativeImage(image.get(), internalSize(), colorSpace, destRect, adjustedSrcRect, op); }
void OMIntegerType::externalize(const OMByte* internalBytes, OMUInt32 ANAME(internalBytesSize), OMByte* externalBytes, OMUInt32 externalBytesSize, OMByteOrder NNAME(byteOrder)) const { TRACE("OMIntegerType::externalize"); PRECONDITION("Valid internal bytes", internalBytes != 0); PRECONDITION("Valid internal bytes size", internalBytesSize >= internalSize(externalBytes, externalBytesSize)); PRECONDITION("Valid external bytes", externalBytes != 0); PRECONDITION("Valid external bytes size", externalBytesSize >= externalSize(internalBytes, internalBytesSize)); ASSERT("Consistent sizes", internalBytesSize == size()); ASSERT("Consistent sizes", externalBytesSize == size()); copy(internalBytes, externalBytes, externalBytesSize); }
void ImplAAFTypeDefCharacter::internalize(const OMByte* externalBytes, OMUInt32 ANAME(externalBytesSize), OMByte* internalBytes, OMUInt32 internalBytesSize, OMByteOrder byteOrder) const { TRACE("ImplAAFTypeDefCharacter::internalize"); PRECONDITION("Valid internal bytes", internalBytes != 0); PRECONDITION("Valid internal bytes size", internalBytesSize >= internalSize(externalBytes, externalBytesSize)); PRECONDITION("Valid external bytes", externalBytes != 0); PRECONDITION("Valid external bytes size", externalBytesSize >= externalSize(internalBytes, internalBytesSize)); if (sizeof(aafCharacter) == kExternalCharacterSize) copy(externalBytes, internalBytes, internalBytesSize); else expand(externalBytes, kExternalCharacterSize, internalBytes, sizeof(aafCharacter), byteOrder); }
inline void ImageBuffer::genericConvertToLuminanceMask() { IntRect luminanceRect(IntPoint(), internalSize()); RefPtr<ByteArray> srcPixelArray = getUnmultipliedImageData(luminanceRect); unsigned pixelArrayLength = srcPixelArray->length(); for (unsigned pixelOffset = 0; pixelOffset < pixelArrayLength; pixelOffset += 4) { unsigned char a = srcPixelArray->get(pixelOffset + 3); if (!a) continue; unsigned char r = srcPixelArray->get(pixelOffset); unsigned char g = srcPixelArray->get(pixelOffset + 1); unsigned char b = srcPixelArray->get(pixelOffset + 2); double luma = (r * 0.2125 + g * 0.7154 + b * 0.0721) * ((double)a / 255.0); srcPixelArray->set(pixelOffset + 3, luma); } putByteArray(Unmultiplied, srcPixelArray.get(), luminanceRect.size(), luminanceRect, IntPoint()); }
String ImageBuffer::toDataURL(const String& mimeType, const double* quality, CoordinateSystem) const { ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType)); if (context().isAcceleratedContext()) flushContext(); RetainPtr<CFStringRef> uti = utiFromMIMEType(mimeType); ASSERT(uti); RefPtr<Uint8ClampedArray> premultipliedData; RetainPtr<CGImageRef> image; if (CFEqual(uti.get(), jpegUTI())) { // JPEGs don't have an alpha channel, so we have to manually composite on top of black. premultipliedData = getPremultipliedImageData(IntRect(IntPoint(0, 0), logicalSize())); if (!premultipliedData) return "data:,"; RetainPtr<CGDataProviderRef> dataProvider; dataProvider = adoptCF(CGDataProviderCreateWithData(0, premultipliedData->data(), 4 * logicalSize().width() * logicalSize().height(), 0)); if (!dataProvider) return "data:,"; image = adoptCF(CGImageCreate(logicalSize().width(), logicalSize().height(), 8, 32, 4 * logicalSize().width(), deviceRGBColorSpaceRef(), kCGBitmapByteOrderDefault | kCGImageAlphaNoneSkipLast, dataProvider.get(), 0, false, kCGRenderingIntentDefault)); } else if (m_resolutionScale == 1) { image = copyNativeImage(CopyBackingStore); image = createCroppedImageIfNecessary(image.get(), internalSize()); } else { image = copyNativeImage(DontCopyBackingStore); RetainPtr<CGContextRef> context = adoptCF(CGBitmapContextCreate(0, logicalSize().width(), logicalSize().height(), 8, 4 * logicalSize().width(), deviceRGBColorSpaceRef(), kCGImageAlphaPremultipliedLast)); CGContextSetBlendMode(context.get(), kCGBlendModeCopy); CGContextClipToRect(context.get(), CGRectMake(0, 0, logicalSize().width(), logicalSize().height())); FloatSize imageSizeInUserSpace = scaleSizeToUserSpace(logicalSize(), m_data.backingStoreSize, internalSize()); CGContextDrawImage(context.get(), CGRectMake(0, 0, imageSizeInUserSpace.width(), imageSizeInUserSpace.height()), image.get()); image = adoptCF(CGBitmapContextCreateImage(context.get())); } return CGImageToDataURL(image.get(), mimeType, quality); }
RefPtr<Image> ImageBuffer::copyImage(BackingStoreCopy copyBehavior, ScaleBehavior scaleBehavior) const { RetainPtr<CGImageRef> image; if (m_resolutionScale == 1 || scaleBehavior == Unscaled) { image = copyNativeImage(copyBehavior); image = createCroppedImageIfNecessary(image.get(), internalSize()); } else { image = copyNativeImage(DontCopyBackingStore); RetainPtr<CGContextRef> context = adoptCF(CGBitmapContextCreate(0, logicalSize().width(), logicalSize().height(), 8, 4 * logicalSize().width(), deviceRGBColorSpaceRef(), kCGImageAlphaPremultipliedLast)); CGContextSetBlendMode(context.get(), kCGBlendModeCopy); CGContextClipToRect(context.get(), FloatRect(FloatPoint::zero(), logicalSize())); FloatSize imageSizeInUserSpace = scaleSizeToUserSpace(logicalSize(), m_data.backingStoreSize, internalSize()); CGContextDrawImage(context.get(), FloatRect(FloatPoint::zero(), imageSizeInUserSpace), image.get()); image = adoptCF(CGBitmapContextCreateImage(context.get())); } if (!image) return nullptr; return BitmapImage::create(image.get()); }
void ImageBuffer::clip(GraphicsContext& contextToClip, const FloatRect& rect) const { FloatSize backingStoreSizeInUserSpace = scaleSizeToUserSpace(rect.size(), m_data.backingStoreSize, internalSize()); RetainPtr<CGImageRef> image = copyNativeImage(DontCopyBackingStore); contextToClip.clipToNativeImage(image.get(), rect, backingStoreSizeInUserSpace); }
void KexiDBImageBox::paintEvent(QPaintEvent *pe) { if (!m_paintEventEnabled) return; QPainter p(this); p.setClipRect(pe->rect()); const int _realLineWidth = realLineWidth(); KexiUtils::WidgetMargins margins(this); margins += KexiUtils::WidgetMargins(_realLineWidth); //Qt3 replaced with 'margins': const int m = realLineWidth() + margin(); const QBrush bgBrush(palette().brush(backgroundRole())); if (designMode() && pixmap().isNull()) { QRect r( QPoint(margins.left, margins.top), size() - QSize(margins.left + margins.right, margins.top + margins.bottom)); // p.fillRect(0, 0, width(), height(), bgBrush); updatePixmap(); QPixmap *imagBoxPm = scaledImageBoxIcon(margins, size()); if (imagBoxPm) { // QImage img(imagBoxPm->toImage()); // QPixmap converted(QPixmap::fromImage(img)); p.drawPixmap(2, height() - margins.top - margins.bottom - imagBoxPm->height() - 2, *imagBoxPm); } QFont f(qApp->font()); p.setFont(f); // p.setPen(KexiUtils::contrastColor(bg)); QString text; if (dataSource().isEmpty()) { text = objectName() + "\n" + i18nc("Unbound Image Box", "(unbound)"); } else { text = dataSource(); const QFontMetrics fm(fontMetrics()); const QPixmap dataSourceTagIcon(KexiFormUtils::dataSourceTagIcon()); if (width() >= (dataSourceTagIcon.width() + 2 + fm.boundingRect(r, Qt::AlignCenter, text).width())) { r.setLeft( r.left() + dataSourceTagIcon.width() + 2 ); // make some room for the [>] icon QRect bounding = fm.boundingRect(r, Qt::AlignCenter, text); p.drawPixmap( bounding.left() - dataSourceTagIcon.width() - 2, bounding.top() + bounding.height() / 2 - dataSourceTagIcon.height() / 2, dataSourceTagIcon); } } p.drawText(r, Qt::AlignCenter, text); } else { QSize internalSize(size()); if (m_chooser && m_dropDownButtonVisible && !dataSource().isEmpty()) internalSize.setWidth(internalSize.width() - m_chooser->width()); //clearing needed here because we may need to draw a pixmap with transparency // p.fillRect(0, 0, width(), height(), bgBrush); const QRect internalRect(QPoint(0, 0), internalSize); if (m_currentScaledPixmap.isNull() || internalRect != m_currentRect) { m_currentRect = internalRect; m_currentPixmapPos = QPoint(0, 0); m_currentScaledPixmap = KexiUtils::scaledPixmap( margins, m_currentRect, pixmap(), m_currentPixmapPos, m_alignment, m_scaledContents, m_keepAspectRatio, m_smoothTransformation ? Qt::SmoothTransformation : Qt::FastTransformation); } p.drawPixmap(m_currentPixmapPos, m_currentScaledPixmap); // KexiUtils::drawPixmap(p, margins, QRect(QPoint(0, 0), internalSize), pixmap(), m_alignment, // m_scaledContents, m_keepAspectRatio); } KexiFrame::drawFrame(&p); if (designMode()) { const bool hasFrame = frameWidth() >= 1 && frameShape() != QFrame::NoFrame; if (!hasFrame) { KFormDesigner::paintWidgetFrame(p, rect()); } } else { // data mode // if the widget is focused, draw focus indicator rect _if_ there is no chooser button if ( !dataSource().isEmpty() && hasFocus() && (!m_chooser || !m_chooser->isVisible())) { QStyleOptionFocusRect option; option.initFrom(this); //option.rect = style().subRect(QStyle::SR_PushButtonContents); style()->drawPrimitive( QStyle::PE_FrameFocusRect, &option, &p, this /*Qt4 , palette().active()*/); } } }
void SeqRep::initSequence(Randomness &rng) { rng.initArray(this->bv, internalSize()); }