@@ -286,22 +286,39 @@ template<typename T>
286286static bool
287287scan_offset (string_view str, T& x, T& y)
288288{
289- return Strutil::parse_value (str, x)
290- && (str.size () && (str[0 ] == ' +' || str[0 ] == ' -' ))
291- && Strutil::parse_value (str, y);
289+ string_view orig = str;
290+ if (Strutil::parse_value (str, x)
291+ && (str.size () && (str[0 ] == ' +' || str[0 ] == ' -' ))
292+ && Strutil::parse_value (str, y))
293+ return true ;
294+ str = orig;
295+ if (Strutil::parse_value (str, x) && Strutil::parse_char (str, ' ,' )
296+ && Strutil::parse_value (str, y))
297+ return true ;
298+ return false ;
292299}
293300
294301
302+
295303template <typename T>
296304static bool
297305scan_res_offset (string_view str, T& w, T& h, T& x, T& y)
298306{
299- return Strutil::parse_value (str, w) && Strutil::parse_char (str, ' x' )
300- && Strutil::parse_value (str, h)
301- && (str.size () && (str[0 ] == ' +' || str[0 ] == ' -' ))
302- && Strutil::parse_value (str, x)
303- && (str.size () && (str[0 ] == ' +' || str[0 ] == ' -' ))
304- && Strutil::parse_value (str, y); // NOSONAR
307+ string_view orig = str;
308+ if (Strutil::parse_value (str, w) && Strutil::parse_char (str, ' x' )
309+ && Strutil::parse_value (str, h)
310+ && (str.size () && (str[0 ] == ' +' || str[0 ] == ' -' ))
311+ && Strutil::parse_value (str, x)
312+ && (str.size () && (str[0 ] == ' +' || str[0 ] == ' -' ))
313+ && Strutil::parse_value (str, y))
314+ return true ;
315+ str = orig;
316+ if (Strutil::parse_value (str, w) && Strutil::parse_char (str, ' x' )
317+ && Strutil::parse_value (str, h) && Strutil::parse_char (str, ' ,' )
318+ && Strutil::parse_value (str, x) && Strutil::parse_char (str, ' ,' )
319+ && Strutil::parse_value (str, y))
320+ return true ;
321+ return false ;
305322}
306323
307324
@@ -968,7 +985,7 @@ adjust_output_options(string_view filename, ImageSpec& spec,
968985 if (tilesize.size ()) {
969986 int x, y; // dummy vals for adjust_geometry
970987 ot.adjust_geometry (" -o" , requested_tilewidth, requested_tileheight, x,
971- y, tilesize.c_str (), false );
988+ y, tilesize.c_str (), false , false );
972989 }
973990 bool requested_scanline = fileoptions.get_int (" scanline" ,
974991 ot.output_scanline );
@@ -1775,7 +1792,23 @@ unit_test_adjust_geometry(Oiiotool& ot)
17751792 OIIO_CHECK_ASSERT (
17761793 !ot.adjust_geometry (" foo" , w, h, x, y, " 10x20+100+200" , true , false ));
17771794
1778- // res
1795+ // geom with comma notation for origin
1796+ w = h = x = y = -42 ;
1797+ OIIO_CHECK_ASSERT (ot.adjust_geometry (" foo" , w, h, x, y, " 10x20,100,200" )
1798+ && x == 100 && y == 200 && w == 10 && h == 20 );
1799+ w = h = x = y = -42 ;
1800+ OIIO_CHECK_ASSERT (ot.adjust_geometry (" foo" , w, h, x, y, " 10x20,-100,-200" )
1801+ && x == -100 && y == -200 && w == 10 && h == 20 );
1802+ w = 100 , h = 50 , x = y = 0 ;
1803+ OIIO_CHECK_ASSERT (ot.adjust_geometry (" foo" , w, h, x, y, " 20x0,100,200" )
1804+ && x == 100 && y == 200 && w == 20 && h == 10 );
1805+ w = 100 , h = 50 , x = y = 0 ;
1806+ OIIO_CHECK_ASSERT (ot.adjust_geometry (" foo" , w, h, x, y, " 0x20,100,200" )
1807+ && x == 100 && y == 200 && w == 40 && h == 20 );
1808+ OIIO_CHECK_ASSERT (
1809+ !ot.adjust_geometry (" foo" , w, h, x, y, " 10x20+100+200" , true , false ));
1810+
1811+ // res only
17791812 w = h = x = y = -42 ;
17801813 OIIO_CHECK_ASSERT (ot.adjust_geometry (" foo" , w, h, x, y, " 10x20" ) && x == -42
17811814 && y == -42 && w == 10 && h == 20 );
@@ -1807,6 +1840,23 @@ unit_test_adjust_geometry(Oiiotool& ot)
18071840 w = h = x = y = -42 ;
18081841 OIIO_CHECK_ASSERT (ot.adjust_geometry (" foo" , w, h, x, y, " +100+200" )
18091842 && x == 100 && y == 200 && w == -42 && h == -42 );
1843+ w = h = x = y = -42 ;
1844+ OIIO_CHECK_ASSERT (ot.adjust_geometry (" foo" , w, h, x, y, " +100-200" )
1845+ && x == 100 && y == -200 && w == -42 && h == -42 );
1846+ w = h = x = y = -42 ;
1847+ OIIO_CHECK_ASSERT (ot.adjust_geometry (" foo" , w, h, x, y, " -100+200" )
1848+ && x == -100 && y == 200 && w == -42 && h == -42 );
1849+
1850+ // offset with comma notation
1851+ w = h = x = y = -42 ;
1852+ OIIO_CHECK_ASSERT (ot.adjust_geometry (" foo" , w, h, x, y, " 100,200" )
1853+ && x == 100 && y == 200 && w == -42 && h == -42 );
1854+ w = h = x = y = -42 ;
1855+ OIIO_CHECK_ASSERT (ot.adjust_geometry (" foo" , w, h, x, y, " 100,-200" )
1856+ && x == 100 && y == -200 && w == -42 && h == -42 );
1857+ w = h = x = y = -42 ;
1858+ OIIO_CHECK_ASSERT (ot.adjust_geometry (" foo" , w, h, x, y, " -100,200" )
1859+ && x == -100 && y == 200 && w == -42 && h == -42 );
18101860
18111861 // scale by factor
18121862 w = 640 ;
0 commit comments