struct image_conv_options image_conv_defaults = {
.flags = IMAGE_CONV_COPY_ALPHA | IMAGE_CONV_FILL_ALPHA | IMAGE_CONV_APPLY_ALPHA,
.background = { .color_space = COLOR_SPACE_GRAYSCALE } };
-
+
/* Grayscale <-> RGB */
#define IMAGE_WALK_PREFIX(x) walk_##x
case COLOR_SPACE_CMYK:
switch (src->flags & IMAGE_CHANNELS_FORMAT)
{
- case COLOR_SPACE_RGB:
+ case COLOR_SPACE_RGB:
if (dest->pixel_size == 4)
{
image_conv_rgb_n_to_cmyk_4(dest, src);
{
for (uns x = 0; x < (uns)(1 << i); x++)
{
- pixels_average(d, s, s + line_size);
+ pixels_average(d, s, s + line_size);
d += 3;
s += 3;
}
usage();
file_name_1 = argv[optind++];
file_name_2 = argv[optind];
-
+
#define TRY(x) do{ if (!(x)) exit(1); }while(0)
MSG("Initializing image library");
struct image_context ctx;
bclose(io.fastbuf);
img1 = io.image;
MSG("Image size=%ux%u", img1->cols, img1->rows);
-
+
image_io_reset(&io);
MSG("Reading %s", file_name_2);
io.fastbuf = bopen(file_name_2, O_RDONLY, 1 << 18);
MSG("Similarity bitmap %02x", image_dup_compare(&dup1, &dup2, transformations | IMAGE_DUP_SCALE | IMAGE_DUP_WANT_ALL));
mp_delete(pool);
-
+
image_destroy(img1);
image_destroy(img2);
image_context_cleanup(&ctx);
write_segmentation(struct image_sig_data *data, byte *fn)
{
MSG("Writing segmentation to %s", fn);
-
+
struct fastbuf *fb = bopen(fn, O_WRONLY | O_CREAT | O_TRUNC, 4096);
struct image *img;
TRY(img = image_new(&ctx, data->image->cols, data->image->rows, COLOR_SPACE_RGB, NULL));
luv[2] = ((int)data->regions[i].a[2] - 128) * (4 / 2.55);
luv_to_xyz_exact(xyz, luv);
xyz_to_srgb_exact(srgb, xyz);
- c[0] = CLAMP(srgb[0] * 255, 0, 255);
- c[1] = CLAMP(srgb[1] * 255, 0, 255);
- c[2] = CLAMP(srgb[2] * 255, 0, 255);
+ c[0] = CLAMP(srgb[0] * 255, 0, 255);
+ c[1] = CLAMP(srgb[1] * 255, 0, 255);
+ c[2] = CLAMP(srgb[2] * 255, 0, 255);
for (struct image_sig_block *block = data->regions[i].blocks; block; block = block->next)
{
uns x1 = block->x * 4;
io.fastbuf = fb;
io.image = img;
- io.format = image_file_name_to_format(fn);
+ io.format = image_file_name_to_format(fn);
TRY(image_io_write(&io));
image_io_reset(&io);
};
struct image_io {
- /* R - read_header input */
- /* H - read_header output */
- /* I - read_data input */
- /* O - read_data output */
- /* W - write input */
+ /* R - read_header input */
+ /* H - read_header output */
+ /* I - read_data input */
+ /* O - read_data output */
+ /* W - write input */
struct image *image; /* [ OW] - image data */
enum image_format format; /* [R W] - file format (IMAGE_FORMAT_x) */
- struct fastbuf *fastbuf; /* [R W] - source/destination stream */
+ struct fastbuf *fastbuf; /* [R W] - source/destination stream */
struct mempool *pool; /* [ I ] - parameter to image_new */
uns cols; /* [ HI ] - number of columns, parameter to image_new */
uns rows; /* [ HI ] - number of rows, parameter to image_new */
}
uns read_flags = io->flags;
-
+
/* Apply transformations */
if (rd->bit_depth == 16)
png_set_strip_16(rd->png_ptr);
read_flags = (read_flags & IMAGE_CHANNELS_FORMAT) | IMAGE_ALPHA;
else
png_set_strip_alpha(rd->png_ptr);
- }
+ }
break;
case PNG_COLOR_TYPE_RGB:
if ((read_flags & IMAGE_COLOR_SPACE) == COLOR_SPACE_GRAYSCALE)
return 0;
}
# define DO_ROW_END do{ \
- walk_row_start += dein_step; \
- while (walk_row_start >= img_end) \
+ walk_row_start += dein_step; \
+ while (walk_row_start >= img_end) \
{ uns n = dein_next >> 1; walk_row_start = rdi.image->pixels + n, dein_step = dein_next; dein_next = n; } \
}while(0)
# define IMAGE_WALK_PREFIX(x) walk_##x
#endif
#ifdef CONFIG_IMAGES_LIBPNG
libpng_cleanup(io);
-libpng_failed:
+libpng_failed:
#endif
#ifdef CONFIG_IMAGES_LIBJPEG
libjpeg_cleanup(io);
return img;
error:
DBG("Failed to decompress thumbnail: %s", io->thread->err_msg);
- return NULL;
+ return NULL;
}
void
uns dist = 0;
for (uns i = 0; i < IMAGE_VEC_F; i++)
{
- uns d = image_sig_cmp_features_weights[0] * isqr((int)sig1->vec.f[i] - (int)sig2->vec.f[i]);
+ uns d = image_sig_cmp_features_weights[0] * isqr((int)sig1->vec.f[i] - (int)sig2->vec.f[i]);
MSGL("feature %u: d=%u (%u %u)", i, d, sig1->vec.f[i], sig2->vec.f[i]);
dist += d;
}
sig->flags = data->flags;
if (!sig->len)
return;
-
+
/* For each region */
u64 w_total = 0;
uns w_border = MIN(data->cols, data->rows) * image_sig_border_size;
cval++;
}
}
-
+
/* Select split value - to minimize error */
uns b1 = val[0] * cnt[0];
uns c1 = isqr(val[0]) * cnt[0];
c2 -= c0;
i += cnt[k];
j -= cnt[k];
- u64 err = (u64)c1 - (u64)b1 * b1 / i + (u64)c2 - (u64)b2 * b2 / j;
+ u64 err = (u64)c1 - (u64)b1 * b1 / i + (u64)c2 - (u64)b2 * b2 / j;
if (err < best_err)
{
best_err = err;
DBG("Zero textured threshold.");
return;
}
-
+
uns cols = data->cols;
uns rows = data->rows;
uns cell_cols = MIN((cols + 1) / 2, MAX_CELLS_COLS);
}
DBG("Detecting textured image... cols=%u rows=%u cell_cols=%u cell_rows=%u", cols, rows, cell_cols, cell_rows);
-
+
/* Compute cells boundaries */
for (i = 1, j = 0; i < cell_cols; i++)
cell_x[i] = fast_div_u32_u8(j += cols, cell_cols);
for (uns i = 0; i < data->regions_count; i++)
for (struct image_sig_block *block = data->regions[i].blocks; block; block = block->next)
block->region = i;
-
+
/* Process cells */
double e = 0;
for (uns j = 0; j < cell_rows; j++)
}
for (uns k = 0; k < data->regions_count; k++)
{
- int a = data->blocks_count * cnt[k] - cell_area * data->regions[k].count;
+ int a = data->blocks_count * cnt[k] - cell_area * data->regions[k].count;
e += (double)a * a / ((double)isqr(data->regions[k].count) * cell_area);
}
}