- dup->image = img;
- for (dup->tab_cols = 0; (uns)(2 << dup->tab_cols) < img->cols && dup->tab_cols < image_dup_tab_limit; dup->tab_cols++);
- for (dup->tab_rows = 0; (uns)(2 << dup->tab_rows) < img->rows && dup->tab_rows < image_dup_tab_limit; dup->tab_rows++);
- dup->tab_pixels = mp_alloc(pool, dup->tab_size = (12 << (dup->tab_cols + dup->tab_rows)));
+ /* Clone image */
+ if (same_size_compare)
+ {
+ if (!image_init_matrix(ctx->ic, &dup->image, ptr, img->cols, img->rows, img->cols * 3, COLOR_SPACE_RGB))
+ return 0;
+ uint size = img->rows * img->cols * 3;
+ ptr += ALIGN_TO(size, CPU_STRUCT_ALIGN);
+ byte *s = img->pixels;
+ byte *d = dup->image.pixels;
+ for (uint row = img->rows; row--; )
+ {
+ memcpy(d, s, img->row_pixels_size);
+ d += dup->image.row_size;
+ s += img->row_size;
+ }
+ }
+ else
+ {
+ dup->image.cols = img->cols;
+ dup->image.rows = img->rows;
+ }
+
+ for (dup->tab_cols = 0; (uint)(2 << dup->tab_cols) < img->cols && dup->tab_cols < ctx->qtree_limit; dup->tab_cols++);
+ for (dup->tab_rows = 0; (uint)(2 << dup->tab_rows) < img->rows && dup->tab_rows < ctx->qtree_limit; dup->tab_rows++);