27 if(
data.empty() || iy >= nfity){
31 data.push_back(std::make_unique<std::array<png_byte, kTotBytes>>());
48 for(
int newdim = kArenaSize/2; newdim >= 1; newdim /= 2){
49 const int olddim = newdim*2;
56 for(
int y = 0;
y < newdim; ++
y){
57 for(
int x = 0;
x < newdim; ++
x){
60 for(
int dy = 0; dy <= 1; ++dy){
61 for(
int dx = 0; dx <= 1; ++dx){
62 const int i = (
y*2+dy)*olddim + (
x*2+dx);
67 for(
int c = 0; c < 3; ++c){
74 const int i =
y*newdim+
x;
75 for(
int c = 0; c < 3; ++c) dest[i*4+c] = tota > 0 ? std::min(totc[c]/tota, 255) : 0;
76 dest[i*4+3] = std::min(tota/2, 255);
81 dest += 4*newdim*newdim;
90 long unsigned int nbytes)
92 FILE*
fout = (FILE*)png_get_io_ptr(png_ptr);
93 const size_t ret = fwrite(buffer, 1, nbytes, fout);
96 std::cout <<
"Error writing " << nbytes <<
" bytes of png -- returned " << ret << std::endl;
110 if(imgIdx >=
int(
data.size())){
111 std::cout <<
"Bad index " << imgIdx << std::endl;
116 std::lock_guard<std::mutex> guard(*
fMIPLocks[imgIdx]);
126 if(src + 4*dim*dim - 1 > &(*
data[imgIdx]).back()){
127 std::cout <<
"Bad mipmap size " << dim << std::endl;
131 png_struct_def* png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
133 auto info_ptr = png_create_info_struct(png_ptr);
138 png_set_compression_level(png_ptr, 1);
139 png_set_compression_strategy(png_ptr, Z_RLE);
141 png_set_IHDR(png_ptr, info_ptr, dim, dim,
142 8, PNG_COLOR_TYPE_RGBA, PNG_INTERLACE_NONE,
143 PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
145 std::vector<png_byte*> pdatas(dim);
146 for(
int i = 0; i < dim; ++i) pdatas[i] = src + i*dim*4;
148 png_set_rows(png_ptr, info_ptr, pdatas.data());
158 png_write_png(png_ptr, info_ptr, PNG_TRANSFORM_IDENTITY, NULL);
160 png_destroy_write_struct(&png_ptr, &info_ptr);
173 for(
unsigned int d = 0; d < bytes.
data.size(); ++d){
177 for(
int y = 0;
y < blockSize && !filled; ++
y){
178 for(
int x = 0;
x < blockSize; ++
x){
179 if(
bytes(d, ix*blockSize+
x, iy*blockSize+
y, 3) > 0){
185 if(filled) ++nfilled;
void webevd_png_write_fn(png_struct_def *png_ptr, png_byte *buffer, long unsigned int nbytes)
process_name opflash particleana ie x
void webevd_png_flush_fn(png_struct_def *png_ptr)
std::vector< std::unique_ptr< std::array< png_byte, kTotBytes > > > data
static constexpr int MipMapOffset(int dim, int maxdim)
process_name opflash particleana ie ie y
void AnalyzeArena(const PNGArena &bytes)
std::vector< bool > fHasMIP
PNGArena(const std::string &name)
void WritePNGBytes(FILE *fout, int imgIdx, int dim)
byte bytes
Alias for common language habits.
std::vector< std::mutex * > fMIPLocks
BEGIN_PROLOG could also be cout