+struct image *
+image_init_matrix(struct image_thread *it, struct image *img, byte *pixels, uns cols, uns rows, uns row_size, uns flags)
+{
+ DBG("image_init_matrix(img=%p pixels=%p cols=%u rows=%u row_size=%u flags=0x%x)", img, pixels, cols, rows, row_size, flags);
+ if (unlikely(!image_dimensions_valid(cols, rows)))
+ {
+ image_thread_err_format(it, IMAGE_ERR_INVALID_DIMENSIONS, "Invalid image dimensions (%ux%u)", cols, rows);
+ return NULL;
+ }
+ img->pixels = pixels;
+ img->cols = cols;
+ img->rows = rows;
+ img->pixel_size = flags_to_pixel_size(flags);
+ img->row_size = row_size;
+ img->image_size = rows * row_size;
+ img->flags = flags & (IMAGE_NEW_FLAGS | IMAGE_GAPS_PROTECTED);
+ return img;
+}
+
+struct image *
+image_init_subimage(struct image_thread *it UNUSED, struct image *img, struct image *src, uns left, uns top, uns cols, uns rows)
+{
+ DBG("image_init_subimage(img=%p src=%p left=%u top=%u cols=%u rows=%u)", img, src, left, top, cols, rows);
+ ASSERT(left + cols <= src->cols && top + rows <= src->rows);
+ img->pixels = src->pixels + left * src->pixel_size + top * src->row_size;
+ img->cols = cols;
+ img->rows = rows;
+ img->pixel_size = src->pixel_size;
+ img->row_size = src->row_size;
+ img->image_size = src->row_size * rows;
+ img->flags = src->flags & IMAGE_NEW_FLAGS;
+ img->flags |= IMAGE_GAPS_PROTECTED;
+ return img;
+}
+