summaryrefslogtreecommitdiff
path: root/packages/gtk+/gtk+-2.10.7/gnome-bug-341177.patch
blob: c31868462a6cd8296dace75a8e2a93dee11b4733 (plain)
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
diff -uprN gtk+-2.8.13.org/gdk-pixbuf/pixops/pixops.c gtk+-2.8.13.INNER_LOOP/gdk-pixbuf/pixops/pixops.c
--- gtk+-2.8.13.org/gdk-pixbuf/pixops/pixops.c	Tue Jul 12 18:58:57 2005
+++ gtk+-2.8.13.INNER_LOOP/gdk-pixbuf/pixops/pixops.c	Tue May  9 17:30:53 2006
@@ -71,35 +71,24 @@ get_check_shift (int check_size)
   return check_shift;
 }
 
-static void
-pixops_scale_nearest (guchar        *dest_buf,
-		      int            render_x0,
-		      int            render_y0,
-		      int            render_x1,
-		      int            render_y1,
-		      int            dest_rowstride,
-		      int            dest_channels,
-		      gboolean       dest_has_alpha,
-		      const guchar  *src_buf,
-		      int            src_width,
-		      int            src_height,
-		      int            src_rowstride,
-		      int            src_channels,
-		      gboolean       src_has_alpha,
-		      double         scale_x,
-		      double         scale_y)
-{
-  int i;
-  int x;
-  int x_step = (1 << SCALE_SHIFT) / scale_x;
-  int y_step = (1 << SCALE_SHIFT) / scale_y;
-  int xmax, xstart, xstop, x_pos, y_pos;
-  const guchar *p;
+typedef struct { guchar a,b,c; } b3;
+extern void BUG_bad_size_of_struct_b3(void);
 
-#define INNER_LOOP(SRC_CHANNELS,DEST_CHANNELS,ASSIGN_PIXEL)     \
+#define INNER_LOOP_PREP()                                       \
+    do {                                                        \
+      x = render_x0 * x_step + x_step / 2;                      \
       xmax = x + (render_x1 - render_x0) * x_step;              \
       xstart = MIN (0, xmax);                                   \
       xstop = MIN (src_width << SCALE_SHIFT, xmax);             \
+    } while(0)
+
+#define INNER_LOOP_BODY(SRC_CHANNELS,DEST_CHANNELS,ASSIGN_PIXEL)\
+    do {                                                        \
+      y_pos = ((i + render_y0) * y_step + y_step / 2) >> SCALE_SHIFT; \
+      y_pos = CLAMP (y_pos, 0, src_height - 1);                 \
+      src  = src_buf + y_pos * src_rowstride;                   \
+      dest = dest_buf + i * dest_rowstride;                     \
+      x = render_x0 * x_step + x_step / 2;                      \
       p = src + (CLAMP (x, xstart, xstop) >> SCALE_SHIFT) * SRC_CHANNELS; \
       while (x < xstart)                                        \
         {                                                       \
@@ -121,42 +110,58 @@ pixops_scale_nearest (guchar        *des
           ASSIGN_PIXEL;                                         \
           dest += DEST_CHANNELS;                                \
           x += x_step;                                          \
-        }
+        }                                                       \
+    } while(0)
 
-  for (i = 0; i < (render_y1 - render_y0); i++)
-    {
-      const guchar *src;
-      guchar       *dest;
-      y_pos = ((i + render_y0) * y_step + y_step / 2) >> SCALE_SHIFT;
-      y_pos = CLAMP (y_pos, 0, src_height - 1);
-      src  = src_buf + y_pos * src_rowstride;
-      dest = dest_buf + i * dest_rowstride;
+static void
+pixops_scale_nearest (guchar        *dest_buf,
+		      int            render_x0,
+		      int            render_y0,
+		      int            render_x1,
+		      int            render_y1,
+		      int            dest_rowstride,
+		      int            dest_channels,
+		      gboolean       dest_has_alpha,
+		      const guchar  *src_buf,
+		      int            src_width,
+		      int            src_height,
+		      int            src_rowstride,
+		      int            src_channels,
+		      gboolean       src_has_alpha,
+		      double         scale_x,
+		      double         scale_y)
+{
+  int i;
+  int x;
+  int x_step = (1 << SCALE_SHIFT) / scale_x;
+  int y_step = (1 << SCALE_SHIFT) / scale_y;
+  int xmax, xstart, xstop, x_pos, y_pos;
+  const guchar *p;
 
-      x = render_x0 * x_step + x_step / 2;
+  const guchar *src;
+  guchar       *dest;
 
-      if (src_channels == 3)
-	{
-	  if (dest_channels == 3)
-	    {
-	      INNER_LOOP (3, 3, dest[0]=p[0];dest[1]=p[1];dest[2]=p[2]);
-	    }
-	  else
-	    {
-	      INNER_LOOP (3, 4, dest[0]=p[0];dest[1]=p[1];dest[2]=p[2];dest[3]=0xff);
-	    }
-	}
-      else if (src_channels == 4)
-	{
-	  if (dest_channels == 3)
-	    {
-	      INNER_LOOP (4, 3, dest[0]=p[0];dest[1]=p[1];dest[2]=p[2]);
-	    }
-	  else
-	    {
-	      guint32 *p32;
-	      INNER_LOOP(4, 4, p32=(guint32*)dest;*p32=*((guint32*)p));
-	    }
-	}
+  if(sizeof(b3) != 3) BUG_bad_size_of_struct_b3();
+
+  INNER_LOOP_PREP();
+
+  if (src_channels == 3)
+    {
+      if (dest_channels == 3)
+	for (i = 0; i < (render_y1 - render_y0); i++)
+	  INNER_LOOP_BODY (3, 3, *(b3*)dest = *(b3*)p);
+      else
+	for (i = 0; i < (render_y1 - render_y0); i++)
+	  INNER_LOOP_BODY (3, 4, (*(b3*)dest = *(b3*)p, dest[3]=0xff) );
+    }
+  else if (src_channels == 4)
+    {
+      if (dest_channels == 3)
+	for (i = 0; i < (render_y1 - render_y0); i++)
+	  INNER_LOOP_BODY (4, 3, *(b3*)dest = *(b3*)p);
+      else
+	for (i = 0; i < (render_y1 - render_y0); i++)
+	  INNER_LOOP_BODY (4, 4, *(guint32*)dest = *((guint32*)p));
     }
 }
 
@@ -187,18 +192,14 @@ pixops_composite_nearest (guchar        
   const guchar *p;
   unsigned int  a0;
 
+  INNER_LOOP_PREP();
+
   for (i = 0; i < (render_y1 - render_y0); i++)
     {
       const guchar *src;
       guchar       *dest;
-      y_pos = ((i + render_y0) * y_step + y_step / 2) >> SCALE_SHIFT;
-      y_pos = CLAMP (y_pos, 0, src_height - 1);
-      src  = src_buf + y_pos * src_rowstride;
-      dest = dest_buf + i * dest_rowstride;
-
-      x = render_x0 * x_step + x_step / 2;
       
-      INNER_LOOP(src_channels, dest_channels,
+      INNER_LOOP_BODY(src_channels, dest_channels,
 	  if (src_has_alpha)
 	    a0 = (p[3] * overall_alpha) / 0xff;
 	  else
@@ -209,9 +210,7 @@ pixops_composite_nearest (guchar        
             case 0:
               break;
             case 255:
-              dest[0] = p[0];
-              dest[1] = p[1];
-              dest[2] = p[2];
+              *(b3*)dest = *(b3*)p;
               if (dest_has_alpha)
                 dest[3] = 0xff;
               break;
@@ -279,17 +278,12 @@ pixops_composite_color_nearest (guchar  
   const guchar *p;
   unsigned int  a0;
 
+  INNER_LOOP_PREP();
+
   for (i = 0; i < (render_y1 - render_y0); i++)
     {
       const guchar *src;
       guchar       *dest;
-      y_pos = ((i + render_y0) * y_step + y_step / 2) >> SCALE_SHIFT;
-      y_pos = CLAMP (y_pos, 0, src_height - 1);
-      src  = src_buf + y_pos * src_rowstride;
-      dest = dest_buf + i * dest_rowstride;
-
-      x = render_x0 * x_step + x_step / 2;
-      
       
       if (((i + check_y) >> check_shift) & 1)
 	{
@@ -313,7 +307,7 @@ pixops_composite_color_nearest (guchar  
 	}
 
       j = 0;
-      INNER_LOOP(src_channels, dest_channels,
+      INNER_LOOP_BODY(src_channels, dest_channels,
 	  if (src_has_alpha)
 	    a0 = (p[3] * overall_alpha + 0xff) >> 8;
 	  else
@@ -372,7 +366,8 @@ pixops_composite_color_nearest (guchar  
 	);
     }
 }
-#undef INNER_LOOP
+#undef INNER_LOOP_BODY
+#undef INNER_LOOP_PREP
 
 static void
 composite_pixel (guchar *dest, int dest_x, int dest_channels, int dest_has_alpha,