@@ -143,6 +143,22 @@ void mirrors() throws Exception {
143143 assertTrue (paint (view ).getPixelReader ().getColor (8 , 24 ).getBrightness () > 0.75 );
144144 }
145145
146+ @ Test
147+ void anyRotationMultiple () throws Exception {
148+ // A rotation outside 0..270 is shown as its equal inside it.
149+ assertSamePixels (rotated (270 ), rotated (-90 ));
150+ assertSamePixels (rotated (90 ), rotated (450 ));
151+
152+ // Sideways, a 4:3 picture in a 4:3 view leaves bars on the sides.
153+ VideoView view = sized (64 , 48 );
154+ view .accept (frame (64 , 48 , 128 , 128 , -90 ));
155+ presented (view );
156+
157+ Image painted = paint (view );
158+ assertEquals (Color .BLACK , painted .getPixelReader ().getColor (2 , 24 ));
159+ assertGray (painted .getPixelReader ().getColor (32 , 24 ));
160+ }
161+
146162 @ Test
147163 void showsRemoteVideo () throws Exception {
148164 SignalingPair link = Signaling .loopback ();
@@ -219,11 +235,24 @@ private static <T> T onFx(Callable<T> action) throws Exception {
219235 return result .get (TIMEOUT_SECONDS , TimeUnit .SECONDS );
220236 }
221237
238+ /** What a 64x48 view paints of a 64x48 two-tone frame with the given rotation. */
239+ private Image rotated (int rotation ) throws Exception {
240+ VideoView view = sized (64 , 48 );
241+ view .accept (frame (64 , 48 , 16 , 235 , rotation ));
242+ presented (view );
243+
244+ return paint (view );
245+ }
246+
247+ private static VideoFrame frame (int width , int height , int left , int right ) {
248+ return frame (width , height , left , right , 0 );
249+ }
250+
222251 /**
223252 * A frame whose left half has luma {@code left} and right half {@code right}, with
224253 * neutral chroma.
225254 */
226- private static VideoFrame frame (int width , int height , int left , int right ) {
255+ private static VideoFrame frame (int width , int height , int left , int right , int rotation ) {
227256 NativeI420Buffer buffer = NativeI420Buffer .allocate (width , height );
228257 ByteBuffer y = buffer .getDataY ();
229258
@@ -236,7 +265,7 @@ private static VideoFrame frame(int width, int height, int left, int right) {
236265 fill (buffer .getDataU ());
237266 fill (buffer .getDataV ());
238267
239- return new VideoFrame (buffer , System .nanoTime ());
268+ return new VideoFrame (buffer , rotation , System .nanoTime ());
240269 }
241270
242271 private static void fill (ByteBuffer plane ) {
@@ -245,6 +274,18 @@ private static void fill(ByteBuffer plane) {
245274 }
246275 }
247276
277+ private static void assertSamePixels (Image expected , Image actual ) {
278+ assertEquals ((int ) expected .getWidth (), (int ) actual .getWidth ());
279+ assertEquals ((int ) expected .getHeight (), (int ) actual .getHeight ());
280+
281+ for (int y = 0 ; y < (int ) expected .getHeight (); y ++) {
282+ for (int x = 0 ; x < (int ) expected .getWidth (); x ++) {
283+ assertEquals (expected .getPixelReader ().getArgb (x , y ), actual .getPixelReader ().getArgb (x , y ),
284+ "Pixel " + x + "," + y );
285+ }
286+ }
287+ }
288+
248289 private static void assertGray (Color color ) {
249290 assertNotNull (color );
250291 assertTrue (Math .abs (color .getRed () - color .getGreen ()) < 0.04 && Math .abs (color .getGreen () - color .getBlue ()) < 0.04
0 commit comments