This file is indexed.

/usr/share/doc/openexr-doc/examples/drawImage.cpp is in openexr-doc 2.2.0-10ubuntu2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
///////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2004, Industrial Light & Magic, a division of Lucas
// Digital Ltd. LLC
// 
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
// *       Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// *       Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// *       Neither the name of Industrial Light & Magic nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission. 
// 
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
///////////////////////////////////////////////////////////////////////////



//-----------------------------------------------------------------------------
//
//	Functions that algorithmically generate images, so that
//	the code examples for image file reading and writing have
//	data they can work with.
//	Note that it is not necessary to study the code below in
//	order to understand how the file I/O code examples work.
//
//-----------------------------------------------------------------------------


#include "drawImage.h"

#include <math.h>
#include <stdlib.h>
#include <float.h>
#include <algorithm>

#include "namespaceAlias.h"
using namespace IMF;
using namespace std;

namespace
{

float
pw (float x, int y)
{
    float p = 1;

    while (y)
    {
	if (y & 1)
	    p *= x;

	x *= x;
	y >>= 1;
    }

    return p;
}


void
sp (Array2D<Rgba> &px, int w, int h,
    float xc, float yc, float rc,
    float rd, float gn, float bl, float lm)
{
    int x1 = int (max ((float) floor (xc - rc),  0.0f));
    int x2 = int (min ((float) ceil  (xc + rc), w - 1.0f));
    int y1 = int (max ((float) floor (yc - rc),  0.0f));
    int y2 = int (min ((float) ceil  (yc + rc), h - 1.0f));

    for (int y = y1; y <= y2; ++y)
    {
	for (int x = x1; x <= x2; ++x)
	{
	    float xl = (x - xc) / rc;
	    float yl = (y - yc) / rc;
	    float r  = sqrt (xl * xl + yl * yl);

	    if (r >= 1)
		continue;

	    float a = 1;

	    if (r * rc > rc - 1)
		a = rc - r * rc;

	    float zl = sqrt (1 - r * r);
	    float dl = xl * 0.42426 - yl * 0.56568 + zl * 0.70710;

	    if (dl < 0)
		dl *= -0.1;

	    float hl = pw (dl, 50) * 4;
	    float dr = (dl + hl) * rd;
	    float dg = (dl + hl) * gn;
	    float db = (dl + hl) * bl;

	    Rgba &p = px[y][x];
	    p.r = p.r * (1 - a) + dr * lm * a;
	    p.g = p.g * (1 - a) + dg * lm * a;
	    p.b = p.b * (1 - a) + db * lm * a;
	    p.a = 1 - (1 - p.a) * (1 - a);
	}
    }
}


void
zsp (Array2D<half> &gpx, Array2D<float> &zpx, int w, int h,
     float xc, float yc, float zc, float rc, float gn)
{
    int x1 = int (max ((float) floor (xc - rc),  0.0f));
    int x2 = int (min ((float) ceil  (xc + rc), w - 1.0f));
    int y1 = int (max ((float) floor (yc - rc),  0.0f));
    int y2 = int (min ((float) ceil  (yc + rc), h - 1.0f));

    for (int x = x1; x <= x2; ++x)
    {
	for (int y = y1; y <= y2; ++y)
	{
	    float xl = (x - xc) / rc;
	    float yl = (y - yc) / rc;
	    float r  = sqrt (xl * xl + yl * yl);

	    if (r >= 1)
		continue;

	    float a = 1;

	    if (r * rc > rc - 1)
		a = rc - r * rc;

	    float zl = sqrt (1 - r * r);
	    float zp = zc - rc * zl;

	    if (zp >= zpx[y][x])
		continue;

	    float dl = xl * 0.42426 - yl * 0.56568 + zl * 0.70710;

	    if (dl < 0)
		dl *= -0.1;

	    float hl = pw (dl, 50) * 4;
	    float dg = (dl + hl) * gn;

	    gpx[y][x] = dg;
	    zpx[y][x] = zp;
	}
    }
}


inline float
z (float k)
{
    k = 2 * (k - int (k));
    return (k < 1)? k: 2 - k;
}


inline void
clear (Rgba &color)
{
    color.r = 0;
    color.g = 0;
    color.b = 0;
}


inline void
clear (GZ &gz)
{
    gz.g = 0;
    gz.z = 0;
}


void
add (float k, Rgba &color)
{
    color.a = k;
    k *= 4;
    color.r += 0.1f + 4 * z (k);
    color.g += 0.1f + 4 * z (k + .33333f);
    color.b += 0.1f + 4 * z (k + .66667f);
}


void
add (float k, GZ &gz)
{
    k *= 5;
    gz.g += 4 * z (k);
    gz.z = k;
}


inline void
scale (float f, Rgba &color)
{
    color.r *= f;
    color.g *= f;
    color.b *= f;
    color.a *= f;
}


inline void
scale (float f, GZ &gz)
{
    gz.g *= f;
    gz.z *= f;
}


template <class P>
void
mndl (Array2D <P> &px,
      int w, int h,
      int xMin, int xMax,
      int yMin, int yMax,
      int xSamples, int ySamples,
      double rMin,
      double rMax,
      double iMin,
      double aspect,
      double rSeed,
      double iSeed)
{
    if (xSamples > 6)
	xSamples = 6;

    if (ySamples > 6)
	ySamples = 6;

    double iMax = iMin + aspect * (rMax - rMin) * h / w;
    double sx = double (rMax - rMin) / w;
    double sy = double (iMax - iMin) / h;
    double tx = 1.f / xSamples;
    double ty = 1.f / ySamples;
    float  t  = tx * ty;

    for (int y = yMin; y < yMax; ++y)
    {
        for (int x = xMin; x < xMax; ++x)
        {
            P &p = px[y - yMin][x - xMin];

	    clear (p);

	    for (int i = 0; i < xSamples; ++i)
            {
		for (int j = 0; j < ySamples; ++j)
                {
                    const double a = rMin + sx * (x + i * tx);
		    const double b = iMin + sy * (y + j * ty);
		    const double sMax = 100;
		    const int kMax = 256;
                    double r = rSeed;
		    double i = iSeed;
		    double s = 0;
                    int k = 0;

                    while (k < kMax && s < sMax)
                    {
                        s = r * r - i * i;
                        i = 2 * r * i + b;
                        r = s + a;
                        k++;
                    }

		    add (k / float (kMax), p);
                }
            }

	    scale (t, p);
        }
    }
}

} // namespace


void
drawImage1 (Array2D<Rgba> &px, int w, int h)
{
    for (int y = 0; y < h; ++y)
    {
	for (int x = 0; x < w; ++x)
	{
	    Rgba &p = px[y][x];
	    p.r = 0;
	    p.g = 0;
	    p.b = 0;
	    p.a = 0;
	}
    }

    int n = 5600;

    for (int i = 0; i < n; ++i)
    {
	float t = (i * 2.0 * M_PI) / n;
	float xp = sin (t * 2.0) + 0.2 * sin (t * 15.0);
	float yp = cos (t * 3.0) + 0.2 * cos (t * 15.0);
	float r = float (i + 1) / float (n);
	float xq = xp + 0.3 * r * sin (t * 80.0);
	float yq = yp + 0.3 * r * cos (t * 80.0);
	float xr = xp + 0.3 * r * sin (t * 80.0 + M_PI / 2);
	float yr = yp + 0.3 * r * cos (t * 80.0 + M_PI / 2);

	if (i % 10 == 0)
	    sp (px, w, h,
		xp * w / 3 + w / 2, yp * h / 3 + h / 2,
		w * 0.05 * r,
		2.0, 0.8, 0.1,
		0.5 * r * r);

	sp (px, w, h,
	    xq * w / 3 + w / 2, yq * h / 3 + h / 2,
	    w * 0.01 * r,
	    0.7, 0.2, 2.0,
	    0.5 * r * r);

	sp (px, w, h,
	    xr * w / 3 + w / 2, yr * h / 3 + h / 2,
	    w * 0.01 * r,
	    0.2, 1.5, 0.1,
	    0.5 * r * r);
    }
}


void
drawImage2 (Array2D<half> &gpx, Array2D<float> &zpx, int w, int h)
{
    for (int y = 0; y < h; ++y)
    {
	for (int x = 0; x < w; ++x)
	{
	    gpx[y][x] = 0;
	    zpx[y][x] = FLT_MAX;
	}
    }

    int n = 2000;

    for (int i = 0; i < n; ++i)
    {
	float t = (i * 2.0 * M_PI) / n;
	float xp = sin (t * 4.0) + 0.2 * sin (t * 15.0);
	float yp = cos (t * 3.0) + 0.2 * cos (t * 15.0);
	float zp = sin (t * 5.0);
	float rd = 0.7 + 0.3 * sin (t * 15.0);
	float gn = 0.5 - 0.5 * zp + 0.2;

	zsp (gpx, zpx, w, h,
	     xp * w / 3 + w / 2,
	     yp * h / 3 + h / 2,
	     zp * w + 3 * w,
	     w * rd * 0.05,
	     2.5 * gn * gn);
    }
}


void
drawImage3 (Array2D<Rgba> &px,
            int w, int h,
            int xMin, int xMax,
            int yMin, int yMax,
            int xLevel, int yLevel)
{
    mndl (px,
	  w, h,
	  xMin, xMax,
	  yMin, yMax,
	  (1 << xLevel), (1 << yLevel),
	  0.328, 0.369,
	  0.5,
	  double (1 << yLevel) / double (1 << xLevel),
	  -0.713, 0.9738);
}


void
drawImage4 (Array2D<Rgba> &px,
            int w, int h,
            int xMin, int xMax,
            int yMin, int yMax,
            int xLevel, int yLevel)
{
    mndl (px,
	  w, h,
	  xMin, xMax,
	  yMin, yMax,
	  (1 << xLevel), (1 << yLevel),
	  0.3247, 0.33348,
	  0.4346,
	  double (1 << yLevel) / double (1 << xLevel),
	  0.4, -0.765);
}


void
drawImage5 (Array2D<Rgba> &px,
            int w, int h,
            int xMin, int xMax,
            int yMin, int yMax,
            int xLevel, int yLevel)
{
    mndl (px,
	  w, h,
	  xMin, xMax,
	  yMin, yMax,
	  (1 << xLevel), (1 << yLevel),
	  0.2839, 0.2852,
	  0.00961,
	  double (1 << yLevel) / double (1 << xLevel),
	  0.25, 0.31);
}


void
drawImage6 (Array2D<GZ> &px, int w, int h)
{
    mndl (px,
	  w, h,
	  0, w,
	  0, h,
	  3, 3,
	  -2.5, 1.0,
	  -1.3333,
	  1,
	  0, 0);
}


void
drawImage7 (Array<Rgba> &px, int w, int h, int y)
{
    for (int x = 0; x < w; ++x)
    {
	float xc = x - w / 2;
	float yc = y - h / 2;
	float a = atan2 (xc, yc);
	float r = sqrt (xc * xc + yc * yc);

	Rgba &p = px[x];
	p.r = sin (3.0f * a + 0.3f * sin (0.10f * r)) * 0.5f + 0.5f;
	p.g = sin (3.0f * a + 0.3f * sin (0.11f * r)) * 0.5f + 0.5f;
	p.b = sin (3.0f * a + 0.3f * sin (0.12f * r)) * 0.5f + 0.5f;
	p.a = 1;
    }
}