static void sample_data(texgz_tex_t* src, texgz_tex_t* dst, int x, int y, int i, int j, int m, int n, double latT, double lonL, double latB, double lonR) { assert(src); assert(dst); LOGD("debug x=%i, y=%i, i=%i, j=%i, m=%i, n=%i, latT=%lf, lonL=%lf, latB=%lf, lonR=%lf", x, y, i, j, m, n, latT, lonL, latB, lonR); // make a dummy tile nedgz_tile_t* tile = nedgz_tile_new(x, y, 9); if(tile == NULL) { return; } // compute sample coords double lat; double lon; tile_coord(tile, i, j, m, n, &lat, &lon); // compute u, v float u = (float) ((lon - lonL)/(lonR - lonL)); float v = (float) ((lat - latT)/(latB - latT)); // interpolate color unsigned char r; unsigned char g; unsigned char b; interpolatec(src, u, v, &r, &g, &b); // store color unsigned char* pixels = dst->pixels; int stride = dst->stride; int bpp = texgz_tex_bpp(dst); int idx = m*stride*bpp + n*bpp; pixels[idx + 0] = r; pixels[idx + 1] = g; pixels[idx + 2] = b; nedgz_tile_delete(&tile); }
static int sample_subtile(nedgz_tile_t* tile, int i, int j, pak_file_t* pak) { assert(tile); LOGD("debug i=%i, j=%i", i, j); texgz_tex_t* tex = texgz_tex_new(SUBTILE_SIZE, SUBTILE_SIZE, SUBTILE_SIZE, SUBTILE_SIZE, TEXGZ_SHORT, TEXGZ_LUMINANCE, NULL); if(tex == NULL) { return 0; } int m; int n; for(m = 0; m < SUBTILE_SIZE; ++m) { for(n = 0; n < SUBTILE_SIZE; ++n) { double lat; double lon; tile_coord(tile, i, j, m, n, &lat, &lon); // flt_cc most likely place to find sample // At edges of range a subtile may not be // fully covered by flt_xx short height; if((flt_cc && flt_tile_sample(flt_cc, lat, lon, &height)) || (flt_tc && flt_tile_sample(flt_tc, lat, lon, &height)) || (flt_bc && flt_tile_sample(flt_bc, lat, lon, &height)) || (flt_cl && flt_tile_sample(flt_cl, lat, lon, &height)) || (flt_cr && flt_tile_sample(flt_cr, lat, lon, &height)) || (flt_tl && flt_tile_sample(flt_tl, lat, lon, &height)) || (flt_bl && flt_tile_sample(flt_bl, lat, lon, &height)) || (flt_tr && flt_tile_sample(flt_tr, lat, lon, &height)) || (flt_br && flt_tile_sample(flt_br, lat, lon, &height))) { short* pixels = (short*) tex->pixels; pixels[m*SUBTILE_SIZE + n] = height; } else { short* pixels = (short*) tex->pixels; pixels[m*SUBTILE_SIZE + n] = NEDGZ_NODATA; } } } // j=dx, i=dy char fname[256]; snprintf(fname, 256, "%i_%i", j, i); pak_file_writek(pak, fname); texgz_tex_exportf(tex, pak->f); texgz_tex_delete(&tex); return 1; }