union totalColors{ version(v4l2) struct {ubyte red, green, blue, grey; } else struct {ubyte blue, green, red, grey; } ubyte[4] array; } class Statistics{ Picture picture; totalColors totals; totalColors[] rows; totalColors[] columns; totalColors[] focusColumns; this(Picture picture, uint focusStart, uint focusEnd){ this.picture = picture; rows.length = picture.height; columns.length = picture.width; focusColumns.length = picture.width; //current subpixel uint current = 0; bool special; with(picture){ for(uint row = 0; row < height; row++){ for(uint column = 0; column < width; column++){ special = (row >= focusStart) && (row <= focusEnd); //Blue subpixel totals totals.blue += data[current]; rows[row].blue += data[current]; columns[column].blue += data[current]; if(special) focusColumns[column].blue += data[current]; current++; //gren subpixel totals totals.green += data[current]; rows[row].green += data[current]; columns[column].green += data[current]; if(special) focusColumns[column].green += data[current]; current++; //Red subpixel totals totals.red += data[current]; rows[row].red += data[current]; columns[column].red += data[current]; if(special) focusColumns[column].red += data[current]; current++; } } }