SpriteImagePtr createSpriteImage(const PremultipliedImage& image, const uint16_t srcX, const uint16_t srcY, const uint16_t width, const uint16_t height, const double ratio, const bool sdf) { // Disallow invalid parameter configurations. if (width <= 0 || height <= 0 || width > 1024 || height > 1024 || ratio <= 0 || ratio > 10 || srcX + width > image.width || srcY + height > image.height) { Log::Error(Event::Sprite, "Can't create sprite with invalid metrics"); return nullptr; } PremultipliedImage dstImage(width, height); auto srcData = reinterpret_cast<const uint32_t*>(image.data.get()); auto dstData = reinterpret_cast<uint32_t*>(dstImage.data.get()); // Copy from the source image into our individual sprite image for (uint16_t y = 0; y < height; ++y) { const auto dstRow = y * width; const auto srcRow = (y + srcY) * image.width + srcX; for (uint16_t x = 0; x < width; ++x) { dstData[dstRow + x] = srcData[srcRow + x]; } } return std::make_unique<const SpriteImage>(std::move(dstImage), ratio, sdf); }
std::unique_ptr<style::Image> createStyleImage(const std::string& id, const PremultipliedImage& image, const uint32_t srcX, const uint32_t srcY, const uint32_t width, const uint32_t height, const double ratio, const bool sdf) { // Disallow invalid parameter configurations. if (width <= 0 || height <= 0 || width > 1024 || height > 1024 || ratio <= 0 || ratio > 10 || srcX >= image.size.width || srcY >= image.size.height || srcX + width > image.size.width || srcY + height > image.size.height) { Log::Error(Event::Sprite, "Can't create sprite with invalid metrics: %ux%u@%u,%u in %ux%u@%sx sprite", width, height, srcX, srcY, image.size.width, image.size.height, util::toString(ratio).c_str()); return nullptr; } PremultipliedImage dstImage({ width, height }); // Copy from the source image into our individual sprite image PremultipliedImage::copy(image, dstImage, { srcX, srcY }, { 0, 0 }, { width, height }); return std::make_unique<style::Image>(id, std::move(dstImage), ratio, sdf); }
void KisGradientPainterTest::testSplitDisjointPaths() { QPainterPath path; // small bug: the smaller rect is also merged path.addRect(QRectF(323, 123, 4, 4)); path.addRect(QRectF(300, 100, 50, 50)); path.addRect(QRectF(320, 120, 10, 10)); path.addRect(QRectF(200, 100, 50, 50)); path.addRect(QRectF(240, 120, 70, 10)); path.addRect(QRectF(100, 100, 50, 50)); path.addRect(QRectF(120, 120, 10, 10)); path = path.simplified(); { QImage srcImage(450, 250, QImage::Format_ARGB32); srcImage.fill(0); QPainter gc(&srcImage); gc.fillPath(path, Qt::red); //srcImage.save("src_disjoint_paths.png"); } QList<QPainterPath> result = KritaUtils::splitDisjointPaths(path); { QImage dstImage(450, 250, QImage::Format_ARGB32); dstImage.fill(0); QPainter gc(&dstImage); QVector<QBrush> brushes; brushes << Qt::red; brushes << Qt::green; brushes << Qt::blue; brushes << Qt::cyan; brushes << Qt::magenta; brushes << Qt::yellow; brushes << Qt::black; brushes << Qt::white; int index = 0; Q_FOREACH (const QPainterPath &p, result) { gc.fillPath(p, brushes[index]); index = (index + 1) % brushes.size(); } TestUtil::checkQImageExternal(dstImage, "shaped_gradient", "test", "disjoint_paths"); }
void GuiApplicationManagerPrivate::createColorPickerCursor() { QImage originalImage; originalImage.load( QString::fromUtf8(NATRON_IMAGES_PATH "color_picker.png") ); originalImage = originalImage.scaled(16, 16); QImage dstImage(32, 32, QImage::Format_ARGB32); dstImage.fill( QColor(0, 0, 0, 0) ); int oW = originalImage.width(); int oH = originalImage.height(); for (int y = 0; y < oH; ++y) { for (int x = 0; x < oW; ++x) { dstImage.setPixel( x + oW, y, originalImage.pixel(x, y) ); } } QPixmap pix = QPixmap::fromImage(dstImage); _colorPickerCursor = QCursor(pix); }