27 static constexpr
const char*
name =
"png";
33 PNG(amrex::Vector<amrex::Geometry>& _geom) :
IC(_geom) {}
44 FILE* fp = std::fopen(
filename.c_str(),
"rb");
48 png_structp png = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
51 png_infop info = png_create_info_struct(png);
59 png_read_info(png, info);
61 png_width = png_get_image_width(png, info);
67 png_set_strip_16(png);
70 png_set_palette_to_rgb(png);
73 png_set_expand_gray_1_2_4_to_8(png);
75 if (png_get_valid(png, info, PNG_INFO_tRNS))
76 png_set_tRNS_to_alpha(png);
81 png_set_filler(png, 0xFF, PNG_FILLER_AFTER);
85 png_set_gray_to_rgb(png);
87 png_read_update_info(png, info);
93 row_pointers[y] = (png_byte*)malloc(png_get_rowbytes(png, info));
100 png_destroy_read_struct(&png, &info, NULL);
111 amrex::Box domain =
geom[lev].Domain();
120 amrex::IndexType type = a_field[lev]->ixType();
121 domain.convert(type);
126 for (amrex::MFIter mfi(*a_field[lev], amrex::TilingIfNotGPU()); mfi.isValid(); ++mfi)
129 if (type == amrex::IndexType::TheNodeType()) bx = mfi.grownnodaltilebox();
130 if (type == amrex::IndexType::TheCellType()) bx = mfi.growntilebox();
134 amrex::Array4<Set::Scalar>
const& field = a_field[lev]->array(mfi);
135 amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE(
int i,
int j,
int k)
139 if (type == amrex::IndexType::TheNodeType())
141 x(0) = domlo(0) + ((amrex::Real)(i)) *
geom[lev].CellSize()[0];
142 x(1) = domlo(1) + ((amrex::Real)(j)) *
geom[lev].CellSize()[1];
144 else if (type == amrex::IndexType::TheCellType())
146 x(0) = domlo(0) + ((amrex::Real)(i)+0.5) *
geom[lev].CellSize()[0];
147 x(1) = domlo(1) + ((amrex::Real)(j)+0.5) *
geom[lev].CellSize()[1];
153 if (
fit == Fit::Stretch)
155 ximg(0) = (x(0) - domlo(0)) / (domhi(0) - domlo(0));
156 ximg(1) = (x(1) - domlo(1)) / (domhi(1) - domlo(1));
158 else if (
fit == Fit::FitWidth)
161 ximg(0) = (x(0) - domlo(0)) / (domhi(0) - domlo(0));
162 ximg(1) = (x(1) - domlo(1)) / (domhi(1) - domlo(1));
163 ximg(1) -= 0.5 - 0.5 / aspect_ratio;
164 ximg(1) *= aspect_ratio;
166 else if (
fit == Fit::FitHeight)
169 ximg(0) = (x(0) - domlo(0)) / (domhi(0) - domlo(0));
170 ximg(1) = (x(1) - domlo(1)) / (domhi(1) - domlo(1));
171 ximg(0) -= 0.5 - 0.5 / aspect_ratio;
172 ximg(0) *= aspect_ratio;
174 else if (
fit == Fit::Coord)
180 ximg(0) = std::min(ximg(0), 1.0); ximg(1) = std::min(ximg(1), 1.0);
181 ximg(0) = std::max(ximg(0), 0.0); ximg(1) = std::max(ximg(1), 0.0);
183 ximg(0) *= img_width;
184 ximg(1) *= img_height;
186 int I = (int)(ximg(0));
187 int J = (int)(ximg(1));
189 Set::Scalar x1 = I * img_dx, x2 = (I + 1) * img_dx;
190 Set::Scalar y1 = J * img_dy, y2 = (J + 1) * img_dy;
208 (fQ11 * (x2 - ximg(0)) * (y2 - ximg(1)) +
209 fQ21 * (ximg(0) - x1) * (y2 - ximg(1)) +
210 fQ12 * (x2 - ximg(0)) * (ximg(1) - y1) +
211 fQ22 * (ximg(0) - x1) * (ximg(1) - y1)) / (img_dx * img_dy);
221 field(i, j, k) = fQ11 + (fQ12 - fQ11) * (ximg(1) - y1);
230 field(i, j, k) = fQ11 + (fQ21 - fQ11) * (ximg(0) - x1);
237 field(i, j, k) = fQ11;
241 field(i, j, k) = 0.0;
244 if (field.nComp() > 1) field(i, j, k, 1) = 1.0 - field(i, j, k, 0);
248 a_field[lev]->FillBoundary();
279 std::string
fit =
"stretch";
281 if (
fit ==
"stretch") value.
fit = Fit::Stretch;
282 else if (
fit ==
"fitheight") value.
fit = Fit::FitHeight;
283 else if (
fit ==
"fitwidth") value.
fit = Fit::FitWidth;
284 else if (
fit ==
"coord")
286 value.
fit = Fit::Coord;
290 else Util::Abort(
INFO,
"Invalid value for png fit - should be stretch/fitheight/fitwidth/coord but received '",
fit,
"'");