예제 #1
0
Pixel* getAveragedArray(Pixel *pixel, unsigned int size, unsigned int width, unsigned int height)
{
    /* Block constraints are defined as constants */
    unsigned int averagedSize = ceil(ceil(size/BLOCK_WIDTH)/BLOCK_HEIGHT);
    Pixel *averagedArray = malloc(sizeof(Pixel) * averagedSize);
  
    /* Divide by BLOCK_WIDTH*BLOCK_HEIGHT to average pixel values */
    int divisor = BLOCK_WIDTH*BLOCK_HEIGHT;

    for (int i = 0; i < ceil(height/BLOCK_HEIGHT); i++) {
        for (int j = 0; j < ceil(width/BLOCK_WIDTH); j++) {
            /* Iterate over real data array */
            for (int y = 0; y < BLOCK_HEIGHT; y++) {
                for (int x = 0; x < BLOCK_WIDTH; x++) {
                    /* Assign pixels */
                    averagedArray[(int)(i * (width/BLOCK_WIDTH) + j)] = addPixels(averagedArray[(int)(i * (width/BLOCK_WIDTH) + j)], pixel[(int)(((i * BLOCK_HEIGHT + y) * width) + (j * BLOCK_WIDTH + x))]);     
                }
            }

            /* Average pixel values */
            averagedArray[(int)(i * (width/BLOCK_WIDTH) + j)].r /= divisor;
            averagedArray[(int)(i * (width/BLOCK_WIDTH) + j)].g /= divisor;
            averagedArray[(int)(i * (width/BLOCK_WIDTH) + j)].b /= divisor;
            averagedArray[(int)(i * (width/BLOCK_WIDTH) + j)].a /= divisor;
        }
    }

    return averagedArray;
}
예제 #2
0
struct pixel* getAveragedArray(struct pixel* pp, unsigned int size, unsigned int height, unsigned int width){
  
    /*single block output is 8x14, so divide size by 8 and then 14
     *this is only a temporary value as the font size obviously can be changed.*/
  unsigned int averagedSize = ceil(ceil(size/8)/17);
  struct pixel* averagedArray = malloc(sizeof(struct pixel) * averagedSize);
  
  for(int i = 0; i < ceil(height/17); i++){
    for(int q = 0; q < ceil(width/8); q++){
	/*m and n for iterating along the original dataArray axis*/
      for(int m = 0; m < 17; m++){
	for(int n = 0; n < 8; n++){
	  
	    /*If you arrange any 1-dimensional array in a 2 dimensional box with the dimensions [width X (size/width)], where size is the 
	     *size of the box in one dimension and width is an arbitrary number (in this case, the width of the image found at 0x12 in the header),
	     * 
	     *then you can access the elements of the one dimensional equivalent
	     *by using the two dimensional array's desired y coordinate times the width to the power of 1, plus the desired x coordinate. Or,
	     *
	     * (x,y) = (y * w^1) + x
	     * 
	     *where w is width, and (x,y) is the coordinates in two dimensions.
	     *Thus, one can avoid potentially tricky pointer arithmetic by using simple algebra.
	     *(x,y), also happens to be the number of the corresponding 1-dimensional element number in base w,
	     *if the number is written as xy (i.e: (1,4) becomes 14). This is why I write y*w^1 instead of y*w; it corresponds with number system
	     *notation
	     */
	    
	  averagedArray[(int)(i*pow(width/8,1) + q)] = addPixels(averagedArray[(int)(i*pow(width/8,1) + q)], pp[(((i*17)+m) * (int)pow(width,1))+((q*8)+n)]);	  
	  
	}
      }
      
	/*8 x 17 is 112, so divide by 112 to average*/
      averagedArray[(int)(i*pow(width/8,1) + q)].r /= 136;
      averagedArray[(int)(i*pow(width/8,1) + q)].g /= 136;
      averagedArray[(int)(i*pow(width/8,1) + q)].b /= 136;
      averagedArray[(int)(i*pow(width/8,1) + q)].t /= 136;
    }
  }
  
  return averagedArray;
}