[Artwork] / [QisMLib] / [Programmer's Corner]
In 2x2 down-sampling, we map every 2x2 block of pixels from the input (two pixels on two rows) to a single pixel in the output
The user-specified recipe controls which of the 16 possible 2x2 patterns from the input results in a black pixel in the output
The recipe is an array of 16 bytes (unsigned char
) where each byte can either be 0
(white/OFF pixel) or 1
(black/ON) pixel and the index/position of the byte in the array (0 .. 15) determines the corresponding 2x2 pattern from the input
The default recipe uses the rule that the output pixel is black if the input pattern has more than 50% black pixels
xxxxxxxxxx
unsigned char default_recipe[] = { //{output}, {input-top-left}{top-right} {bottom-left}{bottom-right}
0, //00 00
0, //00 01
0, //00 10
0, //00 11
0, //01 00
0, //01 01
0, //01 10
1, //01 11 >50% black
0, //10 00
0, //10 01
0, //10 10
1, //10 11 >50% black
0, //11 00
1, //11 01 >50% black
1, //11 10 >50% black
1 //11 11 >50% black
};
An alternate recipe could allow black-white transitions from the input to set a pixel in the output as follows :-
xxxxxxxxxx
unsigned char alternate_recipe[] = { //{output}, {input-top-left}{top-right} {bottom-left}{bottom-right}
0, //00 00
0, //00 01
0, //00 10
1, //00 11 transition from white row (top) to black (bottom)
0, //01 00
1, //01 01 transition from white column (left) to black (right)
0, //01 10
1, //01 11 >50% black
0, //10 00
0, //10 01
1, //10 10 transition from black column (left) to white (right)
1, //10 11 >50% black
1, //11 00 transition from black row (top) to white (bottom)
1, //11 01 >50% black
1, //11 10 >50% black
1 //11 11 >50% black
};