};
int difference (ILuint n, struct PixelInfo *p, void *data);
+int palette_mix (ILuint n, struct PixelInfo *p, void *data);
static inline ILuint diff_1ch (ILint64 x, ILint64 y, ILint64 A, ILint64 B, ILint64 F);
char DIFF_MISSING_ARGS[] = "Missing parameters.\ndiff inPixA inPixB outPix [RA GA BA [RB GB BB]]\n";
if ((info[0].image_height != info[1].image_height) || (info[0].image_width != info[1].image_width) || (info[0].num_images != info[1].num_images))
{
*err = SIZE_MISMATCH;
- return r;
+ return EINVAL;
}
if ((info[0].image_bpc != info[1].image_bpc) || (!(flags[0] & IS_OVER_8BIT)) || (!(flags[0] & IS_OVER_8BIT)))
}
r = convert_picture(0, &(info[0]), &(flags[0]));
+ if (r!=0)
{
*err = CONVERT_FAILED;
return EIO;
}
r = convert_picture(1, &(info[1]), &(flags[1]));
+ if (r!=0)
{
*err = CONVERT_FAILED;
return EIO;
data.g_b = upscale_value(GB, info[0].image_bpc);
data.b_b = upscale_value(BB, info[0].image_bpc);
}
+ data.max = upscale_value(0xFF, info[0].image_bpc);
r = build_picture_from_info(2, &(info[0]), &(info[2]), &(flags[2]));
if (r!=0)
*err = CONVERT_FAILED;
return r;
}
+ flags[0] &= ~OK_PALETTE_ONLY;
+ flags[1] &= ~OK_PALETTE_ONLY;
+ flags[2] &= ~OK_PALETTE_ONLY;
+ r = perform_action(
+ 3,
+ id,
+ xyf0, xyf0, xyf0,
+ 0, 0, 0,
+ &palette_mix,
+ flags,
+ &data
+ );
+ if (r)
+ {
+ *err = CONVERT_FAILED;
+ return r;
+ }
}
else
{
struct diff_data *d;
d = data;
- if (n != 3)
+ if (n < 3)
return EIO;
p[2].red = diff_1ch(p[0].red, p[1].red, d->r_a, d->r_b, d->max);
return 0;
}
+int palette_mix (ILuint n, struct PixelInfo *p, void *data)
+{
+ if (n < 3)
+ return EIO;
+
+ p[2].index = p[0].index * p[0].info.palette_num_cols + p[1].index;
+
+ return 0;
+}
+
static inline ILuint diff_1ch (ILint64 x, ILint64 y, ILint64 A, ILint64 B, ILint64 F)
{
ILint64 v;
if (x == y)
return (ILuint) x;
else if (x > y)
- v = (A * (x - y)) / F;
+ v = y + ((A * (x - y)) / F);
else
- v = (B * (y - x)) / F;
+ v = x + ((B * (y - x)) / F);
return (ILuint) v;
}