Skip to content

Commit dd1a02f

Browse files
joa-quimseisman
andauthored
Commit the files that should have gone into #8612 (#8613)
* Commit the files that should have gone into #8612 (Fix the variable transparency case that was broken by the #8255 commit.) * Add the two modified tests. * Update baseline images --------- Co-authored-by: Dongdong Tian <[email protected]>
1 parent 548e6ed commit dd1a02f

File tree

5 files changed

+115
-90
lines changed

5 files changed

+115
-90
lines changed

src/gmt_map.c

Lines changed: 44 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -8496,7 +8496,7 @@ int gmt_grd_project (struct GMT_CTRL *GMT, struct GMT_GRID *I, struct GMT_GRID *
84968496
}
84978497

84988498
/*! . */
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) {
85008500
/* Generalized image projection that deals with both interpolation and averaging effects.
85018501
* It requires the input image to have 2 boundary rows/cols so that the bcr
85028502
* 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
85308530

85318531
/* Only input image MUST have at least 2 rows/cols padding */
85328532
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");
85348534
return GMT_RUNTIME_ERROR;
85358535
}
85368536

@@ -8552,22 +8552,22 @@ int gmt_img_project (struct GMT_CTRL *GMT, struct GMT_IMAGE *I, struct GMT_IMAGE
85528552
}
85538553

85548554
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;
85598559
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);
85648564
}
85658565
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]);
85698569
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]);
85718571
if (gmt_M_x_is_lon (GMT, GMT_IN) && !gmt_M_is_dnan (x_out_proj[col_out])) {
85728572
while (x_out_proj[col_out] < I->header->wesn[XLO] - GMT_CONV4_LIMIT) x_out_proj[col_out] += 360.0;
85738573
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
85808580
gmt_M_grd_loop (GMT, O, row_out, col_out, ij_out) /* So that nodes outside will have the NaN color */
85818581
for (b = 0; b < nb; b++) O->data[nb*ij_out+b] = gmt_M_u255 (GMT->current.setting.color_patch[GMT_NAN][b]);
85828582
#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]);
85848585

85858586
/* PART 1: Project input image points and do a blockmean operation */
85868587

@@ -8589,16 +8590,16 @@ int gmt_img_project (struct GMT_CTRL *GMT, struct GMT_IMAGE *I, struct GMT_IMAGE
85898590
if ((nz = gmt_M_memory (GMT, NULL, O->header->size, short int)) == NULL) return GMT_MEMORY_ERROR;
85908591
/* Cannot do OPENMP yet here since it would require a reduction into an output array (nz) */
85918592

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 */
85938594
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))
85968597
x_proj = x_in_proj[col_in];
85978598
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]);
85998600
else {
86008601
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);
86028603
}
86038604

86048605
/* 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
86108611

86118612
/* OK, this projected point falls inside the projected grid's rectangular domain */
86128613

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 */
86148615
if (nz[ij_out] == 0) for (b = 0; b < nb; b++) O->data[nb*ij_out+b] = 0; /* First time, override the initial value */
86158616
if (nz[ij_out] < SHRT_MAX) { /* Avoid overflow */
86168617
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
86438644
//#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)
86448645
//#endif
86458646
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))
86498651
x_proj = x_out_proj[col_out];
86508652
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);
86528654
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]);
86548656
if (GMT->current.proj.projection_GMT == GMT_GENPER && GMT->current.proj.g_outside) continue; /* We are beyond the horizon */
86558657

86568658
/* On 17-Sep-2007 the slack of GMT_CONV4_LIMIT was added to allow for round-off
86578659
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)) {
86598661
while (x_proj < I->header->wesn[XLO] - GMT_CONV4_LIMIT) x_proj += 360.0;
86608662
while (x_proj > I->header->wesn[XHI] + GMT_CONV4_LIMIT) x_proj -= 360.0;
86618663
}
86628664
}
86638665

86648666
/* Here, (x_proj, y_proj) is the inversely projected grid point. Now find nearest node on the input grid */
86658667

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];
86688671

86698672
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];
86718675
else { /* Weighted average between blockmean'ed and interpolated values */
86728676
inv_nz = 1.0 / nz[ij_out];
86738677
for (b = 0; b < nb; b++) {
86748678
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]));
86768680
}
86778681
}
86788682
}
@@ -8681,20 +8685,20 @@ int gmt_img_project (struct GMT_CTRL *GMT, struct GMT_IMAGE *I, struct GMT_IMAGE
86818685
/* Time to clean up our mess */
86828686

86838687
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);
86868690
}
86878691
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);
86908694
}
86918695
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);
86968700
}
8697-
if (GMT->common.n.antialias) gmt_M_free (GMT, nz);
8701+
if (GMT->common.n.antialias) gmt_M_free(GMT, nz);
86988702

86998703
return (GMT_NOERROR);
87008704
}

0 commit comments

Comments
 (0)