Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions src/grdimage.c
Original file line number Diff line number Diff line change
Expand Up @@ -1241,9 +1241,13 @@ EXTERN_MSC int GMT_grdimage (void *V_API, int mode, void *args) {
done = true; /* Only doing the loop once here since no -Q */
}
else { /* Dealing with images, three grids, and/or PostScript colormasking */
for (row = 0, byte = colormask_offset; row < n_rows; row++) { /* March along scanlines */
/* Because we fill bitimage in via scanlines, there are complications when the image has reversed x and/or y direction (normal_x, normal_y are false) */
for (row = 0, byte = colormask_offset; row < n_rows; row++) { /* March along scanlines in the output bitimage */
kk = gmt_M_ijpgi (header_work, actual_row[row], 0); /* Start pixel of this row */
if (Ctrl->D.active && row == 0 || !normal_y) node_RGBA = kk; /* First time per row equals 'node', afterwards it grows alone */
if (Ctrl->D.active) { /* Must set pixel node node_RGBA */
if ((row == 0 || !normal_y || !normal_x)) node_RGBA = kk; /* First time per row equals 'node', afterwards it grows alone, except when one of normal_? is false */
if (!normal_x) node_RGBA += (n_columns-1)*Img_proj->header->n_bands; /* Go to last column instead of first column */
}
for (col = 0; col < n_columns; col++) { /* Compute rgb for each pixel along this scanline */
node = kk + actual_col[col];
if (rgb_from_z) { /* Got a single grid and need to look up color via the CPT */
Expand All @@ -1255,7 +1259,6 @@ EXTERN_MSC int GMT_grdimage (void *V_API, int mode, void *args) {
rgb[0] = gmt_M_is255 (Img_proj->data[node_RGBA++]);
else {
for (k = 0; k < 3; k++) rgb[k] = gmt_M_is255 (Img_proj->data[node_RGBA++]);
//if (Img_proj->header->n_bands == 4) node_RGBA++; /* Must skip the alpha transparency byte in the image */
if (Img_proj->header->n_bands == 4) {
/* Here we assume background color is white, hence t * 1.
But what would it take to have a user selected bg color? */
Expand All @@ -1267,6 +1270,7 @@ EXTERN_MSC int GMT_grdimage (void *V_API, int mode, void *args) {
node_RGBA++;
}
}
if (!normal_x) node_RGBA -= 2*Img_proj->header->n_bands; /* Go to start of previous column instead of where we are (start of next) */
}
else /* Got three grids with red, green, blue values */
index = grdimage_set_rgb_three_grids (Grid_proj, node, NaN_rgb, rgb);
Expand All @@ -1291,8 +1295,7 @@ EXTERN_MSC int GMT_grdimage (void *V_API, int mode, void *args) {
rgb_used[(i_rgb[0]*256 + i_rgb[1])*256+i_rgb[2]] = true;
}
}

if (!n_grids) node_RGBA += header_work->n_bands * (header_work->pad[XLO] + header_work->pad[XHI]); /* Increment the node index for the image row */
if (!n_grids && normal_x) node_RGBA += header_work->n_bands * (header_work->pad[XLO] + header_work->pad[XHI]); /* Increment the node index for the image row unless reverse x dir */
}
}
if (rgb_cube_scan) { /* Check that we found an unused r/g/b value so colormasking will work as advertised */
Expand Down