|
| 1 | +module malvar_he_cutler_demosaic ( |
| 2 | + input logic [7:0] pixel_mosaic_matrix [0:5] [0:5], |
| 3 | + // 0 = Blue |
| 4 | + // 1 = Green in blue row (in BGGR, the first green) |
| 5 | + // 2 = Green in red row (in BGGR, the second green) |
| 6 | + // 3 = Red |
| 7 | + input logic [1:0] center_pixel_type, |
| 8 | + output logic [23:0] center_pixel_rgb |
| 9 | +); |
| 10 | + |
| 11 | +logic [11:0] green_estimate_at_non_green; |
| 12 | +always_comb |
| 13 | +begin |
| 14 | + green_estimate_at_non_green = 12'd4 * 12'(pixel_mosaic_matrix[2][2]); |
| 15 | + |
| 16 | + green_estimate_at_non_green += 12'd2 * 12'(pixel_mosaic_matrix[1][2]); |
| 17 | + green_estimate_at_non_green += 12'd2 * 12'(pixel_mosaic_matrix[2][1]); |
| 18 | + green_estimate_at_non_green += 12'd2 * 12'(pixel_mosaic_matrix[2][3]); |
| 19 | + green_estimate_at_non_green += 12'd2 * 12'(pixel_mosaic_matrix[3][2]); |
| 20 | + |
| 21 | + green_estimate_at_non_green -= 12'(pixel_mosaic_matrix[0][2]); |
| 22 | + green_estimate_at_non_green -= 12'(pixel_mosaic_matrix[2][0]); |
| 23 | + green_estimate_at_non_green -= 12'(pixel_mosaic_matrix[2][4]); |
| 24 | + green_estimate_at_non_green -= 12'(pixel_mosaic_matrix[4][2]); |
| 25 | + |
| 26 | + green_estimate_at_non_green /= 12'd8; |
| 27 | +end |
| 28 | + |
| 29 | +logic [11:0] other_estimate_at_non_green; |
| 30 | +always_comb |
| 31 | +begin |
| 32 | + other_estimate_at_non_green = 12'd6 * 12'(pixel_mosaic_matrix[2][2]); |
| 33 | + |
| 34 | + other_estimate_at_non_green += 12'd2 * 12'(pixel_mosaic_matrix[1][1]); |
| 35 | + other_estimate_at_non_green += 12'd2 * 12'(pixel_mosaic_matrix[1][3]); |
| 36 | + other_estimate_at_non_green += 12'd2 * 12'(pixel_mosaic_matrix[3][3]); |
| 37 | + other_estimate_at_non_green += 12'd2 * 12'(pixel_mosaic_matrix[3][1]); |
| 38 | + |
| 39 | + other_estimate_at_non_green -= (12'd3 * 12'(pixel_mosaic_matrix[0][2])) / 12'd2; |
| 40 | + other_estimate_at_non_green -= (12'd3 * 12'(pixel_mosaic_matrix[4][2])) / 12'd2; |
| 41 | + other_estimate_at_non_green -= (12'd3 * 12'(pixel_mosaic_matrix[2][0])) / 12'd2; |
| 42 | + other_estimate_at_non_green -= (12'd3 * 12'(pixel_mosaic_matrix[2][4])) / 12'd2; |
| 43 | + |
| 44 | + other_estimate_at_non_green /= 12'd8; |
| 45 | +end |
| 46 | + |
| 47 | +logic [11:0] non_green_estimate_in_same_row_at_green; |
| 48 | +always_comb |
| 49 | +begin |
| 50 | + non_green_estimate_in_same_row_at_green = 12'd5 * 12'(pixel_mosaic_matrix[2][2]); |
| 51 | + |
| 52 | + non_green_estimate_in_same_row_at_green += 12'd4 * 12'(pixel_mosaic_matrix[2][1]); |
| 53 | + non_green_estimate_in_same_row_at_green += 12'd4 * 12'(pixel_mosaic_matrix[2][3]); |
| 54 | + |
| 55 | + non_green_estimate_in_same_row_at_green += 12'(pixel_mosaic_matrix[0][2]) / 12'd2; |
| 56 | + non_green_estimate_in_same_row_at_green += 12'(pixel_mosaic_matrix[4][2]) / 12'd2; |
| 57 | + |
| 58 | + non_green_estimate_in_same_row_at_green -= 12'(pixel_mosaic_matrix[2][0]); |
| 59 | + non_green_estimate_in_same_row_at_green -= 12'(pixel_mosaic_matrix[2][4]); |
| 60 | + |
| 61 | + non_green_estimate_in_same_row_at_green -= 12'(pixel_mosaic_matrix[1][1]); |
| 62 | + non_green_estimate_in_same_row_at_green -= 12'(pixel_mosaic_matrix[1][3]); |
| 63 | + non_green_estimate_in_same_row_at_green -= 12'(pixel_mosaic_matrix[3][3]); |
| 64 | + non_green_estimate_in_same_row_at_green -= 12'(pixel_mosaic_matrix[3][1]); |
| 65 | + |
| 66 | + non_green_estimate_in_same_row_at_green /= 12'd8; |
| 67 | +end |
| 68 | + |
| 69 | +logic [11:0] non_green_estimate_in_different_row_at_green; |
| 70 | +always_comb |
| 71 | +begin |
| 72 | + non_green_estimate_in_different_row_at_green = 12'd5 * 12'(pixel_mosaic_matrix[2][2]); |
| 73 | + |
| 74 | + non_green_estimate_in_different_row_at_green += 12'd4 * 12'(pixel_mosaic_matrix[1][2]); |
| 75 | + non_green_estimate_in_different_row_at_green += 12'd4 * 12'(pixel_mosaic_matrix[3][2]); |
| 76 | + |
| 77 | + non_green_estimate_in_different_row_at_green += 12'(pixel_mosaic_matrix[2][0]) / 12'd2; |
| 78 | + non_green_estimate_in_different_row_at_green += 12'(pixel_mosaic_matrix[2][4]) / 12'd2; |
| 79 | + |
| 80 | + non_green_estimate_in_different_row_at_green -= 12'(pixel_mosaic_matrix[0][2]); |
| 81 | + non_green_estimate_in_different_row_at_green -= 12'(pixel_mosaic_matrix[4][2]); |
| 82 | + |
| 83 | + non_green_estimate_in_different_row_at_green -= 12'(pixel_mosaic_matrix[1][1]); |
| 84 | + non_green_estimate_in_different_row_at_green -= 12'(pixel_mosaic_matrix[1][3]); |
| 85 | + non_green_estimate_in_different_row_at_green -= 12'(pixel_mosaic_matrix[3][3]); |
| 86 | + non_green_estimate_in_different_row_at_green -= 12'(pixel_mosaic_matrix[3][1]); |
| 87 | + |
| 88 | + non_green_estimate_in_different_row_at_green /= 12'd8; |
| 89 | +end |
| 90 | + |
| 91 | +always_comb |
| 92 | +begin |
| 93 | + case (center_pixel_type) |
| 94 | + 2'b11: // Red |
| 95 | + begin |
| 96 | + center_pixel_rgb[2] = pixel_mosaic_matrix[2][2]; |
| 97 | + center_pixel_rgb[1] = 8'(green_estimate_at_non_green); |
| 98 | + center_pixel_rgb[0] = 8'(other_estimate_at_non_green); |
| 99 | + end |
| 100 | + 2'b10: // Green in red row |
| 101 | + begin |
| 102 | + center_pixel_rgb[2] = 8'(non_green_estimate_in_same_row_at_green); |
| 103 | + center_pixel_rgb[1] = pixel_mosaic_matrix[2][2]; |
| 104 | + center_pixel_rgb[0] = 8'(non_green_estimate_in_different_row_at_green); |
| 105 | + end |
| 106 | + 2'b01: // Green in blue row |
| 107 | + begin |
| 108 | + center_pixel_rgb[2] = 8'(non_green_estimate_in_different_row_at_green); |
| 109 | + center_pixel_rgb[1] = pixel_mosaic_matrix[2][2]; |
| 110 | + center_pixel_rgb[0] = 8'(non_green_estimate_in_same_row_at_green); |
| 111 | + end |
| 112 | + 2'b00: // Blue |
| 113 | + begin |
| 114 | + center_pixel_rgb[2] = 8'(other_estimate_at_non_green); |
| 115 | + center_pixel_rgb[1] = 8'(green_estimate_at_non_green); |
| 116 | + center_pixel_rgb[0] = pixel_mosaic_matrix[2][2]; |
| 117 | + end |
| 118 | + endcase |
| 119 | +end |
| 120 | + |
| 121 | +endmodule |
0 commit comments