31 PNG(amrex::Vector<amrex::Geometry>& _geom) :
IC(_geom) {}
42 FILE* fp = std::fopen(
filename.c_str(),
"rb");
46 png_structp png = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
49 png_infop info = png_create_info_struct(png);
57 png_read_info(png, info);
59 png_width = png_get_image_width(png, info);
65 png_set_strip_16(png);
68 png_set_palette_to_rgb(png);
71 png_set_expand_gray_1_2_4_to_8(png);
73 if (png_get_valid(png, info, PNG_INFO_tRNS))
74 png_set_tRNS_to_alpha(png);
79 png_set_filler(png, 0xFF, PNG_FILLER_AFTER);
83 png_set_gray_to_rgb(png);
85 png_read_update_info(png, info);
91 row_pointers[y] = (png_byte*)malloc(png_get_rowbytes(png, info));
98 png_destroy_read_struct(&png, &info, NULL);
109 amrex::Box domain =
geom[lev].Domain();
118 amrex::IndexType type = a_field[lev]->ixType();
119 domain.convert(type);
124 for (amrex::MFIter mfi(*a_field[lev], amrex::TilingIfNotGPU()); mfi.isValid(); ++mfi)
127 if (type == amrex::IndexType::TheNodeType()) bx = mfi.grownnodaltilebox();
128 if (type == amrex::IndexType::TheCellType()) bx = mfi.growntilebox();
132 amrex::Array4<Set::Scalar>
const& field = a_field[lev]->array(mfi);
133 amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE(
int i,
int j,
int k)
137 if (type == amrex::IndexType::TheNodeType())
139 x(0) = domlo(0) + ((amrex::Real)(i)) *
geom[lev].CellSize()[0];
140 x(1) = domlo(1) + ((amrex::Real)(j)) *
geom[lev].CellSize()[1];
142 else if (type == amrex::IndexType::TheCellType())
144 x(0) = domlo(0) + ((amrex::Real)(i)+0.5) *
geom[lev].CellSize()[0];
145 x(1) = domlo(1) + ((amrex::Real)(j)+0.5) *
geom[lev].CellSize()[1];
151 if (
fit == Fit::Stretch)
153 ximg(0) = (x(0) - domlo(0)) / (domhi(0) - domlo(0));
154 ximg(1) = (x(1) - domlo(1)) / (domhi(1) - domlo(1));
156 else if (
fit == Fit::FitWidth)
159 ximg(0) = (x(0) - domlo(0)) / (domhi(0) - domlo(0));
160 ximg(1) = (x(1) - domlo(1)) / (domhi(1) - domlo(1));
161 ximg(1) -= 0.5 - 0.5 / aspect_ratio;
162 ximg(1) *= aspect_ratio;
164 else if (
fit == Fit::FitHeight)
167 ximg(0) = (x(0) - domlo(0)) / (domhi(0) - domlo(0));
168 ximg(1) = (x(1) - domlo(1)) / (domhi(1) - domlo(1));
169 ximg(0) -= 0.5 - 0.5 / aspect_ratio;
170 ximg(0) *= aspect_ratio;
172 else if (
fit == Fit::Coord)
178 ximg(0) = std::min(ximg(0), 1.0); ximg(1) = std::min(ximg(1), 1.0);
179 ximg(0) = std::max(ximg(0), 0.0); ximg(1) = std::max(ximg(1), 0.0);
181 ximg(0) *= img_width;
182 ximg(1) *= img_height;
184 int I = (int)(ximg(0));
185 int J = (int)(ximg(1));
187 Set::Scalar x1 = I * img_dx, x2 = (I + 1) * img_dx;
188 Set::Scalar y1 = J * img_dy, y2 = (J + 1) * img_dy;
206 (fQ11 * (x2 - ximg(0)) * (y2 - ximg(1)) +
207 fQ21 * (ximg(0) - x1) * (y2 - ximg(1)) +
208 fQ12 * (x2 - ximg(0)) * (ximg(1) - y1) +
209 fQ22 * (ximg(0) - x1) * (ximg(1) - y1)) / (img_dx * img_dy);
219 field(i, j, k) = fQ11 + (fQ12 - fQ11) * (ximg(1) - y1);
228 field(i, j, k) = fQ11 + (fQ21 - fQ11) * (ximg(0) - x1);
235 field(i, j, k) = fQ11;
239 field(i, j, k) = 0.0;
242 if (field.nComp() > 1) field(i, j, k, 1) = 1.0 - field(i, j, k, 0);
246 a_field[lev]->FillBoundary();
277 std::string
fit =
"stretch";
279 if (
fit ==
"stretch") value.
fit = Fit::Stretch;
280 else if (
fit ==
"fitheight") value.
fit = Fit::FitHeight;
281 else if (
fit ==
"fitwidth") value.
fit = Fit::FitWidth;
282 else if (
fit ==
"coord")
284 value.
fit = Fit::Coord;
288 else Util::Abort(
INFO,
"Invalid value for png fit - should be stretch/fitheight/fitwidth/coord but received '",
fit,
"'");