private static QImage warpImage(QImage src, int warp, int sign) { int w = src.width(); int ppl = src.bytesPerLine() / 4; int srch = src.height(); int desth = srch + warp; QImage dest = new QImage(w, desth, QImage.Format.Format_ARGB32_Premultiplied); dest.fill(0); QNativePointer sbits = src.bits(); QNativePointer dbits = dest.bits(); sbits.setVerificationEnabled(false); dbits.setVerificationEnabled(false); double r = w / 2.0; int extra_offset = sign >= 0 ? 0 : warp; for (int x = 0; x < w; ++x) { int oset = (int) (((Math.sqrt(Math.abs(r * r - (x - r) * (x - r)))) * sign / r) * warp); for (int y = 0; y < srch; ++y) { int p = sbits.intAt(y * ppl + x); dbits.setIntAt(((y + oset + extra_offset) * ppl) + x, p); } } return dest; }
@Override protected void resizeEvent(QResizeEvent event) { if (width() > image.width() || height() > image.height()) { int newWidth = Math.max(width() + 128, image.width()); int newHeight = Math.max(height() + 128, image.height()); image = resizeImage(image, new QSize(newWidth, newHeight)); update(); } super.resizeEvent(event); }
public SmokeEffect(int width, int height) { m_width = width; m_height = height; m_seeds = new int[16000]; for (int i = 0; i < m_seeds.length; ++i) { double d = Math.random(); m_seeds[i] = (int) (d * 255); } m_image = new QImage(width, height, QImage.Format.Format_ARGB32_Premultiplied); m_image.fill(0); m_data = new int[m_width * (m_height + 1)]; seedLastRow(); }