1
2/* make an image of size x by y whose pixels are their coordinates.
3 */
4make_xy x y = im_make_xy (to_real x) (to_real y);
5
6/* make an image with the specified properties ... pixel is (eg.)
7 * Vector [0, 0, 0], or 12. If coding == labq, we ignore bands, format and
8 * type, generate a 3 band float image, and lab2labq it before handing it
9 * back.
10 */
11image_new w h b fmt coding type pixel xoff yoff
12	= im''''
13{
14	b'
15		= 3, coding == Image_coding.LABPACK
16		= b;
17	fmt'
18		= Image_format.FLOAT, coding == Image_coding.LABPACK
19		= fmt;
20	type'
21		= Image_type.LAB, coding == Image_coding.LABPACK
22		= type;
23
24	im = im_black (to_real w) (to_real h) (to_real b') + pixel;
25
26	im' = clip2fmt fmt' im;
27
28	im''
29		= im_Lab2LabQ im', coding == Image_coding.LABPACK;
30		= im';
31
32	im''' = image_set_type type' im'';
33	im'''' = image_set_origin xoff yoff im''';
34}
35
36/* generate a slice of LAB space size x size pixels for L* == l
37 */
38lab_slice size l
39	= image_set_type Image_type.LAB im
40{
41    L = image_new size size 1
42		Image_format.FLOAT Image_coding.NOCODING Image_type.B_W l 0 0;
43	A1 = im_fgrey (to_real size) (to_real size);
44
45	/* im_fgrey always makes 0-1, so these ranges can be wired in.
46	 */
47	A2 = A1 * 256 - 128;
48
49	A4 = im_rot90 A2;
50	im = image_set_origin (size / 2) (size / 2) (L ++ A2 ++ A4);
51}
52
53/* Look at Image, try to make a Colour (failing that, a Vector) which is white
54 * for that image type.
55 */
56image_white im
57	= colour_transform_to type white_lab,
58		bands == 3 && coding == Image_coding.NOCODING &&
59		colour_spaces.present 1 type
60	= white_lab,
61		coding == Image_coding.LABPACK
62	= Vector (replicate bands (max_value.lookup 1 0 format))
63{
64	bands = im.bands;
65	type = im.type;
66	format = im.format;
67	coding = im.coding;
68	colour_spaces = Image_type.colour_spaces;
69
70	// white as LAB
71	white_lab = Colour "Lab" [100, 0, 0];
72
73	// maximum value for this numeric type
74	max_value = Table [
75		[255, Image_format.DPCOMPLEX],
76		[255, Image_format.DOUBLE],
77		[255, Image_format.COMPLEX],
78		[255, Image_format.FLOAT],
79		[2 ** 31 - 1, Image_format.INT],
80		[2 ** 32 - 1, Image_format.UINT],
81		[2 ** 15 - 1, Image_format.SHORT],
82		[2 ** 16 - 1, Image_format.USHORT],
83		[2 ** 7 - 1, Image_format.CHAR],
84		[2 ** 8 - 1, Image_format.UCHAR]
85	];
86}
87
88/* Make a seperable gaussian mask.
89 */
90matrix_gaussian_blur radius
91        = Matrix_con mask_g_sum 0 [mask_g_line]
92{
93        mask_g = im_gauss_imask (radius / 3) 0.2;
94        mask_g_line = mask_g.value?(mask_g.height / 2);
95        mask_g_sum = foldr1 add mask_g_line;
96}
97
98/* Make a seperable square mask.
99 */
100matrix_blur radius
101        = Matrix_con (foldr1 add mask_sq_line) 0 [mask_sq_line]
102{
103        mask_sq_line = replicate (2 * radius - 1) 1;
104}
105
106