Grayscale image: Difference between revisions

Content added Content deleted
(→‎{{header|C}}: more logical typedefs)
(Vedit macro language added)
Line 225: Line 225:
g_channel,
g_channel,
b_channel)</ocaml>
b_channel)</ocaml>

=={{header|Vedit macro language}}==
Conversion to a grayscale image.<br>
<pre>
// Convert RGB image to grayscale (8 bit/pixel)
// #10 = buffer that contains image data
// On return:
// #20 = buffer for the new grayscale image

:RGB_TO_GRAYSCALE:
File_Open("|(VEDIT_TEMP)\gray.data", OVERWRITE+NOEVENT+NOMSG)
#20 = Buf_Num
BOF
Del_Char(ALL)
Buf_Switch(#10)
Repeat(File_Size/3) {
#9 = Cur_Char() * 2126
#9 += Cur_Char(1) * 7152
#9 += Cur_Char(2) * 722
Char(3)
Buf_Switch(#20)
Ins_Char(#9 / 10000)
Buf_Switch(#10)
}
Return
</pre>

Conversion to a color image.<br>
<pre>
// Convert grayscale image (8 bits/pixel) into RGB (24 bits/pixel)
// #20 = buffer that contains image data
// On return:
// #10 = buffer for the new RGB image

:GRAYSCALE_TO_RGB:
File_Open("|(VEDIT_TEMP)\RGB.data", OVERWRITE+NOEVENT+NOMSG)
#10 = Buf_Num
BOF
Del_Char(ALL)
Buf_Switch(#20) // input image (grayscale)
BOF
Repeat(File_Size) {
#9 = Cur_Char()
Char
Buf_Switch(#10) // output image (RGB)
Ins_Char(#9, COUNT, 3)
Buf_Switch(#20)
}
Return
</pre>