Qt 4.8
Classes | Functions
qwindowsurface_raster.cpp File Reference
#include <qdebug.h>
#include <qglobal.h>
#include <qlibrary.h>
#include <qt_windows.h>
#include <QtGui/qpaintdevice.h>
#include <QtGui/qwidget.h>
#include "private/qwindowsurface_raster_p.h"
#include "private/qnativeimage_p.h"
#include "private/qwidget_p.h"
#include "private/qpixmap_x11_p.h"
#include "private/qt_x11_p.h"
#include "qx11info_x11.h"
#include "private/qdrawhelper_p.h"
#include <private/qt_cocoa_helpers_mac_p.h>
#include <QMainWindow>
#include <private/qmainwindowlayout_p.h>
#include <QToolBar>

Go to the source code of this file.

Classes

class  QRasterWindowSurfacePrivate
 

Functions

void qt_scrollRectInImage (QImage &img, const QRect &rect, const QPoint &offset)
 

Function Documentation

◆ qt_scrollRectInImage()

void qt_scrollRectInImage ( QImage img,
const QRect rect,
const QPoint offset 
)

Definition at line 345 of file qwindowsurface.cpp.

Referenced by QRasterWindowSurface::scroll(), and QRasterWindowSurface::setGeometry().

346 {
347  // make sure we don't detach
348  uchar *mem = const_cast<uchar*>(const_cast<const QImage &>(img).bits());
349 
350  int lineskip = img.bytesPerLine();
351  int depth = img.depth() >> 3;
352 
353  const QRect imageRect(0, 0, img.width(), img.height());
354  const QRect r = rect & imageRect & imageRect.translated(-offset);
355  const QPoint p = rect.topLeft() + offset;
356 
357  if (r.isEmpty())
358  return;
359 
360  const uchar *src;
361  uchar *dest;
362 
363  if (r.top() < p.y()) {
364  src = mem + r.bottom() * lineskip + r.left() * depth;
365  dest = mem + (p.y() + r.height() - 1) * lineskip + p.x() * depth;
366  lineskip = -lineskip;
367  } else {
368  src = mem + r.top() * lineskip + r.left() * depth;
369  dest = mem + p.y() * lineskip + p.x() * depth;
370  }
371 
372  const int w = r.width();
373  int h = r.height();
374  const int bytes = w * depth;
375 
376  // overlapping segments?
377  if (offset.y() == 0 && qAbs(offset.x()) < w) {
378  do {
379  ::memmove(dest, src, bytes);
380  dest += lineskip;
381  src += lineskip;
382  } while (--h);
383  } else {
384  do {
385  ::memcpy(dest, src, bytes);
386  dest += lineskip;
387  src += lineskip;
388  } while (--h);
389  }
390 }
QRect translated(int dx, int dy) const
Returns a copy of the rectangle that is translated dx along the x axis and dy along the y axis...
Definition: qrect.h:328
int bytesPerLine() const
Returns the number of bytes per image scanline.
Definition: qimage.cpp:1812
Q_DECL_CONSTEXPR T qAbs(const T &t)
Definition: qglobal.h:1201
unsigned char uchar
Definition: qglobal.h:994
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
int depth() const
Returns the depth of the image.
Definition: qimage.cpp:1620
int width() const
Returns the width of the image.
Definition: qimage.cpp:1557
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
int height() const
Returns the height of the image.
Definition: qimage.cpp:1572
int y() const
Returns the y coordinate of this point.
Definition: qpoint.h:131
int x() const
Returns the x coordinate of this point.
Definition: qpoint.h:128
QPoint topLeft() const
Returns the position of the rectangle&#39;s top-left corner.
Definition: qrect.h:288