4 size_t rgb_elements,
size_t patch_elements,
5 size_t height,
size_t width,
size_t patch)
7 if (!height || height > 1024 || !width || width > 1024 ||
8 !patch || patch > 32 || height % patch || width % patch)
10 const size_t elements = height * width * 3;
11 if (rgb_elements != elements || patch_elements != elements)
13 const uintptr_t in = (uintptr_t)rgb, out = (uintptr_t)patches;
14 const size_t bytes = elements *
sizeof(*patches);
15 if (!rgb || !patches || out %
sizeof(*patches) ||
16 in > UINTPTR_MAX - elements || out > UINTPTR_MAX - bytes ||
17 (in < out + bytes && out < in + elements))
21 for (
unsigned i = 0; i < 256; ++i) {
22 const float unit = (float)i / 255.0f;
26 for (
size_t y = 0; y < height; y += patch)
27 for (
size_t x = 0; x < width; x += patch)
28 for (
size_t c = 0; c < 3; ++c)
29 for (
size_t dy = 0; dy < patch; ++dy)
30 for (
size_t dx = 0; dx < patch; ++dx)
31 *patches++ = lut[rgb[((y + dy) * width + x + dx) * 3 + c]];
int ck_image_patchify_rgb8_bf16_checked(const uint8_t *rgb, uint16_t *patches, size_t rgb_elements, size_t patch_elements, size_t height, size_t width, size_t patch)