Pixmap: expand APT

Class

public class Pixmap { public int[] expand(int[] pixels, int rows, int cols, int rowExpand, int colExpand) { // TODO: complete expand } }

Problem Statement

One operation performed on images is expansion: replacing a pixel by a rectangle of equal pixels and repeating this operation for every pixel in the image. An M x N image is generally considered to by M pixels wide by N pixels high. This means it has N rows and M columns (the number of columns is the width).

As an example, consider the 4x3 image below on the left (there are three rows, four columns), a 3x2 expansion replaces each pixel by a 3x2 rectangle of the same pixel resulting in the image on the right. Note that the resulting image is 12x6. Note that the expansion is specified essentially by the size of the rectangle of pixels that "replaces" each original pixel.


 abcd      aaabbbcccddd
 efgh      aaabbbcccddd
 xyzw      eeefffggghhh
           eeefffggghhh
           xxxyyyzzzwww
           xxxyyyzzzwww

The image is given as an array of pixels in row-major order, that is the pixels are listed moving across rows and then down the columns.

Write the method expand that returns an int[] representing the expansion of the image given by parameters pixels , rows, and cols. The size of the expansion is given by the added parameters. See the examples for details.

Constraints

Examples

  1. {1} 
    
    1 
    
    1 
    
    3 
    
    4
    
    Returns:  [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
    

  2. {1, 2, 3, 4}
    
    2 
    
    2 
    
    2 
    
    2 
    
    Returns:  {1, 1, 2, 2, 1, 1, 2, 2, 3, 3, 4, 4, 3, 3, 4, 4}
    

  3. {1, 2, 3, 4, 5, 6, 7, 8}
    
    2 
    
    4 
    
    2 
    
    1
    
    Returns:  {1, 2, 3, 4, 1, 2, 3, 4, 5, 6, 7, 8, 5, 6, 7, 8}