Blender
V5.0
intern
libmv
libmv
image
image_converter.h
Go to the documentation of this file.
1
// Copyright (c) 2009 libmv authors.
2
//
3
// Permission is hereby granted, free of charge, to any person obtaining a copy
4
// of this software and associated documentation files (the "Software"), to
5
// deal in the Software without restriction, including without limitation the
6
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7
// sell copies of the Software, and to permit persons to whom the Software is
8
// furnished to do so, subject to the following conditions:
9
//
10
// The above copyright notice and this permission notice shall be included in
11
// all copies or substantial portions of the Software.
12
//
13
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
19
// IN THE SOFTWARE.
20
21
#ifndef LIBMV_IMAGE_IMAGE_CONVERTER_H
22
#define LIBMV_IMAGE_IMAGE_CONVERTER_H
23
24
#include "
libmv/image/array_nd.h
"
25
26
namespace
libmv
{
27
28
// The factor comes from http://www.easyrgb.com/
29
// RGB to XYZ : Y is the luminance channel
30
// var_R * 0.2126 + var_G * 0.7152 + var_B * 0.0722
31
template
<
typename
T>
32
inline
T
RGB2GRAY
(
const
T
r,
const
T
g,
const
T
b
) {
33
return
static_cast<
T
>
(r * 0.2126 + g * 0.7152 +
b
* 0.0722);
34
}
35
36
/*
37
// Specialization for the uchar type. (that do not want to work...)
38
template<>
39
inline unsigned char RGB2GRAY<unsigned char>(const unsigned char r,
40
const unsigned char g,
41
const unsigned char b) {
42
return (unsigned char)(r * 0.2126 + g * 0.7152 + b * 0.0722 +0.5);
43
}*/
44
45
template
<
class
ImageIn,
class
ImageOut>
46
void
Rgb2Gray
(
const
ImageIn& imaIn, ImageOut* imaOut) {
47
// It is all fine to cnvert RGBA image here as well,
48
// all the additional channels will be nicely ignored.
49
assert
(imaIn.Depth() >= 3);
50
51
imaOut->Resize(imaIn.Height(), imaIn.Width(), 1);
52
// Convert each RGB pixel into Gray value (luminance)
53
54
for
(
int
j = 0; j < imaIn.Height(); ++j) {
55
for
(
int
i
= 0;
i
< imaIn.Width(); ++
i
) {
56
(*imaOut)(j,
i
) =
57
RGB2GRAY
(imaIn(j,
i
, 0), imaIn(j,
i
, 1), imaIn(j,
i
, 2));
58
}
59
}
60
}
61
62
// Convert given float image to an unsigned char array of pixels.
63
template
<
class
Image>
64
unsigned
char
*
FloatImageToUCharArray
(
const
Image
& image) {
65
unsigned
char
* buffer =
66
new
unsigned
char
[image.Width() * image.Height() * image.Depth()];
67
68
for
(
int
y
= 0;
y
< image.Height();
y
++) {
69
for
(
int
x
= 0;
x
< image.Width();
x
++) {
70
for
(
int
d = 0; d < image.Depth(); d++) {
71
int
index = (
y
* image.Width() +
x
) * image.Depth() + d;
72
buffer[index] = 255.0 * image(
y
,
x
, d);
73
}
74
}
75
}
76
77
return
buffer;
78
}
79
80
}
// namespace libmv
81
82
#endif
// LIBMV_IMAGE_IMAGE_CONVERTER_H
x
x
Definition
BLI_expr_pylike_eval_test.cc:345
array_nd.h
libmv::Image
Definition
libmv/libmv/image/image.h:40
y
y
Definition
compositor_morphological_blur_infos.hh:22
b
b
Definition
compositor_morphological_distance_infos.hh:24
assert
#define assert(assertion)
Definition
gpu_shader_compat_cxx.hh:36
T
#define T
Definition
mball_tessellate.cc:274
libmv
Definition
libmv/autotrack/autotrack.h:30
libmv::Rgb2Gray
void Rgb2Gray(const ImageIn &imaIn, ImageOut *imaOut)
Definition
image_converter.h:46
libmv::FloatImageToUCharArray
unsigned char * FloatImageToUCharArray(const Image &image)
Definition
image_converter.h:64
libmv::RGB2GRAY
T RGB2GRAY(const T r, const T g, const T b)
Definition
image_converter.h:32
i
i
Definition
text_draw.cc:230
Generated on
for Blender by
doxygen
1.16.1