@@ -8496,7 +8496,7 @@ int gmt_grd_project (struct GMT_CTRL *GMT, struct GMT_GRID *I, struct GMT_GRID *
8496
8496
}
8497
8497
8498
8498
/*! . */
8499
- int gmt_img_project (struct GMT_CTRL * GMT , struct GMT_IMAGE * I , struct GMT_IMAGE * O , bool inverse ) {
8499
+ int gmt_img_project (struct GMT_CTRL * GMT , struct GMT_IMAGE * I , struct GMT_IMAGE * O , bool inverse ) {
8500
8500
/* Generalized image projection that deals with both interpolation and averaging effects.
8501
8501
* It requires the input image to have 2 boundary rows/cols so that the bcr
8502
8502
* functions can be used. The I struct represents the input image which is either in original
@@ -8530,7 +8530,7 @@ int gmt_img_project (struct GMT_CTRL *GMT, struct GMT_IMAGE *I, struct GMT_IMAGE
8530
8530
8531
8531
/* Only input image MUST have at least 2 rows/cols padding */
8532
8532
if (I -> header -> pad [XLO ] < 2 || I -> header -> pad [XHI ] < 2 || I -> header -> pad [YLO ] < 2 || I -> header -> pad [YHI ] < 2 ) {
8533
- GMT_Report (GMT -> parent , GMT_MSG_ERROR , "gmt_img_project: Input image does not have sufficient (2) padding\n" );
8533
+ GMT_Report (GMT -> parent , GMT_MSG_ERROR , "gmt_img_project: Input image does not have sufficient (2) padding\n" );
8534
8534
return GMT_RUNTIME_ERROR ;
8535
8535
}
8536
8536
@@ -8552,22 +8552,22 @@ int gmt_img_project (struct GMT_CTRL *GMT, struct GMT_IMAGE *I, struct GMT_IMAGE
8552
8552
}
8553
8553
8554
8554
if (gmt_M_is_rect_graticule (GMT )) { /* Since lon/lat parallels x/y it pays to precalculate projected grid coordinates up front */
8555
- if ((x_in_proj = gmt_M_memory (GMT , NULL , I -> header -> n_columns , double )) == NULL ) return GMT_MEMORY_ERROR ;
8556
- if ((y_in_proj = gmt_M_memory (GMT , NULL , I -> header -> n_rows , double )) == NULL ) return GMT_MEMORY_ERROR ;
8557
- if ((x_out_proj = gmt_M_memory (GMT , NULL , O -> header -> n_columns , double )) == NULL ) return GMT_MEMORY_ERROR ;
8558
- if ((y_out_proj = gmt_M_memory (GMT , NULL , O -> header -> n_rows , double )) == NULL ) return GMT_MEMORY_ERROR ;
8555
+ if ((x_in_proj = gmt_M_memory (GMT , NULL , I -> header -> n_columns , double )) == NULL ) return GMT_MEMORY_ERROR ;
8556
+ if ((y_in_proj = gmt_M_memory (GMT , NULL , I -> header -> n_rows , double )) == NULL ) return GMT_MEMORY_ERROR ;
8557
+ if ((x_out_proj = gmt_M_memory (GMT , NULL , O -> header -> n_columns , double )) == NULL ) return GMT_MEMORY_ERROR ;
8558
+ if ((y_out_proj = gmt_M_memory (GMT , NULL , O -> header -> n_rows , double )) == NULL ) return GMT_MEMORY_ERROR ;
8559
8559
if (inverse ) {
8560
- gmt_M_row_loop (GMT , I , row_in ) gmt_xy_to_geo (GMT , & x_proj , & y_in_proj [row_in ], I -> header -> wesn [XLO ], y_in [row_in ]);
8561
- gmt_M_col_loop2 (GMT , I , col_in ) gmt_xy_to_geo (GMT , & x_in_proj [col_in ], & y_proj , x_in [col_in ], I -> header -> wesn [YLO ]);
8562
- gmt_M_row_loop (GMT , O , row_out ) gmt_geo_to_xy (GMT , I -> header -> wesn [YLO ], y_out [row_out ], & x_proj , & y_out_proj [row_out ]);
8563
- gmt_M_col_loop2 (GMT , O , col_out ) gmt_geo_to_xy (GMT , x_out [col_out ], I -> header -> wesn [YLO ], & x_out_proj [col_out ], & y_proj );
8560
+ gmt_M_row_loop (GMT , I , row_in ) gmt_xy_to_geo (GMT , & x_proj , & y_in_proj [row_in ], I -> header -> wesn [XLO ], y_in [row_in ]);
8561
+ gmt_M_col_loop2 (GMT , I , col_in ) gmt_xy_to_geo (GMT , & x_in_proj [col_in ], & y_proj , x_in [col_in ], I -> header -> wesn [YLO ]);
8562
+ gmt_M_row_loop (GMT , O , row_out ) gmt_geo_to_xy (GMT , I -> header -> wesn [YLO ], y_out [row_out ], & x_proj , & y_out_proj [row_out ]);
8563
+ gmt_M_col_loop2 (GMT , O , col_out ) gmt_geo_to_xy (GMT , x_out [col_out ], I -> header -> wesn [YLO ], & x_out_proj [col_out ], & y_proj );
8564
8564
}
8565
8565
else {
8566
- gmt_M_row_loop (GMT , I , row_in ) gmt_geo_to_xy (GMT , I -> header -> wesn [XLO ], y_in [row_in ], & x_proj , & y_in_proj [row_in ]);
8567
- gmt_M_col_loop2 (GMT , I , col_in ) gmt_geo_to_xy (GMT , x_in [col_in ], I -> header -> wesn [YLO ], & x_in_proj [col_in ], & y_proj );
8568
- gmt_M_row_loop (GMT , O , row_out ) gmt_xy_to_geo (GMT , & x_proj , & y_out_proj [row_out ], I -> header -> wesn [YLO ], y_out [row_out ]);
8566
+ gmt_M_row_loop (GMT , I , row_in ) gmt_geo_to_xy (GMT , I -> header -> wesn [XLO ], y_in [row_in ], & x_proj , & y_in_proj [row_in ]);
8567
+ gmt_M_col_loop2 (GMT , I , col_in ) gmt_geo_to_xy (GMT , x_in [col_in ], I -> header -> wesn [YLO ], & x_in_proj [col_in ], & y_proj );
8568
+ gmt_M_row_loop (GMT , O , row_out ) gmt_xy_to_geo (GMT , & x_proj , & y_out_proj [row_out ], I -> header -> wesn [YLO ], y_out [row_out ]);
8569
8569
gmt_M_col_loop2 (GMT , O , col_out ) { /* Here we must also align longitudes properly */
8570
- gmt_xy_to_geo (GMT , & x_out_proj [col_out ], & y_proj , x_out [col_out ], I -> header -> wesn [YLO ]);
8570
+ gmt_xy_to_geo (GMT , & x_out_proj [col_out ], & y_proj , x_out [col_out ], I -> header -> wesn [YLO ]);
8571
8571
if (gmt_M_x_is_lon (GMT , GMT_IN ) && !gmt_M_is_dnan (x_out_proj [col_out ])) {
8572
8572
while (x_out_proj [col_out ] < I -> header -> wesn [XLO ] - GMT_CONV4_LIMIT ) x_out_proj [col_out ] += 360.0 ;
8573
8573
while (x_out_proj [col_out ] > I -> header -> wesn [XHI ] + GMT_CONV4_LIMIT ) x_out_proj [col_out ] -= 360.0 ;
@@ -8580,7 +8580,8 @@ int gmt_img_project (struct GMT_CTRL *GMT, struct GMT_IMAGE *I, struct GMT_IMAGE
8580
8580
gmt_M_grd_loop (GMT , O , row_out , col_out , ij_out ) /* So that nodes outside will have the NaN color */
8581
8581
for (b = 0 ; b < nb ; b ++ ) O -> data [nb * ij_out + b ] = gmt_M_u255 (GMT -> current .setting .color_patch [GMT_NAN ][b ]);
8582
8582
#endif
8583
- for (b = 0 ; b < 4 ; b ++ ) z_int_bg [b ] = gmt_M_u255 (GMT -> current .setting .color_patch [GMT_NAN ][b ]);
8583
+ for (b = 0 ; b < 4 ; b ++ )
8584
+ z_int_bg [b ] = gmt_M_u255 (GMT -> current .setting .color_patch [GMT_NAN ][b ]);
8584
8585
8585
8586
/* PART 1: Project input image points and do a blockmean operation */
8586
8587
@@ -8589,16 +8590,16 @@ int gmt_img_project (struct GMT_CTRL *GMT, struct GMT_IMAGE *I, struct GMT_IMAGE
8589
8590
if ((nz = gmt_M_memory (GMT , NULL , O -> header -> size , short int )) == NULL ) return GMT_MEMORY_ERROR ;
8590
8591
/* Cannot do OPENMP yet here since it would require a reduction into an output array (nz) */
8591
8592
8592
- gmt_M_row_loop (GMT , I , row_in ) { /* Loop over the input grid row coordinates */
8593
+ gmt_M_row_loop (GMT , I , row_in ) { /* Loop over the input grid row coordinates */
8593
8594
if (gmt_M_is_rect_graticule (GMT )) y_proj = y_in_proj [row_in ];
8594
- gmt_M_col_loop (GMT , I , row_in , col_in , ij_in ) { /* Loop over the input grid col coordinates */
8595
- if (gmt_M_is_rect_graticule (GMT ))
8595
+ gmt_M_col_loop (GMT , I , row_in , col_in , ij_in ) { /* Loop over the input grid col coordinates */
8596
+ if (gmt_M_is_rect_graticule (GMT ))
8596
8597
x_proj = x_in_proj [col_in ];
8597
8598
else if (inverse )
8598
- gmt_xy_to_geo (GMT , & x_proj , & y_proj , x_in [col_in ], y_in [row_in ]);
8599
+ gmt_xy_to_geo (GMT , & x_proj , & y_proj , x_in [col_in ], y_in [row_in ]);
8599
8600
else {
8600
8601
if (GMT -> current .map .outside (GMT , x_in [col_in ], y_in [row_in ])) continue ; /* Quite possible we are beyond the horizon */
8601
- gmt_geo_to_xy (GMT , x_in [col_in ], y_in [row_in ], & x_proj , & y_proj );
8602
+ gmt_geo_to_xy (GMT , x_in [col_in ], y_in [row_in ], & x_proj , & y_proj );
8602
8603
}
8603
8604
8604
8605
/* Here, (x_proj, y_proj) is the projected grid point. Now find nearest node on the output grid */
@@ -8610,7 +8611,7 @@ int gmt_img_project (struct GMT_CTRL *GMT, struct GMT_IMAGE *I, struct GMT_IMAGE
8610
8611
8611
8612
/* OK, this projected point falls inside the projected grid's rectangular domain */
8612
8613
8613
- ij_out = gmt_M_ijp (O -> header , row_out , col_out ); /* The output node */
8614
+ ij_out = gmt_M_ijp (O -> header , row_out , col_out ); /* The output node */
8614
8615
if (nz [ij_out ] == 0 ) for (b = 0 ; b < nb ; b ++ ) O -> data [nb * ij_out + b ] = 0 ; /* First time, override the initial value */
8615
8616
if (nz [ij_out ] < SHRT_MAX ) { /* Avoid overflow */
8616
8617
for (b = 0 ; b < nb ; b ++ ) {
@@ -8643,36 +8644,39 @@ int gmt_img_project (struct GMT_CTRL *GMT, struct GMT_IMAGE *I, struct GMT_IMAGE
8643
8644
//#pragma omp parallel for private(row_out,y_proj,col_out,ij_out,x_proj,z_int,inv_nz,b) shared(O,GMT,y_out_proj,x_out_proj,inverse,x_out,y_out,I,nz,z_int_bg,nb)
8644
8645
//#endif
8645
8646
for (row_out = 0 ; row_out < (openmp_int )O -> header -> n_rows ; row_out ++ ) { /* Loop over the output grid row coordinates */
8646
- if (gmt_M_is_rect_graticule (GMT )) y_proj = y_out_proj [row_out ];
8647
- gmt_M_col_loop (GMT , O , row_out , col_out , ij_out ) { /* Loop over the output grid col coordinates */
8648
- if (gmt_M_is_rect_graticule (GMT ))
8647
+ if (gmt_M_is_rect_graticule (GMT ))
8648
+ y_proj = y_out_proj [row_out ];
8649
+ gmt_M_col_loop (GMT , O , row_out , col_out , ij_out ) { /* Loop over the output grid col coordinates */
8650
+ if (gmt_M_is_rect_graticule (GMT ))
8649
8651
x_proj = x_out_proj [col_out ];
8650
8652
else if (inverse )
8651
- gmt_geo_to_xy (GMT , x_out [col_out ], y_out [row_out ], & x_proj , & y_proj );
8653
+ gmt_geo_to_xy (GMT , x_out [col_out ], y_out [row_out ], & x_proj , & y_proj );
8652
8654
else {
8653
- gmt_xy_to_geo (GMT , & x_proj , & y_proj , x_out [col_out ], y_out [row_out ]);
8655
+ gmt_xy_to_geo (GMT , & x_proj , & y_proj , x_out [col_out ], y_out [row_out ]);
8654
8656
if (GMT -> current .proj .projection_GMT == GMT_GENPER && GMT -> current .proj .g_outside ) continue ; /* We are beyond the horizon */
8655
8657
8656
8658
/* On 17-Sep-2007 the slack of GMT_CONV4_LIMIT was added to allow for round-off
8657
8659
errors in the grid limits. */
8658
- if (gmt_M_x_is_lon (GMT , GMT_IN ) && !gmt_M_is_dnan (x_proj )) {
8660
+ if (gmt_M_x_is_lon (GMT , GMT_IN ) && !gmt_M_is_dnan (x_proj )) {
8659
8661
while (x_proj < I -> header -> wesn [XLO ] - GMT_CONV4_LIMIT ) x_proj += 360.0 ;
8660
8662
while (x_proj > I -> header -> wesn [XHI ] + GMT_CONV4_LIMIT ) x_proj -= 360.0 ;
8661
8663
}
8662
8664
}
8663
8665
8664
8666
/* Here, (x_proj, y_proj) is the inversely projected grid point. Now find nearest node on the input grid */
8665
8667
8666
- if (gmtlib_bcr_get_img (GMT , I , x_proj , y_proj , z_int )) /* So that nodes outside will have the NaN color */
8667
- for (b = 0 ; b < 4 ; b ++ ) z_int [b ] = z_int_bg [b ];
8668
+ if (gmtlib_bcr_get_img (GMT , I , x_proj , y_proj , z_int )) /* So that nodes outside will have the NaN color */
8669
+ for (b = 0 ; b < 4 ; b ++ )
8670
+ z_int [b ] = z_int_bg [b ];
8668
8671
8669
8672
if (!GMT -> common .n .antialias || nz [ij_out ] < 2 ) /* Just use the interpolated value */
8670
- for (b = 0 ; b < nb ; b ++ ) O -> data [nb * ij_out + b ] = z_int [b ];
8673
+ for (b = 0 ; b < nb ; b ++ )
8674
+ O -> data [nb * ij_out + b ] = z_int [b ];
8671
8675
else { /* Weighted average between blockmean'ed and interpolated values */
8672
8676
inv_nz = 1.0 / nz [ij_out ];
8673
8677
for (b = 0 ; b < nb ; b ++ ) {
8674
8678
rgb [b ] = ((double )nz [ij_out ] * O -> data [nb * ij_out + b ] + z_int [b ] * inv_nz ) / (nz [ij_out ] + inv_nz );
8675
- O -> data [nb * ij_out + b ] = (unsigned char ) lrint (gmt_M_0_255_truncate (rgb [b ]));
8679
+ O -> data [nb * ij_out + b ] = (unsigned char ) lrint (gmt_M_0_255_truncate (rgb [b ]));
8676
8680
}
8677
8681
}
8678
8682
}
@@ -8681,20 +8685,20 @@ int gmt_img_project (struct GMT_CTRL *GMT, struct GMT_IMAGE *I, struct GMT_IMAGE
8681
8685
/* Time to clean up our mess */
8682
8686
8683
8687
if (!in ) {
8684
- gmt_M_free (GMT , x_in );
8685
- gmt_M_free (GMT , y_in );
8688
+ gmt_M_free (GMT , x_in );
8689
+ gmt_M_free (GMT , y_in );
8686
8690
}
8687
8691
if (!out ) {
8688
- gmt_M_free (GMT , x_out );
8689
- gmt_M_free (GMT , y_out );
8692
+ gmt_M_free (GMT , x_out );
8693
+ gmt_M_free (GMT , y_out );
8690
8694
}
8691
8695
if (gmt_M_is_rect_graticule (GMT )) {
8692
- gmt_M_free (GMT , x_in_proj );
8693
- gmt_M_free (GMT , y_in_proj );
8694
- gmt_M_free (GMT , x_out_proj );
8695
- gmt_M_free (GMT , y_out_proj );
8696
+ gmt_M_free (GMT , x_in_proj );
8697
+ gmt_M_free (GMT , y_in_proj );
8698
+ gmt_M_free (GMT , x_out_proj );
8699
+ gmt_M_free (GMT , y_out_proj );
8696
8700
}
8697
- if (GMT -> common .n .antialias ) gmt_M_free (GMT , nz );
8701
+ if (GMT -> common .n .antialias ) gmt_M_free (GMT , nz );
8698
8702
8699
8703
return (GMT_NOERROR );
8700
8704
}
0 commit comments