277 int quality = inQuality;
284 if (!scaledClipRect.
isEmpty()) {
287 clipRect = scaledClipRect;
288 scaledClipRect =
QRect();
289 }
else if (scaledSize.
isEmpty()) {
293 scaledClipRect =
QRect();
294 }
else if (clipRect.
isEmpty()) {
297 if ((
info->image_width % scaledSize.
width()) == 0 &&
298 (
info->image_height % scaledSize.
height()) == 0) {
299 int x = scaledClipRect.
x() *
info->image_width /
301 int y = scaledClipRect.
y() *
info->image_height /
303 int width = (scaledClipRect.
right() + 1) *
304 info->image_width / scaledSize.
width() - x;
305 int height = (scaledClipRect.
bottom() + 1) *
307 clipRect =
QRect(x, y, width, height);
308 scaledSize = scaledClipRect.
size();
309 scaledClipRect =
QRect();
328 if (
info->scale_denom < 2) {
329 info->scale_denom = 1;
330 }
else if (
info->scale_denom < 4) {
331 info->scale_denom = 2;
332 }
else if (
info->scale_denom < 8) {
333 info->scale_denom = 4;
335 info->scale_denom = 8;
342 while (
info->scale_denom > 1 &&
343 ((clipRect.
x() %
info->scale_denom) != 0 ||
344 (clipRect.
y() %
info->scale_denom) != 0 ||
345 (clipRect.
width() %
info->scale_denom) != 0 ||
346 (clipRect.
height() %
info->scale_denom) != 0)) {
347 info->scale_denom /= 2;
354 info->dct_method = JDCT_IFAST;
358 (void) jpeg_calc_output_dimensions(
info);
361 QRect imageRect(0, 0,
info->output_width,
info->output_height);
365 }
else if (
info->scale_denom ==
info->scale_num) {
370 clip =
QRect(clipRect.
x() / int(
info->scale_denom),
371 clipRect.
y() / int(
info->scale_denom),
372 clipRect.
width() / int(
info->scale_denom),
382 bool quickGray = (
info->output_components == 1 &&
391 JSAMPARRAY rows = (
info->mem->alloc_sarray)
392 ((j_common_ptr)
info, JPOOL_IMAGE,
393 info->output_width *
info->output_components, 1);
395 (void) jpeg_start_decompress(
info);
397 while (
info->output_scanline <
info->output_height) {
398 int y = int(
info->output_scanline) - clip.
y();
402 (void) jpeg_read_scanlines(
info, rows, 1);
407 if (
info->output_components == 3) {
408 uchar *in = rows[0] + clip.
x() * 3;
411 }
else if (
info->out_color_space == JCS_CMYK) {
413 uchar *in = rows[0] + clip.
x() * 4;
415 for (
int i = 0; i < clip.
width(); ++i) {
417 *out++ =
qRgb(k * in[0] / 255, k * in[1] / 255,
421 }
else if (
info->output_components == 1) {
424 rows[0] + clip.
x(), clip.
width());
429 (void) jpeg_start_decompress(
info);
430 while (
info->output_scanline <
info->output_height) {
432 (void) jpeg_read_scanlines(
info, &row, 1);
436 if (
info->output_scanline ==
info->output_height)
437 (void) jpeg_finish_decompress(
info);
439 if (
info->density_unit == 1) {
442 }
else if (
info->density_unit == 2) {
447 if (scaledSize.
isValid() && scaledSize != clip.
size()) {
452 *outImage = outImage->
copy(scaledClipRect);
453 return !outImage->
isNull();
#define HIGH_QUALITY_THRESHOLD
QImage copy(const QRect &rect=QRect()) const
Returns a sub-area of the image as a new image.
static mach_timebase_info_data_t info
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
bool isNull() const
Returns true if it is a null image, otherwise returns false.
int width() const
Returns the width of the rectangle.
QRect intersected(const QRect &other) const
Returns the intersection of this rectangle and the given rectangle.
int height() const
Returns the height of the rectangle.
int bottom() const
Returns the y-coordinate of the rectangle's bottom edge.
int width() const
Returns the width.
static bool ensureValidImage(QImage *dest, struct jpeg_decompress_struct *info, const QSize &size)
QSize size() const
Returns the size of the rectangle.
#define FALSE
Synonym for false.
void setDotsPerMeterY(int)
Sets the number of pixels that fit vertically in a physical meter, to y.
bool isEmpty() const
Returns true if the rectangle is empty, otherwise returns false.
QRgb qRgb(int r, int g, int b)
Returns the ARGB quadruplet (255, {r}, {g}, {b}).
int right() const
Returns the x-coordinate of the rectangle's right edge.
void setDotsPerMeterX(int)
Sets the number of pixels that fit horizontally in a physical meter, to x.
int y() const
Returns the y-coordinate of the rectangle's top edge.
int x() const
Returns the x-coordinate of the rectangle's left edge.
int height() const
Returns the height.
The QRect class defines a rectangle in the plane using integer precision.
bool isValid() const
Returns true if both the width and height is equal to or greater than 0; otherwise returns false...
bool isEmpty() const
Returns true if either of the width and height is less than or equal to 0; otherwise returns false...
static Rgb888ToRgb32Converter rgb888ToRgb32ConverterPtr
QImage scaled(int w, int h, Qt::AspectRatioMode aspectMode=Qt::IgnoreAspectRatio, Qt::TransformationMode mode=Qt::FastTransformation) const
void translate(int dx, int dy)
Moves the rectangle dx along the x axis and dy along the y axis, relative to the current position...
uchar * scanLine(int)
Returns a pointer to the pixel data at the scanline with index i.
QPoint topLeft() const
Returns the position of the rectangle's top-left corner.