This file is indexed.

/usr/include/mapnik/graphics.hpp is in libmapnik2-dev 2.0.0+ds1-3build1.

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
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
/*****************************************************************************
 *
 * This file is part of Mapnik (c++ mapping toolkit)
 *
 * Copyright (C) 2006 Artem Pavlenko
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 *****************************************************************************/

//$Id: graphics.hpp 39 2005-04-10 20:39:53Z pavlenko $

#ifndef GRAPHICS_HPP
#define GRAPHICS_HPP

// mapnik
#include <mapnik/color.hpp>
#include <mapnik/gamma.hpp>
#include <mapnik/image_data.hpp>
#include <mapnik/box2d.hpp>
#include <mapnik/image_view.hpp>
#include <mapnik/global.hpp>

// stl
#include <cmath>
#include <string>
#include <cassert>

// cairo
#ifdef HAVE_CAIRO
#include <cairomm/surface.h>
#endif

// boost
#include <boost/optional/optional.hpp>

namespace mapnik
{

struct Multiply
{
    inline static void mergeRGB(unsigned const &r0, unsigned const &g0, unsigned const &b0,
                                unsigned &r1, unsigned &g1, unsigned &b1)
    {
        r1 = r1*r0/255;
        g1 = g1*g0/255;
        b1 = b1*b0/255;
    }
};
struct Multiply2
{
    inline static void mergeRGB(unsigned const &r0, unsigned const &g0, unsigned const &b0,
                                unsigned &r1, unsigned &g1, unsigned &b1)
    {
        r1 = r1*r0/128;
        if (r1>255) r1=255;
        g1 = g1*g0/128;
        if (g1>255) g1=255;
        b1 = b1*b0/128;
        if (b1>255) b1=255;
    }
};
struct Divide
{
    inline static void mergeRGB(unsigned const &r0, unsigned const &g0, unsigned const &b0,
                                unsigned &r1, unsigned &g1, unsigned &b1)
    {
        r1 = r0*256/(r1+1);
        g1 = g0*256/(g1+1);
        b1 = b0*256/(b1+1);
    }
};
struct Divide2
{
    inline static void mergeRGB(unsigned const &r0, unsigned const &g0, unsigned const &b0,
                                unsigned &r1, unsigned &g1, unsigned &b1)
    {
        r1 = r0*128/(r1+1);
        g1 = g0*128/(g1+1);
        b1 = b0*128/(b1+1);
    }
};
struct Screen
{
    inline static void mergeRGB(unsigned const &r0, unsigned const &g0, unsigned const &b0,
                                unsigned &r1, unsigned &g1, unsigned &b1)
    {
        r1 = 255 - (255-r0)*(255-r1)/255;
        g1 = 255 - (255-g0)*(255-g1)/255;
        b1 = 255 - (255-b0)*(255-b1)/255;
    }
};
struct HardLight
{
    inline static void mergeRGB(unsigned const &r0, unsigned const &g0, unsigned const &b0,
                                unsigned &r1, unsigned &g1, unsigned &b1)
    {
        r1 = (r1>128)?255-(255-r0)*(255-2*(r1-128))/256:r0*r1*2/256;
        g1 = (g1>128)?255-(255-g0)*(255-2*(g1-128))/256:g0*g1*2/256;
        b1 = (b1>128)?255-(255-b0)*(255-2*(b1-128))/256:b0*b1*2/256;
    }
};
struct MergeGrain
{
    inline static void mergeRGB(unsigned const &r0, unsigned const &g0, unsigned const &b0,
                                unsigned &r1, unsigned &g1, unsigned &b1)
    {
        r1 = (r1+r0>128)?r1+r0-128:0;
        if (r1>255) r1=255;
        g1 = (g1+g0>128)?g1+g0-128:0;
        if (g1>255) g1=255;
        b1 = (b1+b0>128)?b1+b0-128:0;
        if (b1>255) b1=255;
    }
};
struct MergeGrain2
{
    inline static void mergeRGB(unsigned const &r0, unsigned const &g0, unsigned const &b0,
                                unsigned &r1, unsigned &g1, unsigned &b1)
    {
        r1 = (2*r1+r0>256)?2*r1+r0-256:0;
        if (r1>255) r1=255;
        g1 = (2*g1+g0>256)?2*g1+g0-256:0;
        if (g1>255) g1=255;
        b1 = (2*b1+b0>256)?2*b1+b0-256:0;
        if (b1>255) b1=255;
    }
};

class MAPNIK_DECL image_32
{
private:
    unsigned width_;
    unsigned height_;
    boost::optional<color> background_;
    image_data_32 data_;
    bool painted_;
public:
    image_32(int width,int height);
    image_32(image_32 const& rhs);
#ifdef HAVE_CAIRO
    image_32(Cairo::RefPtr<Cairo::ImageSurface> rhs);
#endif
    ~image_32();

    void painted(bool painted)
    {
        painted_ = painted;
    }

    bool painted() const
    {
        return painted_;
    }

    boost::optional<color> const& get_background() const;
    
    void set_background(const color& c);

    void set_grayscale_to_alpha();

    void set_color_to_alpha(color const& c);

    void set_alpha(float opacity);
    
    inline const image_data_32& data() const
    {
        return data_;
    }
    
    inline image_data_32& data()
    {
        return data_;
    }

    inline const unsigned char* raw_data() const
    {
        return data_.getBytes();
    }

    inline unsigned char* raw_data()
    {
        return data_.getBytes();
    }

    inline image_view<image_data_32> get_view(unsigned x,unsigned y, unsigned w,unsigned h)
    {
        return image_view<image_data_32>(x,y,w,h,data_);
    }

private:

    inline bool checkBounds(unsigned x, unsigned y) const
    {
        return (x < width_ && y < height_);
    }

public:
    inline void setPixel(int x,int y,unsigned int rgba)
    {
        if (checkBounds(x,y))
        {
            data_(x,y)=rgba;
        }
    }
    inline void blendPixel(int x,int y,unsigned int rgba1,int t)
    {
        blendPixel2(x,y,rgba1,t,1.0);  // do not change opacity
    }

    inline void blendPixel2(int x,int y,unsigned int rgba1,int t,double opacity)
    {
        if (checkBounds(x,y))
        {
            unsigned rgba0 = data_(x,y);
#ifdef MAPNIK_BIG_ENDIAN
            unsigned a1 = (int)((rgba1 & 0xff) * opacity) & 0xff; // adjust for desired opacity
            a1 = (t*a1) / 255;
            if (a1 == 0) return;
            unsigned r1 = (rgba1 >> 24) & 0xff;
            unsigned g1 = (rgba1 >> 16 ) & 0xff;
            unsigned b1 = (rgba1 >> 8) & 0xff;

            unsigned a0 = (rgba0 & 0xff);
            unsigned r0 = ((rgba0 >> 24 ) & 0xff) * a0;
            unsigned g0 = ((rgba0 >> 16 ) & 0xff) * a0;
            unsigned b0 = ((rgba0 >> 8) & 0xff) * a0;

            a0 = ((a1 + a0) << 8) - a0*a1;

            r0 = ((((r1 << 8) - r0) * a1 + (r0 << 8)) / a0);
            g0 = ((((g1 << 8) - g0) * a1 + (g0 << 8)) / a0);
            b0 = ((((b1 << 8) - b0) * a1 + (b0 << 8)) / a0);
            a0 = a0 >> 8;
            data_(x,y)= (a0)| (b0 << 8) |  (g0 << 16) | (r0 << 24) ;
#else
            unsigned a1 = (int)(((rgba1 >> 24) & 0xff) * opacity) & 0xff; // adjust for desired opacity
            a1 = (t*a1) / 255;
            if (a1 == 0) return;
            unsigned r1 = rgba1 & 0xff;
            unsigned g1 = (rgba1 >> 8 ) & 0xff;
            unsigned b1 = (rgba1 >> 16) & 0xff;

            unsigned a0 = (rgba0 >> 24) & 0xff;
            unsigned r0 = (rgba0 & 0xff) * a0;
            unsigned g0 = ((rgba0 >> 8 ) & 0xff) * a0;
            unsigned b0 = ((rgba0 >> 16) & 0xff) * a0;

            a0 = ((a1 + a0) << 8) - a0*a1;

            r0 = ((((r1 << 8) - r0) * a1 + (r0 << 8)) / a0);
            g0 = ((((g1 << 8) - g0) * a1 + (g0 << 8)) / a0);
            b0 = ((((b1 << 8) - b0) * a1 + (b0 << 8)) / a0);
            a0 = a0 >> 8;
            data_(x,y)= (a0 << 24)| (b0 << 16) |  (g0 << 8) | (r0) ;
#endif
        }
    }

    inline unsigned width() const
    {
        return width_;
    }

    inline unsigned height() const
    {
        return height_;
    }

    inline void set_rectangle(int x0,int y0,image_data_32 const& data)
    {
        box2d<int> ext0(0,0,width_,height_);
        box2d<int> ext1(x0,y0,x0+data.width(),y0+data.height());

        if (ext0.intersects(ext1))
        {
            box2d<int> box = ext0.intersect(ext1);
            for (int y = box.miny(); y < box.maxy(); ++y)
            {
                unsigned int* row_to =  data_.getRow(y);
                unsigned int const * row_from = data.getRow(y-y0);

                for (int x = box.minx(); x < box.maxx(); ++x)
                {
#ifdef MAPNIK_BIG_ENDIAN
                    row_to[x] = row_from[x-x0];
#else
                    if (row_from[x-x0] & 0xff000000)
                    {
                        row_to[x] = row_from[x-x0];
                    }
#endif
                }
            }
        }
    }

    inline void set_rectangle_alpha(int x0,int y0,const image_data_32& data)
    {
        box2d<int> ext0(0,0,width_,height_);
        box2d<int> ext1(x0,y0,x0 + data.width(),y0 + data.height());

        if (ext0.intersects(ext1))
        {
            box2d<int> box = ext0.intersect(ext1);
            for (int y = box.miny(); y < box.maxy(); ++y)
            {
                unsigned int* row_to =  data_.getRow(y);
                unsigned int const * row_from = data.getRow(y-y0);
                for (int x = box.minx(); x < box.maxx(); ++x)
                {
                    unsigned rgba0 = row_to[x];
                    unsigned rgba1 = row_from[x-x0];

#ifdef MAPNIK_BIG_ENDIAN
                    unsigned a1 = rgba1 & 0xff;
                    if (a1 == 0) continue;
                    if (a1 == 0xff)
                    {
                        row_to[x] = rgba1;
                        continue;
                    }
                    unsigned r1 = (rgba1 >> 24) & 0xff;
                    unsigned g1 = (rgba1 >> 16 ) & 0xff;
                    unsigned b1 = (rgba1 >> 8) & 0xff;

                    unsigned a0 = rgba0 & 0xff;
                    unsigned r0 = ((rgba0 >> 24) & 0xff) * a0;
                    unsigned g0 = ((rgba0 >> 16 ) & 0xff) * a0;
                    unsigned b0 = ((rgba0 >> 8) & 0xff) * a0;

                    a0 = ((a1 + a0) << 8) - a0*a1;

                    r0 = ((((r1 << 8) - r0) * a1 + (r0 << 8)) / a0);
                    g0 = ((((g1 << 8) - g0) * a1 + (g0 << 8)) / a0);
                    b0 = ((((b1 << 8) - b0) * a1 + (b0 << 8)) / a0);
                    a0 = a0 >> 8;
                    row_to[x] = (a0) | (b0 << 8) |  (g0 << 16) | (r0 << 24) ;
#else
                    unsigned a1 = (rgba1 >> 24) & 0xff;
                    if (a1 == 0) continue;
                    if (a1 == 0xff)
                    {
                        row_to[x] = rgba1;
                        continue;
                    }
                    unsigned r1 = rgba1 & 0xff;
                    unsigned g1 = (rgba1 >> 8 ) & 0xff;
                    unsigned b1 = (rgba1 >> 16) & 0xff;

                    unsigned a0 = (rgba0 >> 24) & 0xff;
                    unsigned r0 = (rgba0 & 0xff) * a0;
                    unsigned g0 = ((rgba0 >> 8 ) & 0xff) * a0;
                    unsigned b0 = ((rgba0 >> 16) & 0xff) * a0;

                    a0 = ((a1 + a0) << 8) - a0*a1;

                    r0 = ((((r1 << 8) - r0) * a1 + (r0 << 8)) / a0);
                    g0 = ((((g1 << 8) - g0) * a1 + (g0 << 8)) / a0);
                    b0 = ((((b1 << 8) - b0) * a1 + (b0 << 8)) / a0);
                    a0 = a0 >> 8;
                    row_to[x] = (a0 << 24)| (b0 << 16) |  (g0 << 8) | (r0) ;
#endif
                }
            }
        }
    }

    inline void set_rectangle_alpha2(image_data_32 const& data, unsigned x0, unsigned y0, float opacity)
    {
        box2d<int> ext0(0,0,width_,height_);
        box2d<int> ext1(x0,y0,x0 + data.width(),y0 + data.height());

        if (ext0.intersects(ext1))
        {
            box2d<int> box = ext0.intersect(ext1);
            for (int y = box.miny(); y < box.maxy(); ++y)
            {
                unsigned int* row_to =  data_.getRow(y);
                unsigned int const * row_from = data.getRow(y-y0);
                for (int x = box.minx(); x < box.maxx(); ++x)
                {
                    unsigned rgba0 = row_to[x];
                    unsigned rgba1 = row_from[x-x0];
#ifdef MAPNIK_BIG_ENDIAN
                    unsigned a1 = int( (rgba1 & 0xff) * opacity );
                    if (a1 == 0) continue;
                    if (a1 == 0xff)
                    {
                        row_to[x] = rgba1;
                        continue;
                    }
                    unsigned r1 = (rgba1 >> 24) & 0xff;
                    unsigned g1 = (rgba1 >> 16 ) & 0xff;
                    unsigned b1 = (rgba1 >> 8) & 0xff;

                    unsigned a0 = rgba0 & 0xff;
                    unsigned r0 = (rgba0 >> 24) & 0xff ;
                    unsigned g0 = (rgba0 >> 16 ) & 0xff;
                    unsigned b0 = (rgba0 >> 8) & 0xff;

                    unsigned atmp = a1 + a0 - ((a1 * a0 + 255) >> 8);
                    if (atmp)
                    {
                        r0 = byte((r1 * a1 + (r0 * a0) - ((r0 * a0 * a1 + 255) >> 8)) / atmp);
                        g0 = byte((g1 * a1 + (g0 * a0) - ((g0 * a0 * a1 + 255) >> 8)) / atmp);
                        b0 = byte((b1 * a1 + (b0 * a0) - ((b0 * a0 * a1 + 255) >> 8)) / atmp);
                    }
                    a0 = byte(atmp);

                    row_to[x] = (a0)| (b0 << 8) |  (g0 << 16) | (r0 << 24) ;
#else
                    unsigned a1 = int( ((rgba1 >> 24) & 0xff) * opacity );
                    if (a1 == 0) continue;
                    if (a1 == 0xff)
                    {
                        row_to[x] = rgba1;
                        continue;
                    }
                    unsigned r1 = rgba1 & 0xff;
                    unsigned g1 = (rgba1 >> 8 ) & 0xff;
                    unsigned b1 = (rgba1 >> 16) & 0xff;

                    unsigned a0 = (rgba0 >> 24) & 0xff;
                    unsigned r0 = rgba0 & 0xff ;
                    unsigned g0 = (rgba0 >> 8 ) & 0xff;
                    unsigned b0 = (rgba0 >> 16) & 0xff;
                    
                    unsigned atmp = a1 + a0 - ((a1 * a0 + 255) >> 8);
                    if (atmp)
                    {
                        r0 = byte((r1 * a1 + (r0 * a0) - ((r0 * a0 * a1 + 255) >> 8)) / atmp);
                        g0 = byte((g1 * a1 + (g0 * a0) - ((g0 * a0 * a1 + 255) >> 8)) / atmp);
                        b0 = byte((b1 * a1 + (b0 * a0) - ((b0 * a0 * a1 + 255) >> 8)) / atmp);
                    }
                    a0 = byte(atmp);
                    
                    row_to[x] = (a0 << 24)| (b0 << 16) |  (g0 << 8) | (r0) ;
#endif
                }
            }
        }
    }

    template <typename MergeMethod>
        inline void merge_rectangle(image_data_32 const& data, unsigned x0, unsigned y0, float opacity)
    {
        box2d<int> ext0(0,0,width_,height_);
        box2d<int> ext1(x0,y0,x0 + data.width(),y0 + data.height());

        if (ext0.intersects(ext1))
        {
            box2d<int> box = ext0.intersect(ext1);
            for (int y = box.miny(); y < box.maxy(); ++y)
            {
                unsigned int* row_to =  data_.getRow(y);
                unsigned int const * row_from = data.getRow(y-y0);
                for (int x = box.minx(); x < box.maxx(); ++x)
                {
                    unsigned rgba0 = row_to[x];
                    unsigned rgba1 = row_from[x-x0];
#ifdef MAPNIK_BIG_ENDIAN
                    unsigned a1 = int( (rgba1 & 0xff) * opacity );
                    if (a1 == 0) continue;
                    unsigned r1 = (rgba1 >> 24)& 0xff;
                    unsigned g1 = (rgba1 >> 16 ) & 0xff;
                    unsigned b1 = (rgba1 >> 8) & 0xff;

                    unsigned a0 = rgba0 & 0xff;
                    unsigned r0 = (rgba0 >> 24) & 0xff ;
                    unsigned g0 = (rgba0 >> 16 ) & 0xff;
                    unsigned b0 = (rgba0 >> 8) & 0xff;

                    unsigned a = (a1 * 255 + (255 - a1) * a0 + 127)/255;

                    MergeMethod::mergeRGB(r0,g0,b0,r1,g1,b1);

                    r0 = (r1*a1 + (((255 - a1) * a0 + 127)/255) * r0 + 127)/a;
                    g0 = (g1*a1 + (((255 - a1) * a0 + 127)/255) * g0 + 127)/a;
                    b0 = (b1*a1 + (((255 - a1) * a0 + 127)/255) * b0 + 127)/a;

                    row_to[x] = (a)| (b0 << 8) |  (g0 << 16) | (r0 << 24) ;
#else
                    unsigned a1 = int( ((rgba1 >> 24) & 0xff) * opacity );
                    if (a1 == 0) continue;
                    unsigned r1 = rgba1 & 0xff;
                    unsigned g1 = (rgba1 >> 8 ) & 0xff;
                    unsigned b1 = (rgba1 >> 16) & 0xff;

                    unsigned a0 = (rgba0 >> 24) & 0xff;
                    unsigned r0 = rgba0 & 0xff ;
                    unsigned g0 = (rgba0 >> 8 ) & 0xff;
                    unsigned b0 = (rgba0 >> 16) & 0xff;

                    unsigned a = (a1 * 255 + (255 - a1) * a0 + 127)/255;

                    MergeMethod::mergeRGB(r0,g0,b0,r1,g1,b1);

                    r0 = (r1*a1 + (((255 - a1) * a0 + 127)/255) * r0 + 127)/a;
                    g0 = (g1*a1 + (((255 - a1) * a0 + 127)/255) * g0 + 127)/a;
                    b0 = (b1*a1 + (((255 - a1) * a0 + 127)/255) * b0 + 127)/a;

                    row_to[x] = (a << 24)| (b0 << 16) |  (g0 << 8) | (r0) ;
#endif
                }
            }
        }
    }
};
}
#endif //GRAPHICS_HPP