Grayscale image: Difference between revisions
m
<lang>
(<code>) |
m (<lang>) |
||
Line 8:
=={{header|Ada}}==
<
type Grayscale_Image is array (Positive range <>, Positive range <>) of Luminance;
</
Conversion to a grayscale image:
<
function Grayscale (Picture : Image) return Grayscale_Image is
type Extended_Luminance is range 0..10_000_000;
Line 33:
return Result;
end Grayscale;
</
Conversion to a color image:
<
function Color (Picture : Grayscale_Image) return Image is
Result : Image (Picture'Range (1), Picture'Range (2));
Line 46:
return Result;
end Color;
</
=={{header|C}}==
Line 52:
Definition for a grayscale image.
<
typedef unsigned char luminance;
typedef luminance pixel1[1];
Line 61:
} grayimage_t;
typedef grayimage_t *grayimage;
</
The same as <tt>alloc_img</tt>, but for grayscale images.
<
grayimage alloc_grayimg(unsigned int width, unsigned int height)
{
Line 75:
return img;
}
</
Convert from ''color'' image to ''grayscale'' image.
<
grayimage tograyscale(image img)
{
Line 103:
return timg;
}
</
And back from a ''grayscale'' image to a ''color'' image.
<lang c>
{
unsigned int x, y;
Line 129 ⟶ 130:
return timg;
}
</
'''Notes'''
* <tt>tocolor</tt> and <tt>tograyscale</tt> do not free the previous image, so it must be freed normally calling <tt>free_img</tt>. With a cast we can use the same function also for grayscale images, or we can define something like
<
#define free_grayimg(IMG) free_img((image)(IMG))
</
* ''Luminance'' is rounded. Since the C implementation is based on unsigned char (256 possible values per components), L can be at most 255.0 and rounding gives 255, as we expect. Changing the color_component type would only change 256, 255.0 and 255 values here written in something else, the code would work the same.
Line 192 ⟶ 193:
Conversion to a grayscale image:
<
let to_grayscale ~img:(_, r_channel, g_channel, b_channel) =
let width = Bigarray.Array2.dim1 r_channel
Line 213 ⟶ 214:
done;
(gray_channel)
</
Conversion to a color image:
<
let to_color ~img:gray_channel =
let width = Bigarray.Array2.dim1 gray_channel
Line 237 ⟶ 238:
g_channel,
b_channel)
</
=={{header|Vedit macro language}}==
|