~kalon33/corsix-th/master

« back to all changes in this revision

Viewing changes to agg/include/agg_span_image_filter_rgb.h

  • Committer: corsixth.bot at gmail
  • Date: 2014-03-31 23:30:23 UTC
  • Revision ID: svn-v4:c39591fa-788f-11de-a72b-d90af8dea425:trunk:2687
Remove trailing whitespaces in .h, .cpp, .c and .lua files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
// Anti-Grain Geometry - Version 2.4
3
3
// Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
4
4
//
5
 
// Permission to copy, use, modify, sell and distribute this software 
6
 
// is granted provided this copyright notice appears in all copies. 
 
5
// Permission to copy, use, modify, sell and distribute this software
 
6
// is granted provided this copyright notice appears in all copies.
7
7
// This software is provided "as is" without express or implied
8
8
// warranty, and with no claim as to its suitability for any purpose.
9
9
//
13
13
//          http://www.antigrain.com
14
14
//----------------------------------------------------------------------------
15
15
//
16
 
// Adaptation for high precision colors has been sponsored by 
 
16
// Adaptation for high precision colors has been sponsored by
17
17
// Liberty Technology Systems, Inc., visit http://lib-sys.com
18
18
//
19
19
// Liberty Technology Systems, Inc. is the provider of
20
20
// PostScript and PDF technology for software developers.
21
 
// 
 
21
//
22
22
//----------------------------------------------------------------------------
23
23
#ifndef AGG_SPAN_IMAGE_FILTER_RGB_INCLUDED
24
24
#define AGG_SPAN_IMAGE_FILTER_RGB_INCLUDED
32
32
{
33
33
 
34
34
    //===============================================span_image_filter_rgb_nn
35
 
    template<class Source, class Interpolator> 
36
 
    class span_image_filter_rgb_nn : 
 
35
    template<class Source, class Interpolator>
 
36
    class span_image_filter_rgb_nn :
37
37
    public span_image_filter<Source, Interpolator>
38
38
    {
39
39
    public:
52
52
 
53
53
        //--------------------------------------------------------------------
54
54
        span_image_filter_rgb_nn() {}
55
 
        span_image_filter_rgb_nn(source_type& src, 
 
55
        span_image_filter_rgb_nn(source_type& src,
56
56
                                 interpolator_type& inter) :
57
 
            base_type(src, inter, 0) 
 
57
            base_type(src, inter, 0)
58
58
        {}
59
59
 
60
60
        //--------------------------------------------------------------------
61
61
        void generate(color_type* span, int x, int y, unsigned len)
62
62
        {
63
 
            base_type::interpolator().begin(x + base_type::filter_dx_dbl(), 
 
63
            base_type::interpolator().begin(x + base_type::filter_dx_dbl(),
64
64
                                            y + base_type::filter_dy_dbl(), len);
65
65
            do
66
66
            {
67
67
                base_type::interpolator().coordinates(&x, &y);
68
68
                const value_type* fg_ptr = (const value_type*)
69
 
                    base_type::source().span(x >> image_subpixel_shift, 
70
 
                                             y >> image_subpixel_shift, 
 
69
                    base_type::source().span(x >> image_subpixel_shift,
 
70
                                             y >> image_subpixel_shift,
71
71
                                             1);
72
72
                span->r = fg_ptr[order_type::R];
73
73
                span->g = fg_ptr[order_type::G];
83
83
 
84
84
 
85
85
    //==========================================span_image_filter_rgb_bilinear
86
 
    template<class Source, class Interpolator> 
87
 
    class span_image_filter_rgb_bilinear : 
 
86
    template<class Source, class Interpolator>
 
87
    class span_image_filter_rgb_bilinear :
88
88
    public span_image_filter<Source, Interpolator>
89
89
    {
90
90
    public:
103
103
 
104
104
        //--------------------------------------------------------------------
105
105
        span_image_filter_rgb_bilinear() {}
106
 
        span_image_filter_rgb_bilinear(source_type& src, 
 
106
        span_image_filter_rgb_bilinear(source_type& src,
107
107
                                       interpolator_type& inter) :
108
 
            base_type(src, inter, 0) 
 
108
            base_type(src, inter, 0)
109
109
        {}
110
110
 
111
111
 
112
112
        //--------------------------------------------------------------------
113
113
        void generate(color_type* span, int x, int y, unsigned len)
114
114
        {
115
 
            base_type::interpolator().begin(x + base_type::filter_dx_dbl(), 
 
115
            base_type::interpolator().begin(x + base_type::filter_dx_dbl(),
116
116
                                            y + base_type::filter_dy_dbl(), len);
117
117
            calc_type fg[3];
118
118
            const value_type *fg_ptr;
131
131
 
132
132
                unsigned weight;
133
133
 
134
 
                fg[0] = 
135
 
                fg[1] = 
 
134
                fg[0] =
 
135
                fg[1] =
136
136
                fg[2] = image_subpixel_scale * image_subpixel_scale / 2;
137
137
 
138
138
                x_hr &= image_subpixel_mask;
139
139
                y_hr &= image_subpixel_mask;
140
140
 
141
141
                fg_ptr = (const value_type*)base_type::source().span(x_lr, y_lr, 2);
142
 
                weight = (image_subpixel_scale - x_hr) * 
 
142
                weight = (image_subpixel_scale - x_hr) *
143
143
                         (image_subpixel_scale - y_hr);
144
144
                fg[0] += weight * *fg_ptr++;
145
145
                fg[1] += weight * *fg_ptr++;
178
178
 
179
179
 
180
180
    //=====================================span_image_filter_rgb_bilinear_clip
181
 
    template<class Source, class Interpolator> 
182
 
    class span_image_filter_rgb_bilinear_clip : 
 
181
    template<class Source, class Interpolator>
 
182
    class span_image_filter_rgb_bilinear_clip :
183
183
    public span_image_filter<Source, Interpolator>
184
184
    {
185
185
    public:
198
198
 
199
199
        //--------------------------------------------------------------------
200
200
        span_image_filter_rgb_bilinear_clip() {}
201
 
        span_image_filter_rgb_bilinear_clip(source_type& src, 
 
201
        span_image_filter_rgb_bilinear_clip(source_type& src,
202
202
                                            const color_type& back_color,
203
203
                                            interpolator_type& inter) :
204
204
            base_type(src, inter, 0),
210
210
        //--------------------------------------------------------------------
211
211
        void generate(color_type* span, int x, int y, unsigned len)
212
212
        {
213
 
            base_type::interpolator().begin(x + base_type::filter_dx_dbl(), 
 
213
            base_type::interpolator().begin(x + base_type::filter_dx_dbl(),
214
214
                                            y + base_type::filter_dy_dbl(), len);
215
215
            calc_type fg[3];
216
216
            calc_type src_alpha;
228
228
            {
229
229
                int x_hr;
230
230
                int y_hr;
231
 
                
 
231
 
232
232
                base_type::interpolator().coordinates(&x_hr, &y_hr);
233
233
 
234
234
                x_hr -= base_type::filter_dx_int();
239
239
                unsigned weight;
240
240
 
241
241
                if(x_lr >= 0    && y_lr >= 0 &&
242
 
                   x_lr <  maxx && y_lr <  maxy) 
 
242
                   x_lr <  maxx && y_lr <  maxy)
243
243
                {
244
 
                    fg[0] = 
245
 
                    fg[1] = 
 
244
                    fg[0] =
 
245
                    fg[1] =
246
246
                    fg[2] = image_subpixel_scale * image_subpixel_scale / 2;
247
247
 
248
248
                    x_hr &= image_subpixel_mask;
251
251
                    fg_ptr = (const value_type*)
252
252
                        base_type::source().row_ptr(y_lr) + x_lr + x_lr + x_lr;
253
253
 
254
 
                    weight = (image_subpixel_scale - x_hr) * 
 
254
                    weight = (image_subpixel_scale - x_hr) *
255
255
                             (image_subpixel_scale - y_hr);
256
256
                    fg[0] += weight * *fg_ptr++;
257
257
                    fg[1] += weight * *fg_ptr++;
293
293
                    }
294
294
                    else
295
295
                    {
296
 
                        fg[0] = 
297
 
                        fg[1] = 
298
 
                        fg[2] = 
 
296
                        fg[0] =
 
297
                        fg[1] =
 
298
                        fg[2] =
299
299
                        src_alpha = image_subpixel_scale * image_subpixel_scale / 2;
300
300
 
301
301
                        x_hr &= image_subpixel_mask;
302
302
                        y_hr &= image_subpixel_mask;
303
303
 
304
 
                        weight = (image_subpixel_scale - x_hr) * 
 
304
                        weight = (image_subpixel_scale - x_hr) *
305
305
                                 (image_subpixel_scale - y_hr);
306
306
                        if(x_lr >= 0    && y_lr >= 0 &&
307
307
                           x_lr <= maxx && y_lr <= maxy)
412
412
 
413
413
 
414
414
    //===============================================span_image_filter_rgb_2x2
415
 
    template<class Source, class Interpolator> 
416
 
    class span_image_filter_rgb_2x2 : 
 
415
    template<class Source, class Interpolator>
 
416
    class span_image_filter_rgb_2x2 :
417
417
    public span_image_filter<Source, Interpolator>
418
418
    {
419
419
    public:
432
432
 
433
433
        //--------------------------------------------------------------------
434
434
        span_image_filter_rgb_2x2() {}
435
 
        span_image_filter_rgb_2x2(source_type& src, 
 
435
        span_image_filter_rgb_2x2(source_type& src,
436
436
                                  interpolator_type& inter,
437
437
                                  const image_filter_lut& filter) :
438
 
            base_type(src, inter, &filter) 
 
438
            base_type(src, inter, &filter)
439
439
        {}
440
440
 
441
441
 
442
442
        //--------------------------------------------------------------------
443
443
        void generate(color_type* span, int x, int y, unsigned len)
444
444
        {
445
 
            base_type::interpolator().begin(x + base_type::filter_dx_dbl(), 
 
445
            base_type::interpolator().begin(x + base_type::filter_dx_dbl(),
446
446
                                            y + base_type::filter_dy_dbl(), len);
447
447
 
448
448
            calc_type fg[3];
449
449
 
450
450
            const value_type *fg_ptr;
451
 
            const int16* weight_array = base_type::filter().weight_array() + 
452
 
                                        ((base_type::filter().diameter()/2 - 1) << 
 
451
            const int16* weight_array = base_type::filter().weight_array() +
 
452
                                        ((base_type::filter().diameter()/2 - 1) <<
453
453
                                          image_subpixel_shift);
454
454
            do
455
455
            {
471
471
                y_hr &= image_subpixel_mask;
472
472
 
473
473
                fg_ptr = (const value_type*)base_type::source().span(x_lr, y_lr, 2);
474
 
                weight = (weight_array[x_hr + image_subpixel_scale] * 
475
 
                          weight_array[y_hr + image_subpixel_scale] + 
476
 
                          image_filter_scale / 2) >> 
 
474
                weight = (weight_array[x_hr + image_subpixel_scale] *
 
475
                          weight_array[y_hr + image_subpixel_scale] +
 
476
                          image_filter_scale / 2) >>
477
477
                          image_filter_shift;
478
478
                fg[0] += weight * *fg_ptr++;
479
479
                fg[1] += weight * *fg_ptr++;
480
480
                fg[2] += weight * *fg_ptr;
481
481
 
482
482
                fg_ptr = (const value_type*)base_type::source().next_x();
483
 
                weight = (weight_array[x_hr] * 
484
 
                          weight_array[y_hr + image_subpixel_scale] + 
485
 
                          image_filter_scale / 2) >> 
 
483
                weight = (weight_array[x_hr] *
 
484
                          weight_array[y_hr + image_subpixel_scale] +
 
485
                          image_filter_scale / 2) >>
486
486
                          image_filter_shift;
487
487
                fg[0] += weight * *fg_ptr++;
488
488
                fg[1] += weight * *fg_ptr++;
489
489
                fg[2] += weight * *fg_ptr;
490
490
 
491
491
                fg_ptr = (const value_type*)base_type::source().next_y();
492
 
                weight = (weight_array[x_hr + image_subpixel_scale] * 
493
 
                          weight_array[y_hr] + 
494
 
                          image_filter_scale / 2) >> 
 
492
                weight = (weight_array[x_hr + image_subpixel_scale] *
 
493
                          weight_array[y_hr] +
 
494
                          image_filter_scale / 2) >>
495
495
                          image_filter_shift;
496
496
                fg[0] += weight * *fg_ptr++;
497
497
                fg[1] += weight * *fg_ptr++;
498
498
                fg[2] += weight * *fg_ptr;
499
499
 
500
500
                fg_ptr = (const value_type*)base_type::source().next_x();
501
 
                weight = (weight_array[x_hr] * 
502
 
                          weight_array[y_hr] + 
503
 
                          image_filter_scale / 2) >> 
 
501
                weight = (weight_array[x_hr] *
 
502
                          weight_array[y_hr] +
 
503
                          image_filter_scale / 2) >>
504
504
                          image_filter_shift;
505
505
                fg[0] += weight * *fg_ptr++;
506
506
                fg[1] += weight * *fg_ptr++;
529
529
 
530
530
 
531
531
    //===================================================span_image_filter_rgb
532
 
    template<class Source, class Interpolator> 
533
 
    class span_image_filter_rgb : 
 
532
    template<class Source, class Interpolator>
 
533
    class span_image_filter_rgb :
534
534
    public span_image_filter<Source, Interpolator>
535
535
    {
536
536
    public:
549
549
 
550
550
        //--------------------------------------------------------------------
551
551
        span_image_filter_rgb() {}
552
 
        span_image_filter_rgb(source_type& src, 
 
552
        span_image_filter_rgb(source_type& src,
553
553
                              interpolator_type& inter,
554
554
                              const image_filter_lut& filter) :
555
 
            base_type(src, inter, &filter) 
 
555
            base_type(src, inter, &filter)
556
556
        {}
557
557
 
558
558
        //--------------------------------------------------------------------
559
559
        void generate(color_type* span, int x, int y, unsigned len)
560
560
        {
561
 
            base_type::interpolator().begin(x + base_type::filter_dx_dbl(), 
 
561
            base_type::interpolator().begin(x + base_type::filter_dx_dbl(),
562
562
                                            y + base_type::filter_dy_dbl(), len);
563
563
 
564
564
            int fg[3];
568
568
            int          start        = base_type::filter().start();
569
569
            const int16* weight_array = base_type::filter().weight_array();
570
570
 
571
 
            int x_count; 
 
571
            int x_count;
572
572
            int weight_y;
573
573
 
574
574
            do
578
578
                x -= base_type::filter_dx_int();
579
579
                y -= base_type::filter_dy_int();
580
580
 
581
 
                int x_hr = x; 
582
 
                int y_hr = y; 
 
581
                int x_hr = x;
 
582
                int y_hr = y;
583
583
 
584
584
                int x_lr = x_hr >> image_subpixel_shift;
585
585
                int y_lr = y_hr >> image_subpixel_shift;
590
590
                unsigned y_count = diameter;
591
591
 
592
592
                y_hr = image_subpixel_mask - (y_hr & image_subpixel_mask);
593
 
                fg_ptr = (const value_type*)base_type::source().span(x_lr + start, 
594
 
                                                                     y_lr + start, 
 
593
                fg_ptr = (const value_type*)base_type::source().span(x_lr + start,
 
594
                                                                     y_lr + start,
595
595
                                                                     diameter);
596
596
                for(;;)
597
597
                {
600
600
                    x_hr = image_subpixel_mask - x_fract;
601
601
                    for(;;)
602
602
                    {
603
 
                        int weight = (weight_y * weight_array[x_hr] + 
604
 
                                     image_filter_scale / 2) >> 
 
603
                        int weight = (weight_y * weight_array[x_hr] +
 
604
                                     image_filter_scale / 2) >>
605
605
                                     image_filter_shift;
606
606
 
607
607
                        fg[0] += weight * *fg_ptr++;
645
645
 
646
646
 
647
647
    //==========================================span_image_resample_rgb_affine
648
 
    template<class Source> 
649
 
    class span_image_resample_rgb_affine : 
 
648
    template<class Source>
 
649
    class span_image_resample_rgb_affine :
650
650
    public span_image_resample_affine<Source>
651
651
    {
652
652
    public:
666
666
 
667
667
        //--------------------------------------------------------------------
668
668
        span_image_resample_rgb_affine() {}
669
 
        span_image_resample_rgb_affine(source_type& src, 
 
669
        span_image_resample_rgb_affine(source_type& src,
670
670
                                       interpolator_type& inter,
671
671
                                       const image_filter_lut& filter) :
672
 
            base_type(src, inter, filter) 
 
672
            base_type(src, inter, filter)
673
673
        {}
674
674
 
675
675
 
676
676
        //--------------------------------------------------------------------
677
677
        void generate(color_type* span, int x, int y, unsigned len)
678
678
        {
679
 
            base_type::interpolator().begin(x + base_type::filter_dx_dbl(), 
 
679
            base_type::interpolator().begin(x + base_type::filter_dx_dbl(),
680
680
                                            y + base_type::filter_dy_dbl(), len);
681
681
 
682
682
            long_type fg[3];
685
685
            int filter_scale = diameter << image_subpixel_shift;
686
686
            int radius_x     = (diameter * base_type::m_rx) >> 1;
687
687
            int radius_y     = (diameter * base_type::m_ry) >> 1;
688
 
            int len_x_lr     = 
689
 
                (diameter * base_type::m_rx + image_subpixel_mask) >> 
 
688
            int len_x_lr     =
 
689
                (diameter * base_type::m_rx + image_subpixel_mask) >>
690
690
                    image_subpixel_shift;
691
691
 
692
692
            const int16* weight_array = base_type::filter().weight_array();
701
701
                fg[0] = fg[1] = fg[2] = image_filter_scale / 2;
702
702
 
703
703
                int y_lr = y >> image_subpixel_shift;
704
 
                int y_hr = ((image_subpixel_mask - (y & image_subpixel_mask)) * 
705
 
                                base_type::m_ry_inv) >> 
 
704
                int y_hr = ((image_subpixel_mask - (y & image_subpixel_mask)) *
 
705
                                base_type::m_ry_inv) >>
706
706
                                    image_subpixel_shift;
707
707
                int total_weight = 0;
708
708
                int x_lr = x >> image_subpixel_shift;
709
 
                int x_hr = ((image_subpixel_mask - (x & image_subpixel_mask)) * 
710
 
                                base_type::m_rx_inv) >> 
 
709
                int x_hr = ((image_subpixel_mask - (x & image_subpixel_mask)) *
 
710
                                base_type::m_rx_inv) >>
711
711
                                    image_subpixel_shift;
712
712
 
713
713
                int x_hr2 = x_hr;
714
 
                const value_type* fg_ptr = 
 
714
                const value_type* fg_ptr =
715
715
                    (const value_type*)base_type::source().span(x_lr, y_lr, len_x_lr);
716
716
                for(;;)
717
717
                {
719
719
                    x_hr = x_hr2;
720
720
                    for(;;)
721
721
                    {
722
 
                        int weight = (weight_y * weight_array[x_hr] + 
723
 
                                     image_filter_scale / 2) >> 
 
722
                        int weight = (weight_y * weight_array[x_hr] +
 
723
                                     image_filter_scale / 2) >>
724
724
                                     downscale_shift;
725
725
 
726
726
                        fg[0] += *fg_ptr++ * weight;
763
763
 
764
764
    //=================================================span_image_resample_rgb
765
765
    template<class Source, class Interpolator>
766
 
    class span_image_resample_rgb : 
 
766
    class span_image_resample_rgb :
767
767
    public span_image_resample<Source, Interpolator>
768
768
    {
769
769
    public:
783
783
 
784
784
        //--------------------------------------------------------------------
785
785
        span_image_resample_rgb() {}
786
 
        span_image_resample_rgb(source_type& src, 
 
786
        span_image_resample_rgb(source_type& src,
787
787
                                interpolator_type& inter,
788
788
                                const image_filter_lut& filter) :
789
789
            base_type(src, inter, filter)
792
792
        //--------------------------------------------------------------------
793
793
        void generate(color_type* span, int x, int y, unsigned len)
794
794
        {
795
 
            base_type::interpolator().begin(x + base_type::filter_dx_dbl(), 
 
795
            base_type::interpolator().begin(x + base_type::filter_dx_dbl(),
796
796
                                            y + base_type::filter_dy_dbl(), len);
797
797
            long_type fg[3];
798
798
 
815
815
 
816
816
                int radius_x = (diameter * rx) >> 1;
817
817
                int radius_y = (diameter * ry) >> 1;
818
 
                int len_x_lr = 
819
 
                    (diameter * rx + image_subpixel_mask) >> 
 
818
                int len_x_lr =
 
819
                    (diameter * rx + image_subpixel_mask) >>
820
820
                        image_subpixel_shift;
821
821
 
822
822
                x += base_type::filter_dx_int() - radius_x;
825
825
                fg[0] = fg[1] = fg[2] = image_filter_scale / 2;
826
826
 
827
827
                int y_lr = y >> image_subpixel_shift;
828
 
                int y_hr = ((image_subpixel_mask - (y & image_subpixel_mask)) * 
829
 
                               ry_inv) >> 
 
828
                int y_hr = ((image_subpixel_mask - (y & image_subpixel_mask)) *
 
829
                               ry_inv) >>
830
830
                                   image_subpixel_shift;
831
831
                int total_weight = 0;
832
832
                int x_lr = x >> image_subpixel_shift;
833
 
                int x_hr = ((image_subpixel_mask - (x & image_subpixel_mask)) * 
834
 
                               rx_inv) >> 
 
833
                int x_hr = ((image_subpixel_mask - (x & image_subpixel_mask)) *
 
834
                               rx_inv) >>
835
835
                                   image_subpixel_shift;
836
836
                int x_hr2 = x_hr;
837
 
                const value_type* fg_ptr = 
 
837
                const value_type* fg_ptr =
838
838
                    (const value_type*)base_type::source().span(x_lr, y_lr, len_x_lr);
839
839
 
840
840
                for(;;)
843
843
                    x_hr = x_hr2;
844
844
                    for(;;)
845
845
                    {
846
 
                        int weight = (weight_y * weight_array[x_hr] + 
847
 
                                     image_filter_scale / 2) >> 
 
846
                        int weight = (weight_y * weight_array[x_hr] +
 
847
                                     image_filter_scale / 2) >>
848
848
                                     downscale_shift;
849
849
                        fg[0] += *fg_ptr++ * weight;
850
850
                        fg[1] += *fg_ptr++ * weight;