Mercurial > hg > orthanc-stone
annotate OrthancStone/Sources/Scene2D/Internals/CairoColorTextureRenderer.cpp @ 2037:d81a7157a846 deep-learning
added OpenGLTexture::ConvertToOpenGLFormats()
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Sat, 28 Jan 2023 12:55:34 +0100 |
parents | 7053b8a0aaec |
children | 07964689cb0b |
rev | line source |
---|---|
597 | 1 /** |
2 * Stone of Orthanc | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
1871
7053b8a0aaec
upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1870
diff
changeset
|
5 * Copyright (C) 2017-2022 Osimis S.A., Belgium |
7053b8a0aaec
upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1870
diff
changeset
|
6 * Copyright (C) 2021-2022 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
597 | 7 * |
8 * This program is free software: you can redistribute it and/or | |
1598
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
9 * modify it under the terms of the GNU Lesser General Public License |
597 | 10 * as published by the Free Software Foundation, either version 3 of |
11 * the License, or (at your option) any later version. | |
12 * | |
13 * This program is distributed in the hope that it will be useful, but | |
14 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
1598
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
16 * Lesser General Public License for more details. |
1596
4fb8fdf03314
removed annoying whitespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
17 * |
1598
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
18 * You should have received a copy of the GNU Lesser General Public |
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
19 * License along with this program. If not, see |
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
20 * <http://www.gnu.org/licenses/>. |
597 | 21 **/ |
22 | |
23 | |
24 #include "CairoColorTextureRenderer.h" | |
25 | |
26 #include "../ColorTextureSceneLayer.h" | |
27 | |
28 namespace OrthancStone | |
29 { | |
30 namespace Internals | |
31 { | |
32 CairoColorTextureRenderer::CairoColorTextureRenderer(ICairoContextProvider& target, | |
33 const ISceneLayer& layer) : | |
34 target_(target) | |
35 { | |
36 Update(layer); | |
37 } | |
38 | |
39 | |
40 void CairoColorTextureRenderer::Update(const ISceneLayer& layer) | |
41 { | |
42 const ColorTextureSceneLayer& l = dynamic_cast<const ColorTextureSceneLayer&>(layer); | |
43 | |
44 texture_.Copy(l.GetTexture(), true); | |
45 textureTransform_ = l.GetTransform(); | |
46 isLinearInterpolation_ = l.IsLinearInterpolation(); | |
47 } | |
48 | |
768
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
597
diff
changeset
|
49 |
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
597
diff
changeset
|
50 void CairoColorTextureRenderer::RenderColorTexture(ICairoContextProvider& target, |
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
597
diff
changeset
|
51 const AffineTransform2D& transform, |
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
597
diff
changeset
|
52 CairoSurface& texture, |
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
597
diff
changeset
|
53 const AffineTransform2D& textureTransform, |
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
597
diff
changeset
|
54 bool isLinearInterpolation) |
597 | 55 { |
768
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
597
diff
changeset
|
56 cairo_t* cr = target.GetCairoContext(); |
597 | 57 |
58 AffineTransform2D t = | |
768
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
597
diff
changeset
|
59 AffineTransform2D::Combine(transform, textureTransform); |
597 | 60 Matrix h = t.GetHomogeneousMatrix(); |
61 | |
62 cairo_save(cr); | |
63 | |
64 cairo_matrix_t m; | |
65 cairo_matrix_init(&m, h(0, 0), h(1, 0), h(0, 1), h(1, 1), h(0, 2), h(1, 2)); | |
66 cairo_transform(cr, &m); | |
67 | |
68 cairo_set_operator(cr, CAIRO_OPERATOR_OVER); | |
768
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
597
diff
changeset
|
69 cairo_set_source_surface(cr, texture.GetObject(), 0, 0); |
597 | 70 |
768
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
597
diff
changeset
|
71 if (isLinearInterpolation) |
597 | 72 { |
73 cairo_pattern_set_filter(cairo_get_source(cr), CAIRO_FILTER_BILINEAR); | |
74 } | |
75 else | |
76 { | |
77 cairo_pattern_set_filter(cairo_get_source(cr), CAIRO_FILTER_NEAREST); | |
78 } | |
79 | |
80 cairo_paint(cr); | |
81 | |
82 cairo_restore(cr); | |
83 } | |
84 } | |
85 } |