Advertisement
xerpi

Untitled

Jun 9th, 2014
355
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.09 KB | None | 0 0
  1. /**
  2.  * Scales an Image
  3.  *
  4.  * @pre image != NULL
  5.  * @param image - the input image
  6.  * @returns the scaled image
  7.  * @param sW - the scale width factor
  8.  * @param sH - the scale height factor
  9.  */
  10. extern Image *scaleImage(Image *image, float sW, float sH);
  11.  
  12.  
  13.  
  14.  
  15.  
  16.  
  17. Image *scaleImage(Image *image, float sW, float sH)
  18. {
  19.     Image *out = (Image*)malloc(sizeof(Image));
  20.     if (!out) return NULL;
  21.    
  22.     out->imageWidth  = image->imageWidth*sW;
  23.     out->imageHeight = image->imageHeight*sH;
  24.     out->textureWidth  = getNextPower2(out->imageWidth);
  25.     out->textureHeight = getNextPower2(out->imageHeight);
  26.  
  27.     out->data = (Color*) memalign(16, out->textureWidth * out->textureHeight * sizeof(Color));
  28.     if (!image->data) {free(out); return NULL;}
  29.    
  30.     memset(out->data, 0, out->textureWidth * out->textureHeight * sizeof(Color));
  31.  
  32.     int x, y;
  33.     for (y = 0; y < image->imageHeight; y++) {
  34.         for (x = 0; x < image->imageWidth; x++) {
  35.             out->data[(x*sW) + (y*sH) * out->textureWidth] |= image->data[x + y * image->textureWidth];
  36.         }
  37.     }
  38.  
  39.     return out;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement