MCPcopy Create free account
hub / github.com/ARM-software/astc-encoder / compute_averages

Function compute_averages

Source/astcenc_entry.cpp:1056–1108  ·  view source on GitHub ↗

* @brief Compute regional averages in an image. * * This function can be called by multiple threads, but only after a single * thread calls the setup function @c init_compute_averages(). * * Results are written back into @c img->input_alpha_averages. * * @param[out] ctx The context. * @param ag The average and variance arguments created during setup. */

Source from the content-addressed store, hash-verified

1054 * @param ag The average and variance arguments created during setup.
1055 */
1056static void compute_averages(
1057 astcenc_context& ctx,
1058 const avg_args &ag
1059) {
1060 pixel_region_args arg = ag.arg;
1061 arg.work_memory = new vfloat4[ag.work_memory_size];
1062
1063 size_t size_x = ag.img_size_x;
1064 size_t size_y = ag.img_size_y;
1065 size_t size_z = ag.img_size_z;
1066
1067 size_t step_xy = ag.blk_size_xy;
1068 size_t step_z = ag.blk_size_z;
1069
1070 size_t tasks_y = (size_y + step_xy - 1) / step_xy;
1071
1072 // All threads run this processing loop until there is no work remaining
1073 while (true)
1074 {
1075 size_t count;
1076 size_t base = ctx.manage_avg.get_task_assignment(16, count);
1077 if (!count)
1078 {
1079 break;
1080 }
1081
1082 for (size_t i = base; i < base + count; i++)
1083 {
1084 size_t z_task = i / tasks_y;
1085 size_t y_task = i - (z_task * tasks_y);
1086
1087 size_t z = z_task * step_z;
1088 size_t y = y_task * step_xy;
1089
1090 arg.size_z = astc::min(step_z, size_z - z);
1091 arg.offset_z = z;
1092
1093 arg.size_y = astc::min(step_xy, size_y - y);
1094 arg.offset_y = y;
1095
1096 for (size_t x = 0; x < size_x; x += step_xy)
1097 {
1098 arg.size_x = astc::min(step_xy, size_x - x);
1099 arg.offset_x = x;
1100 compute_pixel_region_variance(ctx.context, arg);
1101 }
1102 }
1103
1104 ctx.manage_avg.complete_task_assignment(count);
1105 }
1106
1107 delete[] arg.work_memory;
1108}
1109
1110#endif
1111

Callers 1

astcenc_compress_imageFunction · 0.85

Calls 4

get_task_assignmentMethod · 0.80
minFunction · 0.70

Tested by

no test coverage detected