Qt 4.8
Classes | Functions
QImageScale Namespace Reference

Classes

struct  QImageScaleInfo
 

Functions

int * qimageCalcApoints (int s, int d, int up)
 
QImageScaleInfoqimageCalcScaleInfo (const QImage &img, int sw, int sh, int dw, int dh, char aa)
 
int * qimageCalcXPoints (int sw, int dw)
 
unsigned int ** qimageCalcYPoints (unsigned int *src, int sw, int sh, int dh)
 
QImageScaleInfoqimageFreeScaleInfo (QImageScaleInfo *isi)
 

Function Documentation

◆ qimageCalcApoints()

int * QImageScale::qimageCalcApoints ( int  s,
int  d,
int  up 
)

Definition at line 209 of file qimagescale.cpp.

Referenced by qimageCalcScaleInfo().

210 {
211  int *p, i, j = 0, rv = 0;
212 
213  if(d < 0){
214  rv = 1;
215  d = -d;
216  }
217  p = new int[d];
218 
219  /* scaling up */
220  if(up){
221  int val, inc;
222 
223  val = 0x8000 * s / d - 0x8000;
224  inc = (s << 16) / d;
225  for(i = 0; i < d; i++){
226  int pos = val >> 16;
227  if (pos < 0)
228  p[j++] = 0;
229  else if (pos >= (s - 1))
230  p[j++] = 0;
231  else
232  p[j++] = (val >> 8) - ((val >> 8) & 0xffffff00);
233  val += inc;
234  }
235  }
236  /* scaling down */
237  else{
238  int val, inc, ap, Cp;
239  val = 0;
240  inc = (s << 16) / d;
241  Cp = ((d << 14) / s) + 1;
242  for(i = 0; i < d; i++){
243  ap = ((0x100 - ((val >> 8) & 0xff)) * Cp) >> 8;
244  p[j] = ap | (Cp << 16);
245  j++;
246  val += inc;
247  }
248  }
249  if(rv){
250  int tmp;
251  for(i = d / 2; --i >= 0; ){
252  tmp = p[i];
253  p[i] = p[d - i - 1];
254  p[d - i - 1] = tmp;
255  }
256  }
257  return(p);
258 }
double d
Definition: qnumeric_p.h:62

◆ qimageCalcScaleInfo()

QImageScaleInfo * QImageScale::qimageCalcScaleInfo ( const QImage img,
int  sw,
int  sh,
int  dw,
int  dh,
char  aa 
)

Definition at line 272 of file qimagescale.cpp.

Referenced by qSmoothScaleImage().

275 {
276  QImageScaleInfo *isi;
277  int scw, sch;
278 
279  scw = dw * qlonglong(img.width()) / sw;
280  sch = dh * qlonglong(img.height()) / sh;
281 
282  isi = new QImageScaleInfo;
283  if(!isi)
284  return 0;
285  memset(isi, 0, sizeof(QImageScaleInfo));
286 
287  isi->xup_yup = (qAbs(dw) >= sw) + ((qAbs(dh) >= sh) << 1);
288 
289  isi->xpoints = qimageCalcXPoints(img.width(), scw);
290  if(!isi->xpoints)
291  return(qimageFreeScaleInfo(isi));
292  isi->ypoints = qimageCalcYPoints((unsigned int *)img.scanLine(0),
293  img.bytesPerLine() / 4, img.height(), sch);
294  if (!isi->ypoints)
295  return(qimageFreeScaleInfo(isi));
296  if(aa) {
297  isi->xapoints = qimageCalcApoints(img.width(), scw, isi->xup_yup & 1);
298  if(!isi->xapoints)
299  return(qimageFreeScaleInfo(isi));
300  isi->yapoints = qimageCalcApoints(img.height(), sch, isi->xup_yup & 2);
301  if(!isi->yapoints)
302  return(qimageFreeScaleInfo(isi));
303  }
304  return(isi);
305 }
QImageScaleInfo * qimageFreeScaleInfo(QImageScaleInfo *isi)
int bytesPerLine() const
Returns the number of bytes per image scanline.
Definition: qimage.cpp:1812
int * qimageCalcXPoints(int sw, int dw)
Q_DECL_CONSTEXPR T qAbs(const T &t)
Definition: qglobal.h:1201
int width() const
Returns the width of the image.
Definition: qimage.cpp:1557
int * qimageCalcApoints(int s, int d, int up)
unsigned int ** qimageCalcYPoints(unsigned int *src, int sw, int sh, int dh)
int height() const
Returns the height of the image.
Definition: qimage.cpp:1572
qint64 qlonglong
Definition: qglobal.h:951
uchar * scanLine(int)
Returns a pointer to the pixel data at the scanline with index i.
Definition: qimage.cpp:1886

◆ qimageCalcXPoints()

int * QImageScale::qimageCalcXPoints ( int  sw,
int  dw 
)

Definition at line 180 of file qimagescale.cpp.

Referenced by qimageCalcScaleInfo().

181 {
182  int *p, i, j = 0;
183  int val, inc, rv = 0;
184 
185  if(dw < 0){
186  dw = -dw;
187  rv = 1;
188  }
189  p = new int[dw+1];
190 
191  int up = qAbs(dw) >= sw;
192  val = up ? 0x8000 * sw / dw - 0x8000 : 0;
193  inc = (sw << 16) / dw;
194  for(i = 0; i < dw; i++){
195  p[j++] = qMax(0, val >> 16);
196  val += inc;
197  }
198 
199  if(rv){
200  for(i = dw / 2; --i >= 0; ){
201  int tmp = p[i];
202  p[i] = p[dw - i - 1];
203  p[dw - i - 1] = tmp;
204  }
205  }
206  return(p);
207 }
Q_DECL_CONSTEXPR T qAbs(const T &t)
Definition: qglobal.h:1201
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217

◆ qimageCalcYPoints()

unsigned int ** QImageScale::qimageCalcYPoints ( unsigned int *  src,
int  sw,
int  sh,
int  dh 
)

Definition at line 150 of file qimagescale.cpp.

Referenced by qimageCalcScaleInfo().

152 {
153  unsigned int **p;
154  int i, j = 0;
155  int val, inc, rv = 0;
156 
157  if(dh < 0){
158  dh = -dh;
159  rv = 1;
160  }
161  p = new unsigned int* [dh+1];
162 
163  int up = qAbs(dh) >= sh;
164  val = up ? 0x8000 * sh / dh - 0x8000 : 0;
165  inc = (sh << 16) / dh;
166  for(i = 0; i < dh; i++){
167  p[j++] = src + qMax(0, val >> 16) * sw;
168  val += inc;
169  }
170  if(rv){
171  for(i = dh / 2; --i >= 0; ){
172  unsigned int *tmp = p[i];
173  p[i] = p[dh - i - 1];
174  p[dh - i - 1] = tmp;
175  }
176  }
177  return(p);
178 }
Q_DECL_CONSTEXPR T qAbs(const T &t)
Definition: qglobal.h:1201
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217

◆ qimageFreeScaleInfo()

QImageScaleInfo * QImageScale::qimageFreeScaleInfo ( QImageScaleInfo isi)

Definition at line 260 of file qimagescale.cpp.

Referenced by qimageCalcScaleInfo(), and qSmoothScaleImage().

261 {
262  if(isi){
263  delete[] isi->xpoints;
264  delete[] isi->ypoints;
265  delete[] isi->xapoints;
266  delete[] isi->yapoints;
267  delete isi;
268  }
269  return 0;
270 }