~ubuntu-branches/ubuntu/gutsy/avscan/gutsy

« back to all changes in this revision

Viewing changes to avscan/guirgbimg.c

  • Committer: Bazaar Package Importer
  • Author(s): Christoph Berg
  • Date: 2007-08-12 14:22:25 UTC
  • mfrom: (1.9.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20070812142225-2whp6690lilo2wg8
Tags: 3.2.1-openssl-2
Correctly handle DEB_BUILD_OPTIONS=nostrip (Closes: #436496).

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
#include <gdk/gdkprivate.h>
4
4
#if defined(_WIN32)
5
5
# include <gdk/gdkwin32.h>
 
6
# define HAVE_WIN32
6
7
#else
7
8
# include <gdk/gdkx.h>
8
9
# define HAVE_X
22
23
);
23
24
 
24
25
void GUIImageBufferCopyArea(
25
 
        gint bpp,
 
26
        const gint bpp,
26
27
        const guint8 *src_data,
27
 
        gint src_width, gint src_height, gint src_bpl,
 
28
        const gint src_width, const gint src_height, const gint src_bpl,
28
29
        guint8 *tar_data,
29
 
        gint tar_width, gint tar_height, gint tar_bpl,
30
 
        gint tar_x, gint tar_y,
 
30
        const gint tar_width, const gint tar_height, const gint tar_bpl,
 
31
        const gint tar_x, const gint tar_y,
31
32
        const gboolean blend,
32
33
        gint (*progress_cb)(const gulong, const gulong, gpointer),
33
34
        gpointer progress_data
42
43
        gpointer progress_data
43
44
);
44
45
void GUIImageBufferRotateCW90(
45
 
        gint bpp,
 
46
        const gint bpp,
46
47
        const guint8 *src_data,
47
 
        gint src_width, gint src_height, gint src_bpl,
 
48
        const gint src_width, const gint src_height, const gint src_bpl,
48
49
        guint8 *tar_data,
49
 
        gint tar_width, gint tar_height, gint tar_bpl
 
50
        const gint tar_width, const gint tar_height, const gint tar_bpl
50
51
);
51
52
void GUIImageBufferRotateCCW90(
52
 
        gint bpp,
 
53
        const gint bpp,
53
54
        const guint8 *src_data,
54
 
        gint src_width, gint src_height, gint src_bpl,
 
55
        const gint src_width, const gint src_height, const gint src_bpl,
55
56
        guint8 *tar_data,
56
 
        gint tar_width, gint tar_height, gint tar_bpl
 
57
        const gint tar_width, const gint tar_height, const gint tar_bpl
57
58
);
58
59
void GUIImageBufferRotateCW180(
59
 
        gint bpp,
 
60
        const gint bpp,
60
61
        const guint8 *src_data,
61
 
        gint src_width, gint src_height, gint src_bpl,
 
62
        const gint src_width, const gint src_height, const gint src_bpl,
62
63
        guint8 *tar_data,
63
 
        gint tar_width, gint tar_height, gint tar_bpl
 
64
        const gint tar_width, const gint tar_height, const gint tar_bpl
64
65
);
65
66
void GUIImageBufferMirrorH(
66
 
        gint bpp,
 
67
        const gint bpp,
67
68
        const guint8 *src_data,
68
 
        gint src_width, gint src_height, gint src_bpl,
 
69
        const gint src_width, const gint src_height, const gint src_bpl,
69
70
        guint8 *tar_data, 
70
 
        gint tar_width, gint tar_height, gint tar_bpl
 
71
        const gint tar_width, const gint tar_height, const gint tar_bpl
71
72
);
72
73
void GUIImageBufferMirrorV(
73
 
        gint bpp,
 
74
        const gint bpp,
74
75
        const guint8 *src_data,
75
 
        gint src_width, gint src_height, gint src_bpl,
76
 
        guint8 *tar_data, 
77
 
        gint tar_width, gint tar_height, gint tar_bpl
 
76
        const gint src_width, const gint src_height, const gint src_bpl,
 
77
        guint8 *tar_data,
 
78
        const gint tar_width, const gint tar_height, const gint tar_bpl
78
79
);
79
80
 
80
81
void GUIImageBufferFlattenWithBG(
200
201
 *      the target image's pixel.
201
202
 */
202
203
void GUIImageBufferCopyArea(
203
 
        gint bpp,
 
204
        const gint bpp,
204
205
        const guint8 *src_data,
205
 
        gint src_width, gint src_height, gint src_bpl,
 
206
        const gint src_width, const gint src_height, const gint src_bpl,
206
207
        guint8 *tar_data,
207
 
        gint tar_width, gint tar_height, gint tar_bpl,
208
 
        gint tar_x, gint tar_y,
 
208
        const gint tar_width, const gint tar_height, const gint tar_bpl,
 
209
        const gint tar_x, const gint tar_y,
209
210
        const gboolean blend,
210
211
        gint (*progress_cb)(const gulong, const gulong, gpointer),
211
212
        gpointer progress_data
212
213
)
213
214
{
214
 
        gint x, y, src_y;
 
215
        gint    x, y, src_y,
 
216
                _src_bpl = src_bpl,
 
217
                _tar_bpl = tar_bpl;
215
218
        const guint8 *src_ptr, *src_end;
216
219
        void (*pixel_op_func)(const gint, guint8 *, const guint8 *);
217
220
 
229
232
        }
230
233
 
231
234
        /* Calculate bytes per line values as needed */
232
 
        if(src_bpl <= 0)
233
 
            src_bpl = src_width * bpp;
234
 
        if(tar_bpl <= 0)
235
 
            tar_bpl = tar_width * bpp;
 
235
        if(_src_bpl <= 0)
 
236
            _src_bpl = src_width * bpp;
 
237
        if(_tar_bpl <= 0)
 
238
            _tar_bpl = tar_width * bpp;
236
239
 
237
240
        /* Determine the pixel operation function */
238
241
        switch(bpp)
275
278
            }
276
279
 
277
280
            x = tar_x;
278
 
            src_ptr = src_data + (src_y * src_bpl);
 
281
            src_ptr = src_data + (src_y * _src_bpl);
279
282
            src_end = src_ptr + (src_width * bpp);
280
283
            while(src_ptr < src_end)
281
284
            {
289
292
                     */
290
293
                    pixel_op_func(
291
294
                        bpp,
292
 
                        tar_data + (y * tar_bpl) + (x * bpp),
 
295
                        tar_data + (y * _tar_bpl) + (x * bpp),
293
296
                        src_ptr
294
297
                    );
295
298
                    src_ptr += bpp;
600
603
 *      clockwise 90 degrees.
601
604
 */
602
605
void GUIImageBufferRotateCW90(
603
 
        gint bpp,
 
606
        const gint bpp,
604
607
        const guint8 *src_data,
605
 
        gint src_width, gint src_height, gint src_bpl,
 
608
        const gint src_width, const gint src_height, const gint src_bpl,
606
609
        guint8 *tar_data,
607
 
        gint tar_width, gint tar_height, gint tar_bpl
 
610
        const gint tar_width, const gint tar_height, const gint tar_bpl
608
611
)
609
612
{
610
 
        gint sx, sy, tx, ty;
 
613
        gint    sx, sy, tx, ty,
 
614
                _src_bpl = src_bpl,
 
615
                _tar_bpl = tar_bpl;
611
616
        const guint8 *src_line;
612
617
 
613
618
        if((src_width <= 0) || (src_height <= 0) ||
622
627
            return;
623
628
 
624
629
        /* Calculate bytes per line values as needed */
625
 
        if(src_bpl <= 0)
626
 
            src_bpl = src_width * bpp;
627
 
        if(tar_bpl <= 0)
628
 
            tar_bpl = tar_width * bpp;
 
630
        if(_src_bpl <= 0)
 
631
            _src_bpl = src_width * bpp;
 
632
        if(_tar_bpl <= 0)
 
633
            _tar_bpl = tar_width * bpp;
629
634
 
630
635
        /* Copy/rotate clockwise 90 degrees */
631
636
        for(sy = 0, tx = tar_width - 1;
633
638
            sy++, tx--
634
639
        )
635
640
        {
636
 
            src_line = src_data + (sy * src_bpl);
 
641
            src_line = src_data + (sy * _src_bpl);
637
642
            for(sx = 0, ty = 0;
638
643
                sx < src_width;
639
644
                sx++, ty++
640
645
            )
641
646
                memcpy(
642
 
                    tar_data + (ty * tar_bpl) + (tx * bpp),
 
647
                    tar_data + (ty * _tar_bpl) + (tx * bpp),
643
648
                    src_line + (sx * bpp),
644
649
                    bpp
645
650
                );
651
656
 *      counter-clockwise 90 degrees.
652
657
 */
653
658
void GUIImageBufferRotateCCW90(
654
 
        gint bpp,
 
659
        const gint bpp,
655
660
        const guint8 *src_data,
656
 
        gint src_width, gint src_height, gint src_bpl,
 
661
        const gint src_width, const gint src_height, const gint src_bpl,
657
662
        guint8 *tar_data,
658
 
        gint tar_width, gint tar_height, gint tar_bpl
 
663
        const gint tar_width, const gint tar_height, const gint tar_bpl
659
664
)
660
665
{
661
 
        gint sx, sy, tx, ty;
 
666
        gint    sx, sy, tx, ty,
 
667
                _src_bpl = src_bpl,
 
668
                _tar_bpl = tar_bpl;
662
669
        const guint8 *src_line;
663
670
 
664
671
        if((src_width <= 0) || (src_height <= 0) ||
673
680
            return;
674
681
 
675
682
        /* Calculate bytes per line values as needed */
676
 
        if(src_bpl <= 0)
677
 
            src_bpl = src_width * bpp;
678
 
        if(tar_bpl <= 0)
679
 
            tar_bpl = tar_width * bpp;
 
683
        if(_src_bpl <= 0)
 
684
            _src_bpl = src_width * bpp;
 
685
        if(_tar_bpl <= 0)
 
686
            _tar_bpl = tar_width * bpp;
680
687
 
681
688
        /* Copy/rotate counter-clockwise 90 degrees */
682
689
        for(sy = 0, tx = 0;
684
691
            sy++, tx++
685
692
        )
686
693
        {
687
 
            src_line = src_data + (sy * src_bpl);
 
694
            src_line = src_data + (sy * _src_bpl);
688
695
            for(sx = 0, ty = tar_height - 1;
689
696
                sx < src_width;
690
697
                sx++, ty--
691
698
            )
692
699
                memcpy(
693
 
                    tar_data + (ty * tar_bpl) + (tx * bpp),
 
700
                    tar_data + (ty * _tar_bpl) + (tx * bpp),
694
701
                    src_line + (sx * bpp),
695
702
                    bpp
696
703
                );
702
709
 *      clockwise 180 degrees.
703
710
 */
704
711
void GUIImageBufferRotateCW180(
705
 
        gint bpp,
 
712
        const gint bpp,
706
713
        const guint8 *src_data,
707
 
        gint src_width, gint src_height, gint src_bpl,
 
714
        const gint src_width, const gint src_height, const gint src_bpl,
708
715
        guint8 *tar_data,
709
 
        gint tar_width, gint tar_height, gint tar_bpl
 
716
        const gint tar_width, const gint tar_height, const gint tar_bpl
710
717
711
718
{
712
 
        gint sx, sy, tx, ty;
 
719
        gint    sx, sy, tx, ty,
 
720
                _src_bpl = src_bpl,
 
721
                _tar_bpl = tar_bpl;
713
722
        const guint8 *src_line;
714
723
 
715
724
        if((src_width <= 0) || (src_height <= 0) ||
724
733
            return;
725
734
 
726
735
        /* Calculate bytes per line values as needed */
727
 
        if(src_bpl <= 0)
728
 
            src_bpl = src_width * bpp;
729
 
        if(tar_bpl <= 0)
730
 
            tar_bpl = tar_width * bpp;
 
736
        if(_src_bpl <= 0)
 
737
            _src_bpl = src_width * bpp;
 
738
        if(_tar_bpl <= 0)
 
739
            _tar_bpl = tar_width * bpp;
731
740
 
732
741
        /* Copy/rotate clockwise 90 degrees */
733
742
        for(sy = 0, ty = tar_height - 1;
735
744
            sy++, ty--
736
745
        )
737
746
        {
738
 
            src_line = src_data + (sy * src_bpl);
 
747
            src_line = src_data + (sy * _src_bpl);
739
748
            for(sx = 0, tx = tar_width - 1;
740
749
                sx < src_width;
741
750
                sx++, tx--
742
751
            )
743
752
                memcpy(
744
 
                    tar_data + (ty * tar_bpl) + (tx * bpp),
 
753
                    tar_data + (ty * _tar_bpl) + (tx * bpp),
745
754
                    src_line + (sx * bpp),
746
755
                    bpp
747
756
                );
753
762
 *      horizontally.
754
763
 */
755
764
void GUIImageBufferMirrorH(
756
 
        gint bpp,
 
765
        const gint bpp,
757
766
        const guint8 *src_data,
758
 
        gint src_width, gint src_height, gint src_bpl,
 
767
        const gint src_width, const gint src_height, const gint src_bpl,
759
768
        guint8 *tar_data,
760
 
        gint tar_width, gint tar_height, gint tar_bpl
 
769
        const gint tar_width, const gint tar_height, const gint tar_bpl
761
770
)
762
771
{
763
 
        gint sx, sy, tx, ty;
 
772
        gint    sx, sy, tx, ty,
 
773
                _src_bpl = src_bpl,
 
774
                _tar_bpl = tar_bpl;
764
775
        const guint8 *src_line;
765
776
 
766
777
        if((src_width <= 0) || (src_height <= 0) ||
775
786
            return;
776
787
 
777
788
        /* Calculate bytes per line values as needed */
778
 
        if(src_bpl <= 0)
779
 
            src_bpl = src_width * bpp;
780
 
        if(tar_bpl <= 0)
781
 
            tar_bpl = tar_width * bpp;
 
789
        if(_src_bpl <= 0)
 
790
            _src_bpl = src_width * bpp;
 
791
        if(_tar_bpl <= 0)
 
792
            _tar_bpl = tar_width * bpp;
782
793
 
783
794
        /* Copy/mirror horizontally */
784
795
        for(sy = 0, ty = 0;
786
797
            sy++, ty++
787
798
        )
788
799
        {
789
 
            src_line = src_data + (sy * src_bpl);
 
800
            src_line = src_data + (sy * _src_bpl);
790
801
            for(sx = 0, tx = tar_width - 1;
791
802
                sx < src_width;
792
803
                sx++, tx--
793
804
            )
794
805
                memcpy(
795
 
                    tar_data + (ty * tar_bpl) + (tx * bpp),
 
806
                    tar_data + (ty * _tar_bpl) + (tx * bpp),
796
807
                    src_line + (sx * bpp),
797
808
                    bpp
798
809
                );
804
815
 *      vertically.
805
816
 */
806
817
void GUIImageBufferMirrorV(
807
 
        gint bpp,
 
818
        const gint bpp,
808
819
        const guint8 *src_data,
809
 
        gint src_width, gint src_height, gint src_bpl,
 
820
        const gint src_width, const gint src_height, const gint src_bpl,
810
821
        guint8 *tar_data,
811
 
        gint tar_width, gint tar_height, gint tar_bpl
 
822
        const gint tar_width, const gint tar_height, const gint tar_bpl
812
823
)
813
824
{
814
 
        gint sx, sy, tx, ty;
 
825
        gint    sx, sy, tx, ty,
 
826
                _src_bpl = src_bpl,
 
827
                _tar_bpl = tar_bpl;
815
828
        const guint8 *src_line;
816
829
 
817
830
        if((src_width <= 0) || (src_height <= 0) ||
826
839
            return;
827
840
 
828
841
        /* Calculate bytes per line values as needed */
829
 
        if(src_bpl <= 0)
830
 
            src_bpl = src_width * bpp;
831
 
        if(tar_bpl <= 0)
832
 
            tar_bpl = tar_width * bpp;
 
842
        if(_src_bpl <= 0)
 
843
            _src_bpl = src_width * bpp;
 
844
        if(_tar_bpl <= 0)
 
845
            _tar_bpl = tar_width * bpp;
833
846
 
834
847
        /* Copy/mirror horizontally */
835
848
        for(sy = 0, ty = tar_height - 1;
837
850
            sy++, ty--
838
851
        )
839
852
        {
840
 
            src_line = src_data + (sy * src_bpl);
 
853
            src_line = src_data + (sy * _src_bpl);
841
854
            for(sx = 0, tx = 0;
842
855
                sx < src_width;
843
856
                sx++, tx++
844
857
            )
845
858
                memcpy(
846
 
                    tar_data + (ty * tar_bpl) + (tx * bpp),
 
859
                    tar_data + (ty * _tar_bpl) + (tx * bpp),
847
860
                    src_line + (sx * bpp),
848
861
                    bpp
849
862
                );
992
1005
        gint *width_rtn, gint *height_rtn, gint *bpl_rtn  
993
1006
)
994
1007
{
995
 
#if defined(__GDK_X_H__)
 
1008
#if defined(HAVE_X)
996
1009
        gint width, height, src_bpp, src_bpl, tar_bpp, tar_bpl;
997
1010
        const guint8 *src_data;
998
1011
        guint8 *tar_data;
999
1012
        Display *xdpy;
 
1013
        Window xwin;
1000
1014
        XImage *ximg;
1001
1015
        GdkRectangle lrect;
1002
 
        GdkWindowPrivate *private = (GdkWindowPrivate *)drawable;
1003
 
        Window xwin = (private != NULL) ? private->xwindow : None;
 
1016
        GdkVisualType visual_type;
 
1017
        GdkVisual *visual;
 
1018
        GdkColormap *cmap;
 
1019
        GdkWindowPrivate *private;
1004
1020
 
1005
1021
        if(width_rtn != NULL)
1006
1022
            *width_rtn = 0;
1009
1025
        if(bpl_rtn != NULL)
1010
1026
            *bpl_rtn = 0;
1011
1027
 
1012
 
        if(xwin == None)
 
1028
        if(drawable == NULL)
1013
1029
            return(NULL);
1014
1030
 
 
1031
        private = (GdkWindowPrivate *)drawable;
1015
1032
        xdpy = private->xdisplay;
1016
 
        if(xdpy == NULL)
 
1033
        xwin = private->xwindow;
 
1034
        if((xdpy == NULL) || (xwin == None))
1017
1035
            return(NULL);
1018
1036
 
1019
 
        /* If no rectangle is specified then set rectangle to cover the
1020
 
         * entire drawable
 
1037
        cmap = private->colormap;
 
1038
        visual = (cmap != NULL) ? gdk_colormap_get_visual(cmap) : NULL;
 
1039
        if(visual != NULL)
 
1040
            visual_type = visual->type;
 
1041
        else
 
1042
            visual_type = gdk_visual_get_best_type();
 
1043
 
 
1044
        /* If no rectangle was specified then set the rectangle to
 
1045
         * cover the entire drawable
1021
1046
         */
1022
1047
        if(rect == NULL)
1023
1048
        {
1024
1049
            rect = &lrect;
1025
 
            lrect.x = private->x;
1026
 
            lrect.y = private->y;
 
1050
            lrect.x = 0;
 
1051
            lrect.y = 0;
1027
1052
            lrect.width = private->width;
1028
1053
            lrect.height = private->height;
1029
1054
        }
1039
1064
            AllPlanes,
1040
1065
            ZPixmap
1041
1066
        );
1042
 
        if((ximg != NULL) ? (ximg->data == NULL) : TRUE)
 
1067
        if(ximg == NULL)
 
1068
            return(NULL);
 
1069
 
 
1070
        if(ximg->data == NULL)
1043
1071
        {
1044
 
            if(ximg != NULL)
1045
 
                XDestroyImage(ximg);
 
1072
            XDestroyImage(ximg);
1046
1073
            return(NULL);
1047
1074
        }
1048
1075
 
1049
 
        /* Get values from XImage */
 
1076
        /* Get the values from the XImage */
1050
1077
        width = ximg->width;
1051
1078
        height = ximg->height;
1052
1079
        src_bpl = ximg->bytes_per_line;
1067
1094
         */
1068
1095
        if(ximg->depth == 8)
1069
1096
        {
1070
 
            gint xoffset_bytes, x, y;
1071
1097
            const gint  r_div = 7,
1072
1098
                        g_div = 7,
1073
1099
                        b_div = 3;
1074
 
            guint src_v;
 
1100
            gint xoffset_bytes, x, y;
 
1101
            guint32 src_v;
1075
1102
            const guint8 *src_ptr;
1076
1103
            guint8 *tar_ptr;
 
1104
            GdkColor *c;
1077
1105
 
1078
1106
            src_bpp = 1;
1079
1107
            xoffset_bytes = ximg->xoffset * src_bpp;
1080
1108
 
1081
 
            for(y = 0; y < height; y++)
 
1109
            switch(visual_type)
1082
1110
            {
1083
 
                src_ptr = (const guint8 *)(
1084
 
                    src_data + (y * src_bpl) + xoffset_bytes
1085
 
                );
1086
 
                tar_ptr = tar_data + (y * tar_bpl);
1087
 
 
1088
 
                for(x = 0; x < width; x++)
1089
 
                {
1090
 
                    /* 8 Bits Format: rrrgggbb */
1091
 
                    src_v = (guint)*src_ptr++;
1092
 
                    *tar_ptr++ = (guint8)(
 
1111
              case GDK_VISUAL_STATIC_GRAY:
 
1112
              case GDK_VISUAL_GRAYSCALE:
 
1113
                for(y = 0; y < height; y++)
 
1114
                {
 
1115
                    src_ptr = (const guint8 *)(
 
1116
                        src_data + (y * src_bpl) + xoffset_bytes
 
1117
                    );
 
1118
                    tar_ptr = tar_data + (y * tar_bpl);
 
1119
 
 
1120
                    for(x = 0; x < width; x++)
 
1121
                    {
 
1122
                        *tar_ptr++ = *src_ptr;
 
1123
                        *tar_ptr++ = *src_ptr;
 
1124
                        *tar_ptr++ = *src_ptr++;
 
1125
                    }
 
1126
                }
 
1127
                break;
 
1128
 
 
1129
              case GDK_VISUAL_STATIC_COLOR:
 
1130
              case GDK_VISUAL_PSEUDO_COLOR:
 
1131
                if(cmap == NULL)
 
1132
                {
 
1133
                    g_free(tar_data);
 
1134
                    XDestroyImage(ximg);
 
1135
                    return(NULL);
 
1136
                }
 
1137
                if((cmap->colors == NULL) || (cmap->size <= 0))
 
1138
                {
 
1139
                    g_free(tar_data);
 
1140
                    XDestroyImage(ximg);
 
1141
                    return(NULL);
 
1142
                }
 
1143
                for(y = 0; y < height; y++)
 
1144
                {
 
1145
                    src_ptr = (const guint8 *)(
 
1146
                        src_data + (y * src_bpl) + xoffset_bytes
 
1147
                    );
 
1148
                    tar_ptr = tar_data + (y * tar_bpl);
 
1149
 
 
1150
                    for(x = 0; x < width; x++)
 
1151
                    {
 
1152
                        c = &cmap->colors[*src_ptr];
 
1153
                        src_ptr++;
 
1154
                        *tar_ptr++ = (guint8)(c->red >> 8);
 
1155
                        *tar_ptr++ = (guint8)(c->green >> 8);
 
1156
                        *tar_ptr++ = (guint8)(c->blue >> 8);
 
1157
                    }
 
1158
                }
 
1159
                break;
 
1160
 
 
1161
              default:          /* GDK_VISUAL_TRUE_COLOR */
 
1162
                for(y = 0; y < height; y++)
 
1163
                {
 
1164
                    src_ptr = (const guint8 *)(
 
1165
                        src_data + (y * src_bpl) + xoffset_bytes
 
1166
                    );
 
1167
                    tar_ptr = tar_data + (y * tar_bpl);
 
1168
 
 
1169
                    for(x = 0; x < width; x++)
 
1170
                    {
 
1171
                        /* 8 Bits Format: rrrgggbb */
 
1172
                        src_v = (guint32)*src_ptr++;
 
1173
                        *tar_ptr++ = (guint8)(
1093
1174
                ((src_v & 0xE0) >> 5) * 0xff / r_div  
1094
 
                    );
1095
 
                    *tar_ptr++ = (guint8)(
 
1175
                        );
 
1176
                        *tar_ptr++ = (guint8)(
1096
1177
                ((src_v & 0x1C) >> 2) * 0xff / g_div
1097
 
                    );
1098
 
                    *tar_ptr++ = (guint8)(
 
1178
                        );
 
1179
                        *tar_ptr++ = (guint8)(
1099
1180
                ((src_v & 0x03) >> 0) * 0xff / b_div
1100
 
                    );
 
1181
                        );
 
1182
                    }
1101
1183
                }
 
1184
                break;
1102
1185
            }
1103
1186
        }
1104
1187
        else if(ximg->depth == 15)
1107
1190
            const gint  r_div = 31,
1108
1191
                        g_div = 31,
1109
1192
                        b_div = 31;
 
1193
            guint16 v16;
1110
1194
            const guint16 *src_ptr;
1111
1195
            guint8 *tar_ptr;
1112
1196
 
1122
1206
 
1123
1207
                for(x = 0; x < width; x++)
1124
1208
                {
1125
 
                    /* 16 Bits Format: arrrrrgg gggbbbbb */
1126
 
                    *tar_ptr++ = (guint8)(
1127
 
                ((((guint)*src_ptr) & 0x7C00) >> 10) * 0xff / r_div
1128
 
                    );
1129
 
                    *tar_ptr++ = (guint8)(
1130
 
                ((((guint)*src_ptr) & 0x03E0) >> 5) * 0xff / g_div
1131
 
                    );
1132
 
                    *tar_ptr++ = (guint8)(
1133
 
                ((((guint)*src_ptr) & 0x001F) >> 0) * 0xff / b_div
1134
 
                    );
 
1209
                    /* 15 Bits Format: arrrrrgg gggbbbbb */
 
1210
                    v16 = *src_ptr++;
1135
1211
 
1136
 
                    src_ptr++;
 
1212
                    *tar_ptr++ = (guint8)(
 
1213
                (guint32)((v16 & 0x7C00) >> 10) * 0xFF / r_div
 
1214
                    );
 
1215
                    *tar_ptr++ = (guint8)(
 
1216
                (guint32)((v16 & 0x03E0) >> 5) * 0xFF / g_div
 
1217
                    );
 
1218
                    *tar_ptr++ = (guint8)(
 
1219
                (guint32)((v16 & 0x001F) >> 0) * 0xFF / b_div
 
1220
                    );
1137
1221
                }
1138
1222
            }
1139
1223
        }
1143
1227
            const gint  r_div = 31,
1144
1228
                        g_div = 63,
1145
1229
                        b_div = 31;
 
1230
            guint16 v16;
1146
1231
            const guint16 *src_ptr;
1147
1232
            guint8 *tar_ptr;
1148
1233
 
1159
1244
                for(x = 0; x < width; x++)
1160
1245
                {
1161
1246
                    /* 16 Bits Format: rrrrrggg gggbbbbb */
1162
 
                    *tar_ptr++ = (guint8)(
1163
 
                ((((guint)*src_ptr) & 0xF800) >> 11) * 0xff / r_div
1164
 
                    );
1165
 
                    *tar_ptr++ = (guint8)(
1166
 
                ((((guint)*src_ptr) & 0x07E0) >> 5) * 0xff / g_div
1167
 
                    );
1168
 
                    *tar_ptr++ = (guint8)(
1169
 
                ((((guint)*src_ptr) & 0x001F) >> 0) * 0xff / b_div
1170
 
                    );
 
1247
                    v16 = *src_ptr++;
1171
1248
 
1172
 
                    src_ptr++;
 
1249
                    *tar_ptr++ = (guint8)(
 
1250
                (guint32)((v16 & 0xF800) >> 11) * 0xFF / r_div
 
1251
                    );
 
1252
                    *tar_ptr++ = (guint8)(
 
1253
                (guint32)((v16 & 0x07E0) >> 5) * 0xFF / g_div
 
1254
                    );
 
1255
                    *tar_ptr++ = (guint8)(
 
1256
                (guint32)((v16 & 0x001F) >> 0) * 0xFF / b_div
 
1257
                    );
1173
1258
                }
1174
1259
            }
1175
1260
        }
1261
1346
        gint *width_rtn, gint *height_rtn, gint *bpl_rtn  
1262
1347
)
1263
1348
{
1264
 
#if defined(__GDK_X_H__)
 
1349
#if defined(HAVE_X)
1265
1350
        gint width, height, src_bpp, src_bpl, tar_bpp, tar_bpl;
1266
1351
        const guint8 *src_data;
1267
1352
        guint8 *tar_data;
1268
1353
        Display *xdpy;
 
1354
        Window xwin;
1269
1355
        XImage *ximg;
1270
1356
        GdkRectangle lrect;
1271
 
        GdkWindowPrivate *private = (GdkWindowPrivate *)drawable;
1272
 
        Window xwin = (private != NULL) ? private->xwindow : None;
 
1357
        GdkVisualType visual_type;
 
1358
        GdkVisual *visual;
 
1359
        GdkColormap *cmap;
 
1360
        GdkWindowPrivate *private;
1273
1361
 
1274
1362
        if(width_rtn != NULL)
1275
1363
            *width_rtn = 0;
1278
1366
        if(bpl_rtn != NULL)
1279
1367
            *bpl_rtn = 0;
1280
1368
 
1281
 
        if(xwin == None)
 
1369
        if(drawable == NULL)
1282
1370
            return(NULL);
1283
1371
 
 
1372
        private = (GdkWindowPrivate *)drawable;
1284
1373
        xdpy = private->xdisplay;
1285
 
        if(xdpy == NULL)
 
1374
        xwin = private->xwindow;
 
1375
        if((xdpy == NULL) || (xwin == None))
1286
1376
            return(NULL);
1287
1377
 
1288
 
        /* If no rectangle is specified then set rectangle to cover the
1289
 
         * entire drawable
 
1378
        cmap = private->colormap;
 
1379
        visual = (cmap != NULL) ? gdk_colormap_get_visual(cmap) : NULL;
 
1380
        if(visual != NULL)
 
1381
            visual_type = visual->type;
 
1382
        else
 
1383
            visual_type = gdk_visual_get_best_type();
 
1384
 
 
1385
        /* If no rectangle was specified then set the rectangle to
 
1386
         * cover the entire drawable
1290
1387
         */
1291
1388
        if(rect == NULL)
1292
1389
        {
1293
1390
            rect = &lrect;
1294
 
            lrect.x = private->x;
1295
 
            lrect.y = private->y;
 
1391
            lrect.x = 0;
 
1392
            lrect.y = 0;
1296
1393
            lrect.width = private->width;
1297
1394
            lrect.height = private->height;
1298
1395
        }
1308
1405
            AllPlanes,
1309
1406
            ZPixmap
1310
1407
        );
1311
 
        if((ximg != NULL) ? (ximg->data == NULL) : TRUE)
 
1408
        if(ximg == NULL)
 
1409
            return(NULL);
 
1410
 
 
1411
        if(ximg->data == NULL)
1312
1412
        {
1313
 
            if(ximg != NULL)
1314
 
                XDestroyImage(ximg);
 
1413
            XDestroyImage(ximg);
1315
1414
            return(NULL);
1316
1415
        }
1317
1416
 
1322
1421
        src_data = (const guint8 *)ximg->data;
1323
1422
 
1324
1423
        /* Allocate the target RGBA image data */
1325
 
        tar_bpp = 4;
 
1424
        tar_bpp = 4 * sizeof(guint8);
1326
1425
        tar_bpl = width * tar_bpp;
1327
1426
        tar_data = (guint8 *)g_malloc(tar_bpl * height);
1328
1427
        if(tar_data == NULL)
1332
1431
        }
1333
1432
 
1334
1433
        /* Begin copying the XImage data to the return data */
1335
 
        if(ximg->depth == 8)
 
1434
        if(ximg->depth == 1)
1336
1435
        {
1337
 
            gint xoffset_bytes, x, y;
1338
 
            const gint  r_div = 7,
1339
 
                        g_div = 7,
1340
 
                        b_div = 3;
1341
 
            guint src_v;
 
1436
            gint x, y, xoffset_bytes;
1342
1437
            const guint8 *src_ptr;
1343
1438
            guint8 *tar_ptr;
1344
1439
 
1345
 
            src_bpp = 1;
1346
 
            xoffset_bytes = ximg->xoffset * src_bpp;
 
1440
            src_bpp = 1;
 
1441
            xoffset_bytes = ximg->xoffset * src_bpp;
1347
1442
 
1348
1443
            for(y = 0; y < height; y++)
1349
1444
            {
1354
1449
 
1355
1450
                for(x = 0; x < width; x++)
1356
1451
                {
1357
 
                    /* 8 Bits Format: rrrgggbb */
1358
 
                    src_v = (guint)*src_ptr++;
1359
 
                    *tar_ptr++ = (guint8)(
1360
 
                ((src_v & 0xE0) >> 5) * 0xff / r_div
1361
 
                    );
1362
 
                    *tar_ptr++ = (guint8)(
 
1452
                    if(src_ptr[x / 8] & (1 << (x % 8)))
 
1453
                    {
 
1454
                        *tar_ptr++ = 0xff;
 
1455
                        *tar_ptr++ = 0xff;
 
1456
                        *tar_ptr++ = 0xff;
 
1457
                        *tar_ptr++ = 0xff;
 
1458
                    }
 
1459
                    else
 
1460
                    {
 
1461
                        *tar_ptr++ = 0x00;
 
1462
                        *tar_ptr++ = 0x00;
 
1463
                        *tar_ptr++ = 0x00;
 
1464
                        *tar_ptr++ = 0x00;
 
1465
                    }
 
1466
                }
 
1467
            }
 
1468
        }
 
1469
        else if(ximg->depth == 8)
 
1470
        {
 
1471
            const gint  r_div = 7,
 
1472
                        g_div = 7,
 
1473
                        b_div = 3;
 
1474
            gint xoffset_bytes, x, y;
 
1475
            guint32 src_v;
 
1476
            const guint8 *src_ptr;
 
1477
            guint8 *tar_ptr;
 
1478
            GdkColor *c;
 
1479
 
 
1480
            src_bpp = 1;
 
1481
            xoffset_bytes = ximg->xoffset * src_bpp;
 
1482
 
 
1483
            switch(visual_type)
 
1484
            {
 
1485
              case GDK_VISUAL_STATIC_GRAY:
 
1486
              case GDK_VISUAL_GRAYSCALE:
 
1487
                for(y = 0; y < height; y++)
 
1488
                {
 
1489
                    src_ptr = (const guint8 *)(
 
1490
                        src_data + (y * src_bpl) + xoffset_bytes
 
1491
                    );
 
1492
                    tar_ptr = tar_data + (y * tar_bpl);
 
1493
 
 
1494
                    for(x = 0; x < width; x++)
 
1495
                    {
 
1496
                        *tar_ptr++ = *src_ptr;
 
1497
                        *tar_ptr++ = *src_ptr;
 
1498
                        *tar_ptr++ = *src_ptr++;
 
1499
                        *tar_ptr++ = 0xff;
 
1500
                    }
 
1501
                }
 
1502
                break;
 
1503
 
 
1504
              case GDK_VISUAL_STATIC_COLOR:
 
1505
              case GDK_VISUAL_PSEUDO_COLOR:
 
1506
                if(cmap == NULL)
 
1507
                {
 
1508
                    g_free(tar_data);
 
1509
                    XDestroyImage(ximg);
 
1510
                    return(NULL);
 
1511
                }
 
1512
                if((cmap->colors == NULL) || (cmap->size <= 0))
 
1513
                {
 
1514
                    g_free(tar_data);
 
1515
                    XDestroyImage(ximg);
 
1516
                    return(NULL);
 
1517
                }
 
1518
                for(y = 0; y < height; y++)
 
1519
                {
 
1520
                    src_ptr = (const guint8 *)(
 
1521
                        src_data + (y * src_bpl) + xoffset_bytes
 
1522
                    );
 
1523
                    tar_ptr = tar_data + (y * tar_bpl);
 
1524
 
 
1525
                    for(x = 0; x < width; x++)
 
1526
                    {
 
1527
                        c = &cmap->colors[*src_ptr];
 
1528
                        src_ptr++;
 
1529
                        *tar_ptr++ = (guint8)(c->red >> 8);
 
1530
                        *tar_ptr++ = (guint8)(c->green >> 8);
 
1531
                        *tar_ptr++ = (guint8)(c->blue >> 8);
 
1532
                        *tar_ptr++ = 0xff;
 
1533
                    }
 
1534
                }
 
1535
                break;
 
1536
 
 
1537
              default:          /* GDK_VISUAL_TRUE_COLOR */
 
1538
                for(y = 0; y < height; y++)
 
1539
                {
 
1540
                    src_ptr = (const guint8 *)(
 
1541
                        src_data + (y * src_bpl) + xoffset_bytes
 
1542
                    );
 
1543
                    tar_ptr = tar_data + (y * tar_bpl);
 
1544
 
 
1545
                    for(x = 0; x < width; x++)
 
1546
                    {
 
1547
                        /* 8 Bits Format: rrrgggbb */
 
1548
                        src_v = (guint32)*src_ptr++;
 
1549
                        *tar_ptr++ = (guint8)(
 
1550
                ((src_v & 0xE0) >> 5) * 0xff / r_div  
 
1551
                        );
 
1552
                        *tar_ptr++ = (guint8)(
1363
1553
                ((src_v & 0x1C) >> 2) * 0xff / g_div
1364
 
                    );
1365
 
                    *tar_ptr++ = (guint8)(
 
1554
                        );
 
1555
                        *tar_ptr++ = (guint8)(
1366
1556
                ((src_v & 0x03) >> 0) * 0xff / b_div
1367
 
                    );
1368
 
                    *tar_ptr++ = 0xff;
 
1557
                        );
 
1558
                        *tar_ptr++ = 0xff;
 
1559
                    }
1369
1560
                }
 
1561
                break;
1370
1562
            }
1371
1563
        }
1372
1564
        else if(ximg->depth == 15)
1375
1567
            const gint  r_div = 31,
1376
1568
                        g_div = 31,
1377
1569
                        b_div = 31;
 
1570
            guint16 v16;
1378
1571
            const guint16 *src_ptr;
1379
1572
            guint8 *tar_ptr;
1380
1573
 
1390
1583
 
1391
1584
                for(x = 0; x < width; x++)
1392
1585
                {
1393
 
                    /* 16 Bits Format: arrrrrgg gggbbbbb */
1394
 
                    *tar_ptr++ = (guint8)(
1395
 
                ((((guint)*src_ptr) & 0x7C00) >> 10) * 0xff / r_div
1396
 
                    );
1397
 
                    *tar_ptr++ = (guint8)(
1398
 
                ((((guint)*src_ptr) & 0x03E0) >> 5) * 0xff / g_div
1399
 
                    );
1400
 
                    *tar_ptr++ = (guint8)(
1401
 
                ((((guint)*src_ptr) & 0x001F) >> 0) * 0xff / b_div
 
1586
                    /* 15 Bits Format: arrrrrgg gggbbbbb */
 
1587
                    v16 = *src_ptr++;
 
1588
 
 
1589
                    *tar_ptr++ = (guint8)(
 
1590
                (guint32)((v16 & 0x7C00) >> 10) * 0xFF / r_div
 
1591
                    );
 
1592
                    *tar_ptr++ = (guint8)(
 
1593
                (guint32)((v16 & 0x03E0) >> 5) * 0xFF / g_div
 
1594
                    );
 
1595
                    *tar_ptr++ = (guint8)(
 
1596
                (guint32)((v16 & 0x001F) >> 0) * 0xFF / b_div
1402
1597
                    );
1403
1598
/* Alpha channel may not be defined
1404
 
                    *tar_ptr++ = (((guint)*src_ptr) & (1 << 15)) ?
1405
 
                        0xff : 0x00;
 
1599
                    *tar_ptr++ = (v16 & (1 << 15)) ? 0xff : 0x00;
1406
1600
 */
1407
1601
                    *tar_ptr++ = 0xff;
1408
 
 
1409
 
                    src_ptr++;
1410
1602
                }
1411
1603
            }
1412
1604
        }
1416
1608
            const gint  r_div = 31,
1417
1609
                        g_div = 63,
1418
1610
                        b_div = 31;
 
1611
            guint16 v16;
1419
1612
            const guint16 *src_ptr;
1420
1613
            guint8 *tar_ptr;
1421
1614
 
1432
1625
                for(x = 0; x < width; x++)
1433
1626
                {
1434
1627
                    /* 16 Bits Format: rrrrrggg gggbbbbb */
1435
 
                    *tar_ptr++ = (guint8)(
1436
 
                ((((guint)*src_ptr) & 0xF800) >> 11) * 0xff / r_div
1437
 
                    );
1438
 
                    *tar_ptr++ = (guint8)(
1439
 
                ((((guint)*src_ptr) & 0x07E0) >> 5) * 0xff / g_div
1440
 
                    );
1441
 
                    *tar_ptr++ = (guint8)(
1442
 
                ((((guint)*src_ptr) & 0x001F) >> 0) * 0xff / b_div
 
1628
                    v16 = *src_ptr++;
 
1629
 
 
1630
                    *tar_ptr++ = (guint8)(
 
1631
                (guint32)((v16 & 0xF800) >> 11) * 0xff / r_div
 
1632
                    );
 
1633
                    *tar_ptr++ = (guint8)(
 
1634
                (guint32)((v16 & 0x07E0) >> 5) * 0xff / g_div
 
1635
                    );
 
1636
                    *tar_ptr++ = (guint8)(
 
1637
                (guint32)((v16 & 0x001F) >> 0) * 0xff / b_div
1443
1638
                    );
1444
1639
                    *tar_ptr++ = 0xff;
1445
 
 
1446
 
                    src_ptr++;
1447
1640
                }
1448
1641
            }
1449
1642
        }