+#define IM_STRING(x) #x
+
+/* I considered using assert.h here, but perl does it's own thing with
+ assert() and the NDEBUG test is opposite to the direction I prefer */
+#ifdef IM_ASSERT
+extern void im_assert_fail(char const *, int, char const *);
+#define im_assert(x) ((x) ? (void)(0) : im_assert_fail(__FILE__, __LINE__, IM_STRING(x)))
+#else
+#define im_assert(x) (void)(0)
+#endif
+
+i_img_dim i_minx(i_img_dim a, i_img_dim b);
+i_img_dim i_maxx(i_img_dim x, i_img_dim y);
+i_img_dim i_abs(i_img_dim x);
+
+#define i_min(a, b) i_minx((a), (b))
+#define i_max(a, b) i_maxx((a), (b))
+
+#define color_to_grey(col) ((col)->rgb.r * 0.222 + (col)->rgb.g * 0.707 + (col)->rgb.b * 0.071)
+