Qt 4.8
Classes | Namespaces | Macros | Typedefs | Functions | Variables
qimagescale.cpp File Reference
#include <private/qimagescale_p.h>
#include <private/qdrawhelper_p.h>
#include "qimage.h"
#include "qcolor.h"

Go to the source code of this file.

Classes

struct  QImageScale::QImageScaleInfo
 

Namespaces

 QImageScale
 

Macros

#define A_VAL(p)   (qAlpha(*p))
 
#define B_VAL(p)   (qBlue(*p))
 
#define G_VAL(p)   (qGreen(*p))
 
#define INV_XAP   (256 - xapoints[x])
 
#define INV_YAP   (256 - yapoints[dyy + y])
 
#define R_VAL(p)   (qRed(*p))
 
#define XAP   (xapoints[x])
 
#define YAP   (yapoints[dyy + y])
 

Typedefs

typedef void(* qt_qimageScaleFunc) (QImageScale::QImageScaleInfo *isi, unsigned int *dest, int dxx, int dyy, int dx, int dy, int dw, int dh, int dow, int sow)
 

Functions

int * QImageScale::qimageCalcApoints (int s, int d, int up)
 
QImageScaleInfoQImageScale::qimageCalcScaleInfo (const QImage &img, int sw, int sh, int dw, int dh, char aa)
 
int * QImageScale::qimageCalcXPoints (int sw, int dw)
 
unsigned int ** QImageScale::qimageCalcYPoints (unsigned int *src, int sw, int sh, int dh)
 
QImageScaleInfoQImageScale::qimageFreeScaleInfo (QImageScaleInfo *isi)
 
QImage qSmoothScaleImage (const QImage &src, int dw, int dh)
 
static void qt_qimageScaleAARGB (QImageScale::QImageScaleInfo *isi, unsigned int *dest, int dxx, int dyy, int dx, int dy, int dw, int dh, int dow, int sow)
 
static void qt_qimageScaleAARGBA (QImageScale::QImageScaleInfo *isi, unsigned int *dest, int dxx, int dyy, int dx, int dy, int dw, int dh, int dow, int sow)
 

Variables

qt_qimageScaleFunc qt_qimageScaleArgb = qt_qimageScaleAARGBA
 
qt_qimageScaleFunc qt_qimageScaleRgb = qt_qimageScaleAARGB
 

Macro Definition Documentation

◆ A_VAL

#define A_VAL (   p)    (qAlpha(*p))

Definition at line 140 of file qimagescale.cpp.

Referenced by qt_qimageScaleAARGBA().

◆ B_VAL

#define B_VAL (   p)    (qBlue(*p))

Definition at line 143 of file qimagescale.cpp.

Referenced by qt_qimageScaleAARGB(), and qt_qimageScaleAARGBA().

◆ G_VAL

#define G_VAL (   p)    (qGreen(*p))

Definition at line 142 of file qimagescale.cpp.

Referenced by qt_qimageScaleAARGB(), and qt_qimageScaleAARGBA().

◆ INV_XAP

#define INV_XAP   (256 - xapoints[x])

Definition at line 145 of file qimagescale.cpp.

Referenced by qt_qimageScaleAARGB(), and qt_qimageScaleAARGBA().

◆ INV_YAP

#define INV_YAP   (256 - yapoints[dyy + y])

Definition at line 147 of file qimagescale.cpp.

Referenced by qt_qimageScaleAARGB(), and qt_qimageScaleAARGBA().

◆ R_VAL

#define R_VAL (   p)    (qRed(*p))

Definition at line 141 of file qimagescale.cpp.

Referenced by qt_qimageScaleAARGB(), and qt_qimageScaleAARGBA().

◆ XAP

#define XAP   (xapoints[x])

Definition at line 146 of file qimagescale.cpp.

Referenced by qt_qimageScaleAARGB(), and qt_qimageScaleAARGBA().

◆ YAP

#define YAP   (yapoints[dyy + y])

Definition at line 148 of file qimagescale.cpp.

Referenced by qt_qimageScaleAARGB(), and qt_qimageScaleAARGBA().

Typedef Documentation

◆ qt_qimageScaleFunc

typedef void(* qt_qimageScaleFunc) (QImageScale::QImageScaleInfo *isi, unsigned int *dest, int dxx, int dyy, int dx, int dy, int dw, int dh, int dow, int sow)

Definition at line 53 of file qimagescale.cpp.

Function Documentation

◆ qSmoothScaleImage()

QImage qSmoothScaleImage ( const QImage src,
int  dw,
int  dh 
)

Definition at line 1000 of file qimagescale.cpp.

Referenced by smoothScaled().

1001 {
1002  QImage buffer;
1003  if (src.isNull() || dw <= 0 || dh <= 0)
1004  return buffer;
1005 
1006  int w = src.width();
1007  int h = src.height();
1008  QImageScaleInfo *scaleinfo =
1009  qimageCalcScaleInfo(src, w, h, dw, dh, true);
1010  if (!scaleinfo)
1011  return buffer;
1012 
1013  buffer = QImage(dw, dh, src.format());
1014  if (buffer.isNull()) {
1015  qWarning("QImage: out of memory, returning null");
1016  qimageFreeScaleInfo(scaleinfo);
1017  return QImage();
1018  }
1019 
1021  qt_qimageScaleArgb(scaleinfo, (unsigned int *)buffer.scanLine(0),
1022  0, 0, 0, 0, dw, dh, dw, src.bytesPerLine() / 4);
1023  else
1024  qt_qimageScaleRgb(scaleinfo, (unsigned int *)buffer.scanLine(0),
1025  0, 0, 0, 0, dw, dh, dw, src.bytesPerLine() / 4);
1026 
1027  qimageFreeScaleInfo(scaleinfo);
1028  return buffer;
1029 }
QImageScaleInfo * qimageFreeScaleInfo(QImageScaleInfo *isi)
qt_qimageScaleFunc qt_qimageScaleArgb
Definition: qimagescale.cpp:65
bool isNull() const
Returns true if it is a null image, otherwise returns false.
Definition: qimage.cpp:1542
int bytesPerLine() const
Returns the number of bytes per image scanline.
Definition: qimage.cpp:1812
qt_qimageScaleFunc qt_qimageScaleRgb
Definition: qimagescale.cpp:66
Format format() const
Returns the format of the image.
Definition: qimage.cpp:2305
Q_CORE_EXPORT void qWarning(const char *,...)
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
int width() const
Returns the width of the image.
Definition: qimage.cpp:1557
int height() const
Returns the height of the image.
Definition: qimage.cpp:1572
QImageScaleInfo * qimageCalcScaleInfo(const QImage &img, int sw, int sh, int dw, int dh, char aa)
uchar * scanLine(int)
Returns a pointer to the pixel data at the scanline with index i.
Definition: qimage.cpp:1886

◆ qt_qimageScaleAARGB()

static void qt_qimageScaleAARGB ( QImageScale::QImageScaleInfo isi,
unsigned int *  dest,
int  dxx,
int  dyy,
int  dx,
int  dy,
int  dw,
int  dh,
int  dow,
int  sow 
)
static

Definition at line 669 of file qimagescale.cpp.

672 {
673  unsigned int *sptr, *dptr;
674  int x, y, end;
675  unsigned int **ypoints = isi->ypoints;
676  int *xpoints = isi->xpoints;
677  int *xapoints = isi->xapoints;
678  int *yapoints = isi->yapoints;
679 
680  end = dxx + dw;
681  /* scaling up both ways */
682  if(isi->xup_yup == 3){
683  /* go through every scanline in the output buffer */
684  for(y = 0; y < dh; y++){
685  /* calculate the source line we'll scan from */
686  dptr = dest + dx + ((y + dy) * dow);
687  sptr = ypoints[dyy + y];
688  if(YAP > 0){
689  for(x = dxx; x < end; x++){
690  int r = 0, g = 0, b = 0;
691  int rr = 0, gg = 0, bb = 0;
692  unsigned int *pix;
693 
694  if(XAP > 0){
695  pix = ypoints[dyy + y] + xpoints[x];
696  r = R_VAL(pix) * INV_XAP;
697  g = G_VAL(pix) * INV_XAP;
698  b = B_VAL(pix) * INV_XAP;
699  pix++;
700  r += R_VAL(pix) * XAP;
701  g += G_VAL(pix) * XAP;
702  b += B_VAL(pix) * XAP;
703  pix += sow;
704  rr = R_VAL(pix) * XAP;
705  gg = G_VAL(pix) * XAP;
706  bb = B_VAL(pix) * XAP;
707  pix --;
708  rr += R_VAL(pix) * INV_XAP;
709  gg += G_VAL(pix) * INV_XAP;
710  bb += B_VAL(pix) * INV_XAP;
711  r = ((rr * YAP) + (r * INV_YAP)) >> 16;
712  g = ((gg * YAP) + (g * INV_YAP)) >> 16;
713  b = ((bb * YAP) + (b * INV_YAP)) >> 16;
714  *dptr++ = qRgba(r, g, b, 0xff);
715  }
716  else{
717  pix = ypoints[dyy + y] + xpoints[x];
718  r = R_VAL(pix) * INV_YAP;
719  g = G_VAL(pix) * INV_YAP;
720  b = B_VAL(pix) * INV_YAP;
721  pix += sow;
722  r += R_VAL(pix) * YAP;
723  g += G_VAL(pix) * YAP;
724  b += B_VAL(pix) * YAP;
725  r >>= 8;
726  g >>= 8;
727  b >>= 8;
728  *dptr++ = qRgba(r, g, b, 0xff);
729  }
730  }
731  }
732  else{
733  for(x = dxx; x < end; x++){
734  int r = 0, g = 0, b = 0;
735  unsigned int *pix;
736 
737  if(XAP > 0){
738  pix = ypoints[dyy + y] + xpoints[x];
739  r = R_VAL(pix) * INV_XAP;
740  g = G_VAL(pix) * INV_XAP;
741  b = B_VAL(pix) * INV_XAP;
742  pix++;
743  r += R_VAL(pix) * XAP;
744  g += G_VAL(pix) * XAP;
745  b += B_VAL(pix) * XAP;
746  r >>= 8;
747  g >>= 8;
748  b >>= 8;
749  *dptr++ = qRgba(r, g, b, 0xff);
750  }
751  else
752  *dptr++ = sptr[xpoints[x] ];
753  }
754  }
755  }
756  }
757  /* if we're scaling down vertically */
758  else if(isi->xup_yup == 1){
759  /*\ 'Correct' version, with math units prepared for MMXification \*/
760  int Cy, j;
761  unsigned int *pix;
762  int r, g, b, rr, gg, bb;
763  int yap;
764 
765  /* go through every scanline in the output buffer */
766  for(y = 0; y < dh; y++){
767  Cy = YAP >> 16;
768  yap = YAP & 0xffff;
769 
770  dptr = dest + dx + ((y + dy) * dow);
771  for(x = dxx; x < end; x++){
772  pix = ypoints[dyy + y] + xpoints[x];
773  r = R_VAL(pix) * yap;
774  g = G_VAL(pix) * yap;
775  b = B_VAL(pix) * yap;
776  pix += sow;
777  for(j = (1 << 14) - yap; j > Cy; j -= Cy){
778  r += R_VAL(pix) * Cy;
779  g += G_VAL(pix) * Cy;
780  b += B_VAL(pix) * Cy;
781  pix += sow;
782  }
783  if(j > 0){
784  r += R_VAL(pix) * j;
785  g += G_VAL(pix) * j;
786  b += B_VAL(pix) * j;
787  }
788  if(XAP > 0){
789  pix = ypoints[dyy + y] + xpoints[x] + 1;
790  rr = R_VAL(pix) * yap;
791  gg = G_VAL(pix) * yap;
792  bb = B_VAL(pix) * yap;
793  pix += sow;
794  for(j = (1 << 14) - yap; j > Cy; j -= Cy){
795  rr += R_VAL(pix) * Cy;
796  gg += G_VAL(pix) * Cy;
797  bb += B_VAL(pix) * Cy;
798  pix += sow;
799  }
800  if(j > 0){
801  rr += R_VAL(pix) * j;
802  gg += G_VAL(pix) * j;
803  bb += B_VAL(pix) * j;
804  }
805  r = r * INV_XAP;
806  g = g * INV_XAP;
807  b = b * INV_XAP;
808  r = (r + ((rr * XAP))) >> 12;
809  g = (g + ((gg * XAP))) >> 12;
810  b = (b + ((bb * XAP))) >> 12;
811  }
812  else{
813  r >>= 4;
814  g >>= 4;
815  b >>= 4;
816  }
817  *dptr = qRgba(r >> 10, g >> 10, b >> 10, 0xff);
818  dptr++;
819  }
820  }
821  }
822  /* if we're scaling down horizontally */
823  else if(isi->xup_yup == 2){
824  /*\ 'Correct' version, with math units prepared for MMXification \*/
825  int Cx, j;
826  unsigned int *pix;
827  int r, g, b, rr, gg, bb;
828  int xap;
829 
830  /* go through every scanline in the output buffer */
831  for(y = 0; y < dh; y++){
832  dptr = dest + dx + ((y + dy) * dow);
833  for(x = dxx; x < end; x++){
834  Cx = XAP >> 16;
835  xap = XAP & 0xffff;
836 
837  pix = ypoints[dyy + y] + xpoints[x];
838  r = R_VAL(pix) * xap;
839  g = G_VAL(pix) * xap;
840  b = B_VAL(pix) * xap;
841  pix++;
842  for(j = (1 << 14) - xap; j > Cx; j -= Cx){
843  r += R_VAL(pix) * Cx;
844  g += G_VAL(pix) * Cx;
845  b += B_VAL(pix) * Cx;
846  pix++;
847  }
848  if(j > 0){
849  r += R_VAL(pix) * j;
850  g += G_VAL(pix) * j;
851  b += B_VAL(pix) * j;
852  }
853  if(YAP > 0){
854  pix = ypoints[dyy + y] + xpoints[x] + sow;
855  rr = R_VAL(pix) * xap;
856  gg = G_VAL(pix) * xap;
857  bb = B_VAL(pix) * xap;
858  pix++;
859  for(j = (1 << 14) - xap; j > Cx; j -= Cx){
860  rr += R_VAL(pix) * Cx;
861  gg += G_VAL(pix) * Cx;
862  bb += B_VAL(pix) * Cx;
863  pix++;
864  }
865  if(j > 0){
866  rr += R_VAL(pix) * j;
867  gg += G_VAL(pix) * j;
868  bb += B_VAL(pix) * j;
869  }
870  r = r * INV_YAP;
871  g = g * INV_YAP;
872  b = b * INV_YAP;
873  r = (r + ((rr * YAP))) >> 12;
874  g = (g + ((gg * YAP))) >> 12;
875  b = (b + ((bb * YAP))) >> 12;
876  }
877  else{
878  r >>= 4;
879  g >>= 4;
880  b >>= 4;
881  }
882  *dptr = qRgba(r >> 10, g >> 10, b >> 10, 0xff);
883  dptr++;
884  }
885  }
886  }
887  /* fully optimized (i think) - onyl change of algorithm can help */
888  /* if we're scaling down horizontally & vertically */
889  else{
890  /*\ 'Correct' version, with math units prepared for MMXification \*/
891  int Cx, Cy, i, j;
892  unsigned int *pix;
893  int r, g, b, rx, gx, bx;
894  int xap, yap;
895 
896  for(y = 0; y < dh; y++){
897  Cy = YAP >> 16;
898  yap = YAP & 0xffff;
899 
900  dptr = dest + dx + ((y + dy) * dow);
901  for(x = dxx; x < end; x++){
902  Cx = XAP >> 16;
903  xap = XAP & 0xffff;
904 
905  sptr = ypoints[dyy + y] + xpoints[x];
906  pix = sptr;
907  sptr += sow;
908  rx = R_VAL(pix) * xap;
909  gx = G_VAL(pix) * xap;
910  bx = B_VAL(pix) * xap;
911  pix++;
912  for(i = (1 << 14) - xap; i > Cx; i -= Cx){
913  rx += R_VAL(pix) * Cx;
914  gx += G_VAL(pix) * Cx;
915  bx += B_VAL(pix) * Cx;
916  pix++;
917  }
918  if(i > 0){
919  rx += R_VAL(pix) * i;
920  gx += G_VAL(pix) * i;
921  bx += B_VAL(pix) * i;
922  }
923 
924  r = (rx >> 5) * yap;
925  g = (gx >> 5) * yap;
926  b = (bx >> 5) * yap;
927 
928  for(j = (1 << 14) - yap; j > Cy; j -= Cy){
929  pix = sptr;
930  sptr += sow;
931  rx = R_VAL(pix) * xap;
932  gx = G_VAL(pix) * xap;
933  bx = B_VAL(pix) * xap;
934  pix++;
935  for(i = (1 << 14) - xap; i > Cx; i -= Cx){
936  rx += R_VAL(pix) * Cx;
937  gx += G_VAL(pix) * Cx;
938  bx += B_VAL(pix) * Cx;
939  pix++;
940  }
941  if(i > 0){
942  rx += R_VAL(pix) * i;
943  gx += G_VAL(pix) * i;
944  bx += B_VAL(pix) * i;
945  }
946 
947  r += (rx >> 5) * Cy;
948  g += (gx >> 5) * Cy;
949  b += (bx >> 5) * Cy;
950  }
951  if(j > 0){
952  pix = sptr;
953  sptr += sow;
954  rx = R_VAL(pix) * xap;
955  gx = G_VAL(pix) * xap;
956  bx = B_VAL(pix) * xap;
957  pix++;
958  for(i = (1 << 14) - xap; i > Cx; i -= Cx){
959  rx += R_VAL(pix) * Cx;
960  gx += G_VAL(pix) * Cx;
961  bx += B_VAL(pix) * Cx;
962  pix++;
963  }
964  if(i > 0){
965  rx += R_VAL(pix) * i;
966  gx += G_VAL(pix) * i;
967  bx += B_VAL(pix) * i;
968  }
969 
970  r += (rx >> 5) * j;
971  g += (gx >> 5) * j;
972  b += (bx >> 5) * j;
973  }
974 
975  *dptr = qRgb(r >> 23, g >> 23, b >> 23);
976  dptr++;
977  }
978  }
979  }
980 }
#define B_VAL(p)
#define INV_YAP
#define G_VAL(p)
#define INV_XAP
QRgb qRgb(int r, int g, int b)
Returns the ARGB quadruplet (255, {r}, {g}, {b}).
Definition: qrgb.h:69
#define YAP
static const KeyPair *const end
#define XAP
QRgb qRgba(int r, int g, int b, int a)
Returns the ARGB quadruplet ({a}, {r}, {g}, {b}).
Definition: qrgb.h:72
#define R_VAL(p)

◆ qt_qimageScaleAARGBA()

static void qt_qimageScaleAARGBA ( QImageScale::QImageScaleInfo isi,
unsigned int *  dest,
int  dxx,
int  dyy,
int  dx,
int  dy,
int  dw,
int  dh,
int  dow,
int  sow 
)
static

Definition at line 310 of file qimagescale.cpp.

Referenced by qt_qimageScaleAARGB().

313 {
314  unsigned int *sptr, *dptr;
315  int x, y, end;
316  unsigned int **ypoints = isi->ypoints;
317  int *xpoints = isi->xpoints;
318  int *xapoints = isi->xapoints;
319  int *yapoints = isi->yapoints;
320 
321  end = dxx + dw;
322  /* scaling up both ways */
323  if(isi->xup_yup == 3){
324  /* go through every scanline in the output buffer */
325  for(y = 0; y < dh; y++){
326  /* calculate the source line we'll scan from */
327  dptr = dest + dx + ((y + dy) * dow);
328  sptr = ypoints[dyy + y];
329  if(YAP > 0){
330  for(x = dxx; x < end; x++){
331  int r, g, b, a;
332  int rr, gg, bb, aa;
333  unsigned int *pix;
334 
335  if(XAP > 0){
336  pix = ypoints[dyy + y] + xpoints[x];
337  r = R_VAL(pix) * INV_XAP;
338  g = G_VAL(pix) * INV_XAP;
339  b = B_VAL(pix) * INV_XAP;
340  a = A_VAL(pix) * INV_XAP;
341  pix++;
342  r += R_VAL(pix) * XAP;
343  g += G_VAL(pix) * XAP;
344  b += B_VAL(pix) * XAP;
345  a += A_VAL(pix) * XAP;
346  pix += sow;
347  rr = R_VAL(pix) * XAP;
348  gg = G_VAL(pix) * XAP;
349  bb = B_VAL(pix) * XAP;
350  aa = A_VAL(pix) * XAP;
351  pix--;
352  rr += R_VAL(pix) * INV_XAP;
353  gg += G_VAL(pix) * INV_XAP;
354  bb += B_VAL(pix) * INV_XAP;
355  aa += A_VAL(pix) * INV_XAP;
356  r = ((rr * YAP) + (r * INV_YAP)) >> 16;
357  g = ((gg * YAP) + (g * INV_YAP)) >> 16;
358  b = ((bb * YAP) + (b * INV_YAP)) >> 16;
359  a = ((aa * YAP) + (a * INV_YAP)) >> 16;
360  *dptr++ = qRgba(r, g, b, a);
361  }
362  else{
363  pix = ypoints[dyy + y] + xpoints[x];
364  r = R_VAL(pix) * INV_YAP;
365  g = G_VAL(pix) * INV_YAP;
366  b = B_VAL(pix) * INV_YAP;
367  a = A_VAL(pix) * INV_YAP;
368  pix += sow;
369  r += R_VAL(pix) * YAP;
370  g += G_VAL(pix) * YAP;
371  b += B_VAL(pix) * YAP;
372  a += A_VAL(pix) * YAP;
373  r >>= 8;
374  g >>= 8;
375  b >>= 8;
376  a >>= 8;
377  *dptr++ = qRgba(r, g, b, a);
378  }
379  }
380  }
381  else{
382  for(x = dxx; x < end; x++){
383  int r, g, b, a;
384  unsigned int *pix;
385 
386  if(XAP > 0){
387  pix = ypoints[dyy + y] + xpoints[x];
388  r = R_VAL(pix) * INV_XAP;
389  g = G_VAL(pix) * INV_XAP;
390  b = B_VAL(pix) * INV_XAP;
391  a = A_VAL(pix) * INV_XAP;
392  pix++;
393  r += R_VAL(pix) * XAP;
394  g += G_VAL(pix) * XAP;
395  b += B_VAL(pix) * XAP;
396  a += A_VAL(pix) * XAP;
397  r >>= 8;
398  g >>= 8;
399  b >>= 8;
400  a >>= 8;
401  *dptr++ = qRgba(r, g, b, a);
402  }
403  else
404  *dptr++ = sptr[xpoints[x] ];
405  }
406  }
407  }
408  }
409  /* if we're scaling down vertically */
410  else if(isi->xup_yup == 1){
411  /*\ 'Correct' version, with math units prepared for MMXification \*/
412  int Cy, j;
413  unsigned int *pix;
414  int r, g, b, a, rr, gg, bb, aa;
415  int yap;
416 
417  /* go through every scanline in the output buffer */
418  for(y = 0; y < dh; y++){
419  Cy = YAP >> 16;
420  yap = YAP & 0xffff;
421 
422  dptr = dest + dx + ((y + dy) * dow);
423  for(x = dxx; x < end; x++){
424  pix = ypoints[dyy + y] + xpoints[x];
425  r = R_VAL(pix) * yap;
426  g = G_VAL(pix) * yap;
427  b = B_VAL(pix) * yap;
428  a = A_VAL(pix) * yap;
429  for(j = (1 << 14) - yap; j > Cy; j -= Cy){
430  pix += sow;
431  r += R_VAL(pix) * Cy;
432  g += G_VAL(pix) * Cy;
433  b += B_VAL(pix) * Cy;
434  a += A_VAL(pix) * Cy;
435  }
436  if(j > 0){
437  pix += sow;
438  r += R_VAL(pix) * j;
439  g += G_VAL(pix) * j;
440  b += B_VAL(pix) * j;
441  a += A_VAL(pix) * j;
442  }
443  if(XAP > 0){
444  pix = ypoints[dyy + y] + xpoints[x] + 1;
445  rr = R_VAL(pix) * yap;
446  gg = G_VAL(pix) * yap;
447  bb = B_VAL(pix) * yap;
448  aa = A_VAL(pix) * yap;
449  for(j = (1 << 14) - yap; j > Cy; j -= Cy){
450  pix += sow;
451  rr += R_VAL(pix) * Cy;
452  gg += G_VAL(pix) * Cy;
453  bb += B_VAL(pix) * Cy;
454  aa += A_VAL(pix) * Cy;
455  }
456  if(j > 0){
457  pix += sow;
458  rr += R_VAL(pix) * j;
459  gg += G_VAL(pix) * j;
460  bb += B_VAL(pix) * j;
461  aa += A_VAL(pix) * j;
462  }
463  r = r * INV_XAP;
464  g = g * INV_XAP;
465  b = b * INV_XAP;
466  a = a * INV_XAP;
467  r = (r + ((rr * XAP))) >> 12;
468  g = (g + ((gg * XAP))) >> 12;
469  b = (b + ((bb * XAP))) >> 12;
470  a = (a + ((aa * XAP))) >> 12;
471  }
472  else{
473  r >>= 4;
474  g >>= 4;
475  b >>= 4;
476  a >>= 4;
477  }
478  *dptr = qRgba(r >> 10, g >> 10, b >> 10, a >> 10);
479  dptr++;
480  }
481  }
482  }
483  /* if we're scaling down horizontally */
484  else if(isi->xup_yup == 2){
485  /*\ 'Correct' version, with math units prepared for MMXification \*/
486  int Cx, j;
487  unsigned int *pix;
488  int r, g, b, a, rr, gg, bb, aa;
489  int xap;
490 
491  /* go through every scanline in the output buffer */
492  for(y = 0; y < dh; y++){
493  dptr = dest + dx + ((y + dy) * dow);
494  for(x = dxx; x < end; x++){
495  Cx = XAP >> 16;
496  xap = XAP & 0xffff;
497 
498  pix = ypoints[dyy + y] + xpoints[x];
499  r = R_VAL(pix) * xap;
500  g = G_VAL(pix) * xap;
501  b = B_VAL(pix) * xap;
502  a = A_VAL(pix) * xap;
503  for(j = (1 << 14) - xap; j > Cx; j -= Cx){
504  pix++;
505  r += R_VAL(pix) * Cx;
506  g += G_VAL(pix) * Cx;
507  b += B_VAL(pix) * Cx;
508  a += A_VAL(pix) * Cx;
509  }
510  if(j > 0){
511  pix++;
512  r += R_VAL(pix) * j;
513  g += G_VAL(pix) * j;
514  b += B_VAL(pix) * j;
515  a += A_VAL(pix) * j;
516  }
517  if(YAP > 0){
518  pix = ypoints[dyy + y] + xpoints[x] + sow;
519  rr = R_VAL(pix) * xap;
520  gg = G_VAL(pix) * xap;
521  bb = B_VAL(pix) * xap;
522  aa = A_VAL(pix) * xap;
523  for(j = (1 << 14) - xap; j > Cx; j -= Cx){
524  pix++;
525  rr += R_VAL(pix) * Cx;
526  gg += G_VAL(pix) * Cx;
527  bb += B_VAL(pix) * Cx;
528  aa += A_VAL(pix) * Cx;
529  }
530  if(j > 0){
531  pix++;
532  rr += R_VAL(pix) * j;
533  gg += G_VAL(pix) * j;
534  bb += B_VAL(pix) * j;
535  aa += A_VAL(pix) * j;
536  }
537  r = r * INV_YAP;
538  g = g * INV_YAP;
539  b = b * INV_YAP;
540  a = a * INV_YAP;
541  r = (r + ((rr * YAP))) >> 12;
542  g = (g + ((gg * YAP))) >> 12;
543  b = (b + ((bb * YAP))) >> 12;
544  a = (a + ((aa * YAP))) >> 12;
545  }
546  else{
547  r >>= 4;
548  g >>= 4;
549  b >>= 4;
550  a >>= 4;
551  }
552  *dptr = qRgba(r >> 10, g >> 10, b >> 10, a >> 10);
553  dptr++;
554  }
555  }
556  }
557  /* if we're scaling down horizontally & vertically */
558  else{
559  /*\ 'Correct' version, with math units prepared for MMXification:
560  |*| The operation 'b = (b * c) >> 16' translates to pmulhw,
561  |*| so the operation 'b = (b * c) >> d' would translate to
562  |*| psllw (16 - d), %mmb; pmulh %mmc, %mmb
563  \*/
564  int Cx, Cy, i, j;
565  unsigned int *pix;
566  int a, r, g, b, ax, rx, gx, bx;
567  int xap, yap;
568 
569  for(y = 0; y < dh; y++){
570  Cy = YAP >> 16;
571  yap = YAP & 0xffff;
572 
573  dptr = dest + dx + ((y + dy) * dow);
574  for(x = dxx; x < end; x++){
575  Cx = XAP >> 16;
576  xap = XAP & 0xffff;
577 
578  sptr = ypoints[dyy + y] + xpoints[x];
579  pix = sptr;
580  sptr += sow;
581  rx = R_VAL(pix) * xap;
582  gx = G_VAL(pix) * xap;
583  bx = B_VAL(pix) * xap;
584  ax = A_VAL(pix) * xap;
585 
586  pix++;
587  for(i = (1 << 14) - xap; i > Cx; i -= Cx){
588  rx += R_VAL(pix) * Cx;
589  gx += G_VAL(pix) * Cx;
590  bx += B_VAL(pix) * Cx;
591  ax += A_VAL(pix) * Cx;
592  pix++;
593  }
594  if(i > 0){
595  rx += R_VAL(pix) * i;
596  gx += G_VAL(pix) * i;
597  bx += B_VAL(pix) * i;
598  ax += A_VAL(pix) * i;
599  }
600 
601  r = (rx >> 5) * yap;
602  g = (gx >> 5) * yap;
603  b = (bx >> 5) * yap;
604  a = (ax >> 5) * yap;
605 
606  for(j = (1 << 14) - yap; j > Cy; j -= Cy){
607  pix = sptr;
608  sptr += sow;
609  rx = R_VAL(pix) * xap;
610  gx = G_VAL(pix) * xap;
611  bx = B_VAL(pix) * xap;
612  ax = A_VAL(pix) * xap;
613  pix++;
614  for(i = (1 << 14) - xap; i > Cx; i -= Cx){
615  rx += R_VAL(pix) * Cx;
616  gx += G_VAL(pix) * Cx;
617  bx += B_VAL(pix) * Cx;
618  ax += A_VAL(pix) * Cx;
619  pix++;
620  }
621  if(i > 0){
622  rx += R_VAL(pix) * i;
623  gx += G_VAL(pix) * i;
624  bx += B_VAL(pix) * i;
625  ax += A_VAL(pix) * i;
626  }
627 
628  r += (rx >> 5) * Cy;
629  g += (gx >> 5) * Cy;
630  b += (bx >> 5) * Cy;
631  a += (ax >> 5) * Cy;
632  }
633  if(j > 0){
634  pix = sptr;
635  sptr += sow;
636  rx = R_VAL(pix) * xap;
637  gx = G_VAL(pix) * xap;
638  bx = B_VAL(pix) * xap;
639  ax = A_VAL(pix) * xap;
640  pix++;
641  for(i = (1 << 14) - xap; i > Cx; i -= Cx){
642  rx += R_VAL(pix) * Cx;
643  gx += G_VAL(pix) * Cx;
644  bx += B_VAL(pix) * Cx;
645  ax += A_VAL(pix) * Cx;
646  pix++;
647  }
648  if(i > 0){
649  rx += R_VAL(pix) * i;
650  gx += G_VAL(pix) * i;
651  bx += B_VAL(pix) * i;
652  ax += A_VAL(pix) * i;
653  }
654 
655  r += (rx >> 5) * j;
656  g += (gx >> 5) * j;
657  b += (bx >> 5) * j;
658  a += (ax >> 5) * j;
659  }
660 
661  *dptr = qRgba(r >> 23, g >> 23, b >> 23, a >> 23);
662  dptr++;
663  }
664  }
665  }
666 }
#define B_VAL(p)
#define A_VAL(p)
#define INV_YAP
#define G_VAL(p)
long ASN1_INTEGER_get ASN1_INTEGER * a
#define INV_XAP
#define YAP
static const KeyPair *const end
#define XAP
QRgb qRgba(int r, int g, int b, int a)
Returns the ARGB quadruplet ({a}, {r}, {g}, {b}).
Definition: qrgb.h:72
#define R_VAL(p)

Variable Documentation

◆ qt_qimageScaleArgb

Definition at line 65 of file qimagescale.cpp.

Referenced by qSmoothScaleImage().

◆ qt_qimageScaleRgb

Definition at line 66 of file qimagescale.cpp.

Referenced by qSmoothScaleImage().