+ 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_ERROR(ctx, IMAGE_ERROR_INVALID_DIMENSIONS, "Invalid image dimensions (%ux%u)", cols, rows);
+ return NULL;
+ }
+ img->pixels = pixels;
+ img->cols = cols;
+ img->rows = rows;
+ img->pixel_size = img->channels = flags_to_pixel_size(flags);
+ img->row_size = row_size;
+ img->row_pixels_size = cols * img->pixel_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_context *ctx 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 = img->channels = src->pixel_size;
+ img->row_size = src->row_size;
+ img->row_pixels_size = cols * src->pixel_size;
+ img->image_size = src->row_size * rows;
+ img->flags = src->flags & IMAGE_NEW_FLAGS;
+ img->flags |= IMAGE_GAPS_PROTECTED;
+ return img;