MCPcopy Create free account
hub / github.com/MolinDeng/Princeton-algs4 / seamOverlay

Method seamOverlay

LabEnv/07Lab/SCUtility.java:91–114  ·  view source on GitHub ↗
(Picture picture, boolean horizontal, int[] seamIndices)

Source from the content-addressed store, hash-verified

89 // pixels over the calculate seam. Due to the lack of a copy
90 // constructor, it also alters the original picture.
91 public static Picture seamOverlay(Picture picture, boolean horizontal, int[] seamIndices) {
92 Picture overlaid = new Picture(picture.width(), picture.height());
93 int width = picture.width();
94 int height = picture.height();
95
96 for (int col = 0; col < width; col++)
97 for (int row = 0; row < height; row++)
98 overlaid.set(col, row, picture.get(col, row));
99
100
101 // if horizontal seam, then set one pixel in every column
102 if (horizontal) {
103 for (int col = 0; col < width; col++)
104 overlaid.set(col, seamIndices[col], Color.RED);
105 }
106
107 // if vertical, put one pixel in every row
108 else {
109 for (int row = 0; row < height; row++)
110 overlaid.set(seamIndices[row], row, Color.RED);
111 }
112
113 return overlaid;
114 }
115
116}

Callers 2

showHorizontalSeamMethod · 0.95
showVerticalSeamMethod · 0.95

Calls 3

widthMethod · 0.45
heightMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected