@@ -194,11 +194,7 @@ namespace
194194 void fillAlphaChannel (Image *img)
195195 {
196196 CAGE_ASSERT (img->channels () == 4 );
197- const uint32 w = img->width ();
198- const uint32 h = img->height ();
199- for (uint32 y = 0 ; y < h; y++)
200- for (uint32 x = 0 ; x < w; x++)
201- img->value (x, y, 3 , 1 );
197+ imageFill (img, 3 , 1 );
202198 }
203199
204200 void overrideColorConfig (AlphaModeEnum alpha, GammaSpaceEnum gamma)
@@ -216,6 +212,13 @@ namespace
216212
217213 void performDownscale (const uint32 downscale, bool volume3D)
218214 {
215+ const auto &update = [&](uint32 w)
216+ {
217+ w = max (w / downscale, 1u );
218+ w = (w + 3 ) & ~3u ; // round up to next multiple of 4
219+ return w;
220+ };
221+
219222 if (volume3D)
220223 { // downscale image as a whole
221224 CAGE_LOG (SeverityEnum::Info, " assetProcessor" , Stringizer () + " downscaling whole image (3D)" );
@@ -225,7 +228,7 @@ namespace
225228 { // downscale each image separately
226229 CAGE_LOG (SeverityEnum::Info, " assetProcessor" , Stringizer () + " downscaling each slice separately" );
227230 for (auto &it : images.parts )
228- imageResize (+it.image , max (it.image ->width () / downscale, 1u ), max (it.image ->height () / downscale, 1u ));
231+ imageResize (+it.image , update (it.image ->width ()), update (it.image ->height ()));
229232 }
230233 }
231234
@@ -355,8 +358,9 @@ namespace
355358 for (const auto &layer : face.second )
356359 size += layer.second ->data .size ();
357360
361+ const uint32 faces = level.second .size ();
358362 const uint32 layers = level.second .at (0 ).size ();
359- ser << Vec3i (level.second .at (0 ).at (0 )->resolution , layers);
363+ ser << Vec3i (level.second .at (0 ).at (0 )->resolution , faces * layers);
360364 ser << size;
361365 for (const auto &face : level.second )
362366 for (const auto &layer : face.second )
@@ -386,8 +390,9 @@ namespace
386390 for (const auto &layer : face.second )
387391 size += layer.second ->rawViewU8 ().size ();
388392
393+ const uint32 faces = level.second .size ();
389394 const uint32 layers = level.second .at (0 ).size ();
390- ser << Vec3i (level.second .at (0 ).at (0 )->resolution (), layers);
395+ ser << Vec3i (level.second .at (0 ).at (0 )->resolution (), faces * layers);
391396 ser << size;
392397 for (const auto &face : level.second )
393398 for (const auto &layer : face.second )
0 commit comments