|
8 | 8 | /// @parblock |
9 | 9 | /// |
10 | 10 | /// Persistence of Vision Ray Tracer ('POV-Ray') version 3.7. |
11 | | -/// Copyright 1991-2016 Persistence of Vision Raytracer Pty. Ltd. |
| 11 | +/// Copyright 1991-2017 Persistence of Vision Raytracer Pty. Ltd. |
12 | 12 | /// |
13 | 13 | /// POV-Ray is free software: you can redistribute it and/or modify |
14 | 14 | /// it under the terms of the GNU Affero General Public License as |
@@ -107,64 +107,6 @@ static void InterpolateBicubic(const ImageData *image, DBL xcoor, DBL ycoor, RGB |
107 | 107 | * 1. Cylindrical mapping 2. Spherical mapping 3. Torus mapping |
108 | 108 | */ |
109 | 109 |
|
110 | | -/***************************************************************************** |
111 | | -* |
112 | | -* FUNCTION |
113 | | -* |
114 | | -* image_map |
115 | | -* |
116 | | -* INPUT |
117 | | -* |
118 | | -* EPoint -- 3-D point at which function is evaluated |
119 | | -* Pigment -- Pattern containing various parameters |
120 | | -* |
121 | | -* OUTPUT |
122 | | -* |
123 | | -* Colour -- color at EPoint |
124 | | -* |
125 | | -* RETURNS |
126 | | -* |
127 | | -* int - true, if current point on the image map |
128 | | -* false, if current point is not on the image map |
129 | | -* |
130 | | -* AUTHOR |
131 | | -* |
132 | | -* POV-Ray Team |
133 | | -* |
134 | | -* DESCRIPTION : Determines color of a 3-D point from a 2-D bitmap |
135 | | -* |
136 | | -* CHANGES |
137 | | -* |
138 | | -******************************************************************************/ |
139 | | - |
140 | | -bool image_map(const Vector3d& EPoint, const PIGMENT *Pigment, TransColour& colour) |
141 | | -{ |
142 | | - // TODO ALPHA - the caller does expect non-premultiplied data, but maybe he could profit from premultiplied data? |
143 | | - |
144 | | - int reg_number; |
145 | | - DBL xcoor = 0.0, ycoor = 0.0; |
146 | | - |
147 | | - // If outside map coverage area, return clear |
148 | | - |
149 | | - if(map_pos(EPoint, Pigment->pattern.get(), &xcoor, &ycoor)) |
150 | | - { |
151 | | - colour = ToTransColour(RGBFTColour(1.0, 1.0, 1.0, 0.0, 1.0)); |
152 | | - return false; |
153 | | - } |
154 | | - else |
155 | | - { |
156 | | - RGBFTColour rgbft; |
157 | | - if (const ImagePatternImpl *pattern = dynamic_cast<ImagePatternImpl*>(Pigment->pattern.get())) |
158 | | - image_colour_at(pattern->pImage, xcoor, ycoor, rgbft, ®_number, false); |
159 | | - else |
160 | | - POV_PATTERN_ASSERT(false); |
161 | | - colour = ToTransColour(rgbft); |
162 | | - return true; |
163 | | - } |
164 | | -} |
165 | | - |
166 | | - |
167 | | - |
168 | 110 | /***************************************************************************** |
169 | 111 | * |
170 | 112 | * FUNCTION |
@@ -199,14 +141,15 @@ TEXTURE *material_map(const Vector3d& EPoint, const TEXTURE *Texture) |
199 | 141 | * texture index. |
200 | 142 | */ |
201 | 143 |
|
202 | | - if(map_pos(EPoint, Texture->pattern.get(), &xcoor, &ycoor)) |
| 144 | + // NB: Can't use `static_cast` here due to multi-inheritance in the pattern class hierarchy. |
| 145 | + const ImagePatternImpl *pattern = dynamic_cast<ImagePatternImpl*>(Texture->pattern.get()); |
| 146 | + POV_PATTERN_ASSERT(pattern); |
| 147 | + |
| 148 | + if(map_pos(EPoint, pattern->pImage, &xcoor, &ycoor)) |
203 | 149 | Material_Number = 0; |
204 | 150 | else |
205 | 151 | { |
206 | | - if (const ImagePatternImpl *pattern = dynamic_cast<ImagePatternImpl*>(Texture->pattern.get())) |
207 | | - image_colour_at(pattern->pImage, xcoor, ycoor, colour, ®_number); // TODO ALPHA - we should decide whether we prefer premultiplied or non-premultiplied alpha |
208 | | - else |
209 | | - POV_PATTERN_ASSERT(false); |
| 152 | + image_colour_at(pattern->pImage, xcoor, ycoor, colour, ®_number); // TODO ALPHA - we should decide whether we prefer premultiplied or non-premultiplied alpha |
210 | 153 |
|
211 | 154 | if(reg_number == -1) |
212 | 155 | Material_Number = (int)(colour.red() * 255.0); |
@@ -252,15 +195,16 @@ void bump_map(const Vector3d& EPoint, const TNORMAL *Tnormal, Vector3d& normal) |
252 | 195 | DBL Amount = Tnormal->Amount; |
253 | 196 | const ImageData *image; |
254 | 197 |
|
255 | | - if (const ImagePatternImpl *pattern = dynamic_cast<ImagePatternImpl*>(Tnormal->pattern.get())) |
256 | | - image = pattern->pImage; |
257 | | - else |
258 | | - POV_PATTERN_ASSERT(false); |
| 198 | + // NB: Can't use `static_cast` here due to multi-inheritance in the pattern class hierarchy. |
| 199 | + const ImagePatternImpl *pattern = dynamic_cast<ImagePatternImpl*>(Tnormal->pattern.get()); |
| 200 | + POV_PATTERN_ASSERT(pattern); |
| 201 | + |
| 202 | + image = pattern->pImage; |
259 | 203 |
|
260 | 204 | // going to have to change this |
261 | 205 | // need to know if bump point is off of image for all 3 points |
262 | 206 |
|
263 | | - if(map_pos(EPoint, Tnormal->pattern.get(), &xcoor, &ycoor)) |
| 207 | + if(map_pos(EPoint, image, &xcoor, &ycoor)) |
264 | 208 | return; |
265 | 209 | else |
266 | 210 | image_colour_at(image, xcoor, ycoor, colour1, &index); // TODO ALPHA - we should decide whether we prefer premultiplied or non-premultiplied alpha |
@@ -371,20 +315,20 @@ void bump_map(const Vector3d& EPoint, const TNORMAL *Tnormal, Vector3d& normal) |
371 | 315 | * |
372 | 316 | ******************************************************************************/ |
373 | 317 |
|
374 | | -DBL image_pattern(const Vector3d& EPoint, const BasicPattern* pPattern) |
| 318 | +DBL image_pattern(const Vector3d& EPoint, const ImagePattern* pPattern) |
375 | 319 | { |
376 | 320 | DBL xcoor = 0.0, ycoor = 0.0; |
377 | 321 | int index = -1; |
378 | 322 | RGBFTColour colour; |
379 | | - const ImageData *image = dynamic_cast<const ImagePatternImpl*>(pPattern)->pImage; |
| 323 | + const ImageData *image = pPattern->pImage; |
380 | 324 | DBL Value; |
381 | 325 |
|
382 | 326 | colour.Clear(); |
383 | 327 |
|
384 | 328 | // going to have to change this |
385 | 329 | // need to know if bump point is off of image for all 3 points |
386 | 330 |
|
387 | | - if(map_pos(EPoint, pPattern, &xcoor, &ycoor)) |
| 331 | + if(map_pos(EPoint, pPattern->pImage, &xcoor, &ycoor)) |
388 | 332 | return 0.0; |
389 | 333 | else |
390 | 334 | image_colour_at(image, xcoor, ycoor, colour, &index); // TODO ALPHA - we should decide whether we prefer premultiplied or non-premultiplied alpha |
@@ -978,11 +922,9 @@ static int planar_image_map(const Vector3d& EPoint, const ImageData *image, DBL |
978 | 922 | * |
979 | 923 | ******************************************************************************/ |
980 | 924 |
|
981 | | -int map_pos(const Vector3d& EPoint, const BasicPattern* pPattern, DBL *xcoor, DBL *ycoor) |
| 925 | +int map_pos(const Vector3d& EPoint, const ImageData* image, DBL *xcoor, DBL *ycoor) |
982 | 926 | { |
983 | | - const ImageData *image = dynamic_cast<const ImagePatternImpl*>(pPattern)->pImage; |
984 | | - |
985 | | - // Now determine which mapper to use. |
| 927 | + // Determine which mapper to use. |
986 | 928 |
|
987 | 929 | switch(image->Map_Type) |
988 | 930 | { |
@@ -1024,7 +966,7 @@ int map_pos(const Vector3d& EPoint, const BasicPattern* pPattern, DBL *xcoor, DB |
1024 | 966 | } |
1025 | 967 |
|
1026 | 968 | *xcoor = wrap( *xcoor, (DBL)(image->iwidth)); |
1027 | | - *ycoor = wrap(-*ycoor, (DBL)(image->iheight)); // (Compensate for y coordinates on the images being upsidedown) |
| 969 | + *ycoor = wrap(-*ycoor, (DBL)(image->iheight)); // (Compensate for y coordinates on the images being upside down) |
1028 | 970 |
|
1029 | 971 | return (0); |
1030 | 972 | } |
|
0 commit comments