Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add new comparison method rgb_difference that resembles arithmetical … #462

Closed
wants to merge 6 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 20 additions & 37 deletions filters.im
Original file line number Diff line number Diff line change
Expand Up @@ -1556,64 +1556,47 @@ i_rgbdiff_image(i_img *im1, i_img *im2) {

out = i_sametype_chans(im1, xsize, ysize, outchans);

if (im1->bits == i_8_bits && im2->bits == i_8_bits) {
i_color *line1 = mymalloc(xsize * sizeof(*line1));
i_color *line2 = mymalloc(xsize * sizeof(*line1));
#code im1->bits == i_8_bits && im2->bits == i_8_bits
IM_COLOR *line1 = mymalloc(xsize * sizeof(*line1));
IM_COLOR *line2 = mymalloc(xsize * sizeof(*line1));
i_img_dim x, y;
int ch;
IM_WORK_T opaque;
#ifdef IM_EIGHT_BIT
opaque = 255;
#else
opaque = 1.0;
#endif

for (y = 0; y < ysize; ++y) {
i_glin(im1, 0, xsize, y, line1);
i_glin(im2, 0, xsize, y, line2);
IM_GLIN(im1, 0, xsize, y, line1);
IM_GLIN(im2, 0, xsize, y, line2);
if (outchans != diffchans) {
/* give the output an alpha channel since it doesn't have one */
for (x = 0; x < xsize; ++x)
line2[x].channel[diffchans] = 255;
}
for (x = 0; x < xsize; ++x) {
for (ch = 0; ch < diffchans; ++ch) {
if (ch == outchans-1) {
line2[x].channel[ch] = 255; /* ignore alpha channel */
} else {
line2[x].channel[ch] = i_abs(line1[x].channel[ch] - line2[x].channel[ch]);
}
for (x = 0; x < xsize; ++x) {
line2[x].channel[diffchans] = opaque;
tonycoz marked this conversation as resolved.
Show resolved Hide resolved
}
}
i_plin(out, 0, xsize, y, line2);
}
myfree(line1);
myfree(line2);
}
else {
i_fcolor *line1 = mymalloc(xsize * sizeof(*line1));
i_fcolor *line2 = mymalloc(xsize * sizeof(*line2));
i_img_dim x, y;
int ch;

for (y = 0; y < ysize; ++y) {
i_glinf(im1, 0, xsize, y, line1);
i_glinf(im2, 0, xsize, y, line2);
if (outchans != diffchans) {
/* give the output an alpha channel since it doesn't have one */
for (x = 0; x < xsize; ++x)
line2[x].channel[diffchans] = 1.0;
}
for (x = 0; x < xsize; ++x) {
for (ch = 0; ch < diffchans; ++ch) {
if (ch == outchans-1) {
line2[x].channel[ch] = 1.0; /* ignore alpha channel */
line2[x].channel[ch] = opaque;
} else {
#ifdef IM_EIGHT_BIT
line2[x].channel[ch] = i_abs(line1[x].channel[ch] - line2[x].channel[ch]);
#else
if (line1[x].channel[ch] != line2[x].channel[ch]) {
line2[x].channel[ch] = i_abs(line1[x].channel[ch] - line2[x].channel[ch]);
}
#endif
tonycoz marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
i_plinf(out, 0, xsize, y, line2);
IM_PLIN(out, 0, xsize, y, line2);
}
myfree(line1);
myfree(line2);
}
#/code

return out;
}
Expand Down