Prevent promotion to unsigned when calculating strides.
authorJosé Fonseca <jrfonseca@tungstengraphics.com>
Mon, 17 Sep 2007 17:49:40 +0000 (18:49 +0100)
committerJosé Fonseca <jrfonseca@tungstengraphics.com>
Mon, 17 Sep 2007 17:49:40 +0000 (18:49 +0100)
pixman/pixman-image.c
pixman/pixman-mmx.c
pixman/pixman-private.h
pixman/pixman-utils.c

index c39ee9b..0bcd901 100644 (file)
@@ -49,7 +49,7 @@ init_gradient (gradient_t     *gradient,
        return FALSE;
 
     memcpy (gradient->stops, stops, n_stops * sizeof (pixman_gradient_stop_t));
-    
+
     gradient->n_stops = n_stops;
 
     gradient->stop_range = 0xffff;
@@ -73,7 +73,7 @@ static pixman_image_t *
 allocate_image (void)
 {
     pixman_image_t *image = malloc (sizeof (pixman_image_t));
-    
+
     if (image)
     {
        image_common_t *common = &image->common;
@@ -132,7 +132,7 @@ pixman_image_unref (pixman_image_t *image)
        if (image->type == BITS && image->bits.indexed)
            free (image->bits.indexed);
 #endif
-       
+
 #if 0
        memset (image, 0xaa, sizeof (pixman_image_t));
 #endif
@@ -142,10 +142,10 @@ pixman_image_unref (pixman_image_t *image)
                free (image->gradient.stops);
        }
 
-       
+
        if (image->type == BITS && image->bits.free_me)
            free (image->bits.free_me);
-       
+
        free (image);
 
        return TRUE;
@@ -161,9 +161,9 @@ pixman_image_create_solid_fill (pixman_color_t *color)
     pixman_image_t *img = allocate_image();
     if (!img)
        return NULL;
-    
+
     init_source_image (&img->solid.common);
-    
+
     img->type = SOLID;
     img->solid.color = color_to_uint32 (color);
 
@@ -180,14 +180,14 @@ pixman_image_create_linear_gradient (pixman_point_fixed_t         *p1,
     linear_gradient_t *linear;
 
     return_val_if_fail (n_stops >= 2, NULL);
-    
+
     image = allocate_image();
-    
+
     if (!image)
        return NULL;
 
     linear = &image->linear;
-    
+
     if (!init_gradient (&linear->common, stops, n_stops))
     {
        free (image);
@@ -215,7 +215,7 @@ pixman_image_create_radial_gradient (pixman_point_fixed_t         *inner,
     radial_gradient_t *radial;
 
     return_val_if_fail (n_stops >= 2, NULL);
-    
+
     image = allocate_image();
 
     if (!image)
@@ -230,7 +230,7 @@ pixman_image_create_radial_gradient (pixman_point_fixed_t         *inner,
     }
 
     image->type = RADIAL;
-    
+
     radial->c1.x = inner->x;
     radial->c1.y = inner->y;
     radial->c1.radius = inner_radius;
@@ -243,7 +243,7 @@ pixman_image_create_radial_gradient (pixman_point_fixed_t         *inner,
     radial->A = (radial->cdx * radial->cdx
                 + radial->cdy * radial->cdy
                 - radial->dr  * radial->dr);
-    
+
     return image;
 }
 
@@ -260,7 +260,7 @@ pixman_image_create_conical_gradient (pixman_point_fixed_t *center,
        return NULL;
 
     conical = &image->conical;
-    
+
     if (!init_gradient (&conical->common, stops, n_stops))
     {
        free (image);
@@ -283,9 +283,9 @@ create_bits (pixman_format_code_t format,
     int stride;
     int buf_size;
     int bpp;
-    
+
     bpp = PIXMAN_FORMAT_BPP (format);
-    stride = ((width * bpp + FB_MASK) >> FB_SHIFT) * sizeof (uint32_t);
+    stride = ((width * bpp + FB_MASK) >> FB_SHIFT) * (int) sizeof (uint32_t);
     buf_size = height * stride;
 
     if (rowstride_bytes)
@@ -298,11 +298,11 @@ static void
 reset_clip_region (pixman_image_t *image)
 {
     pixman_region_fini (&image->common.clip_region);
-    
+
     if (image->type == BITS)
     {
        pixman_region_init_rect (&image->common.clip_region, 0, 0,
-                                image->bits.width, image->bits.height);        
+                                image->bits.width, image->bits.height);
     }
     else
     {
@@ -320,10 +320,10 @@ pixman_image_create_bits (pixman_format_code_t  format,
     pixman_image_t *image;
     uint32_t *free_me = NULL;
 
-    /* must be a whole number of uint32_t's 
+    /* must be a whole number of uint32_t's
      */
     return_val_if_fail (bits == NULL ||
-                       (rowstride_bytes % sizeof (uint32_t)) == 0, NULL); 
+                       (rowstride_bytes % sizeof (uint32_t)) == 0, NULL);
 
     if (!bits)
     {
@@ -331,20 +331,20 @@ pixman_image_create_bits (pixman_format_code_t  format,
        if (!bits)
            return NULL;
     }
-    
+
     image = allocate_image();
 
     if (!image)
        return NULL;
-    
+
     image->type = BITS;
     image->bits.format = format;
     image->bits.width = width;
     image->bits.height = height;
     image->bits.bits = bits;
     image->bits.free_me = free_me;
-    
-    image->bits.rowstride = rowstride_bytes / sizeof (uint32_t); /* we store it in number
+
+    image->bits.rowstride = rowstride_bytes / (int) sizeof (uint32_t); /* we store it in number
                                                                  * of uint32_t's
                                                                  */
     image->bits.indexed = NULL;
@@ -370,7 +370,7 @@ pixman_image_set_clip_region (pixman_image_t    *image,
     else
     {
        reset_clip_region (image);
-       
+
        return TRUE;
     }
 }
@@ -395,7 +395,7 @@ pixman_image_set_transform (pixman_image_t           *image,
          { 0, 0, pixman_fixed_1 }
        }
     };
-    
+
     image_common_t *common = (image_common_t *)image;
 
     if (common->transform == transform)
@@ -407,7 +407,7 @@ pixman_image_set_transform (pixman_image_t           *image,
        common->transform = NULL;
        return TRUE;
     }
-    
+
     if (common->transform == NULL)
        common->transform = malloc (sizeof (pixman_transform_t));
     if (common->transform == NULL)
@@ -425,7 +425,7 @@ pixman_image_set_repeat (pixman_image_t  *image,
     image->common.repeat = repeat;
 }
 
-pixman_bool_t 
+pixman_bool_t
 pixman_image_set_filter (pixman_image_t       *image,
                         pixman_filter_t       filter,
                         const pixman_fixed_t *params,
@@ -449,7 +449,7 @@ pixman_image_set_filter (pixman_image_t       *image,
     }
 
     common->filter = filter;
-       
+
     if (common->filter_params)
        free (common->filter_params);
 
@@ -490,7 +490,7 @@ pixman_image_set_alpha_map (pixman_image_t *image,
                            int16_t         y)
 {
     image_common_t *common = (image_common_t *)image;
-    
+
     return_if_fail (!alpha_map || alpha_map->type == BITS);
 
     if (common->alpha_map != (bits_image_t *)alpha_map)
@@ -558,7 +558,7 @@ int
 pixman_image_get_stride (pixman_image_t *image)
 {
     if (image->type == BITS)
-       return image->bits.rowstride * sizeof (uint32_t);
+       return image->bits.rowstride * (int) sizeof (uint32_t);
 
     return 0;
 }
@@ -589,7 +589,7 @@ color_to_pixel (pixman_color_t *color,
     {
        return FALSE;
     }
-    
+
     if (PIXMAN_FORMAT_TYPE (format) == PIXMAN_TYPE_ABGR)
     {
        c = ((c & 0xff000000) >>  0) |
@@ -608,7 +608,7 @@ color_to_pixel (pixman_color_t *color,
     printf ("color: %x %x %x %x\n", color->alpha, color->red, color->green, color->blue);
     printf ("pixel: %x\n", c);
 #endif
-    
+
     *pixel = c;
     return TRUE;
 }
@@ -623,7 +623,7 @@ pixman_image_fill_rectangles (pixman_op_t               op,
     pixman_image_t *solid;
     pixman_color_t c;
     int i;
-    
+
     if (color->alpha == 0xffff)
     {
        if (op == PIXMAN_OP_OVER)
@@ -638,14 +638,14 @@ pixman_image_fill_rectangles (pixman_op_t             op,
        c.alpha = 0;
 
        color = &c;
-       
+
        op = PIXMAN_OP_SRC;
     }
 
     if (op == PIXMAN_OP_SRC)
     {
        uint32_t pixel;
-       
+
        if (color_to_pixel (color, &pixel, dest->bits.format))
        {
            for (i = 0; i < n_rects; ++i)
@@ -653,7 +653,7 @@ pixman_image_fill_rectangles (pixman_op_t               op,
                pixman_region16_t fill_region;
                int n_boxes, j;
                pixman_box16_t *boxes;
-               
+
                pixman_region_init_rect (&fill_region, rects[i].x, rects[i].y, rects[i].width, rects[i].height);
                pixman_region_intersect (&fill_region, &fill_region, &dest->common.clip_region);
 
@@ -671,7 +671,7 @@ pixman_image_fill_rectangles (pixman_op_t               op,
            return TRUE;
        }
     }
-    
+
     solid = pixman_image_create_solid_fill (color);
     if (!solid)
        return FALSE;
@@ -679,13 +679,13 @@ pixman_image_fill_rectangles (pixman_op_t             op,
     for (i = 0; i < n_rects; ++i)
     {
        const pixman_rectangle16_t *rect = &(rects[i]);
-       
+
        pixman_image_composite (op, solid, NULL, dest,
                                0, 0, 0, 0,
                                rect->x, rect->y,
                                rect->width, rect->height);
     }
-    
+
     pixman_image_unref (solid);
 
     return TRUE;
index 5a752ce..30d18cf 100644 (file)
@@ -1698,14 +1698,14 @@ pixman_fill_mmx (uint32_t *bits,
 
     if (bpp == 16)
     {
-       stride = stride * sizeof (uint32_t) / 2;
+       stride = stride * (int) sizeof (uint32_t) / 2;
        byte_line = (uint8_t *)(((uint16_t *)bits) + stride * y + x);
        byte_width = 2 * width;
        stride *= 2;
     }
     else
     {
-       stride = stride * sizeof (uint32_t) / 4;
+       stride = stride * (int) sizeof (uint32_t) / 4;
        byte_line = (uint8_t *)(((uint32_t *)bits) + stride * y + x);
        byte_width = 4 * width;
        stride *= 4;
@@ -2765,16 +2765,16 @@ pixman_blt_mmx (uint32_t *src_bits,
 
     if (src_bpp == 16)
     {
-       src_stride = src_stride * sizeof (uint32_t) / 2;
-       dst_stride = dst_stride * sizeof (uint32_t) / 2;
+       src_stride = src_stride * (int) sizeof (uint32_t) / 2;
+       dst_stride = dst_stride * (int) sizeof (uint32_t) / 2;
        src_bytes = (uint8_t *)(((uint16_t *)src_bits) + src_stride * (src_y) + (src_x));
        dst_bytes = (uint8_t *)(((uint16_t *)dst_bits) + dst_stride * (dst_y) + (dst_x));
        byte_width = 2 * width;
        src_stride *= 2;
        dst_stride *= 2;
     } else if (src_bpp == 32) {
-       src_stride = src_stride * sizeof (uint32_t) / 4;
-       dst_stride = dst_stride * sizeof (uint32_t) / 4;
+       src_stride = src_stride * (int) sizeof (uint32_t) / 4;
+       dst_stride = dst_stride * (int) sizeof (uint32_t) / 4;
        src_bytes = (uint8_t *)(((uint32_t *)src_bits) + src_stride * (src_y) + (src_x));
        dst_bytes = (uint8_t *)(((uint32_t *)dst_bits) + dst_stride * (dst_y) + (dst_x));
        byte_width = 4 * width;
index 56dec83..faaf830 100644 (file)
@@ -712,7 +712,7 @@ union pixman_image
        __bits__ = pict->bits.bits;                                     \
        __stride__ = pict->bits.rowstride;                              \
        __bpp__ = PIXMAN_FORMAT_BPP(pict->bits.format);                 \
-       (out_stride) = __stride__ * sizeof (uint32_t) / sizeof (type);  \
+       (out_stride) = __stride__ * (int) sizeof (uint32_t) / (int) sizeof (type);      \
        (line) = ((type *) __bits__) +                                  \
            (out_stride) * (y) + (mul) * (x);                           \
     } while (0)
index cdf115d..33b1ee6 100644 (file)
@@ -15,7 +15,7 @@
  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL SuSE
  * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
- * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 
+ * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  *
  * Author:  Keith Packard, SuSE, Inc.
@@ -51,10 +51,10 @@ pixman_transform_point_3d (pixman_transform_t *transform,
 
        result.vector[j] = (pixman_fixed_48_16_t) v;
     }
-    
+
     if (!result.vector[2])
        return FALSE;
-    
+
     *vector = result;
     return TRUE;
 }
@@ -90,7 +90,7 @@ pixman_fill8 (uint32_t  *bits,
              int       height,
              uint32_t  xor)
 {
-    int byte_stride = stride * sizeof (uint32_t);
+    int byte_stride = stride * (int) sizeof (uint32_t);
     uint8_t *dst = (uint8_t *) bits;
     uint8_t v = xor & 0xff;
     int i;
@@ -115,7 +115,7 @@ pixman_fill16 (uint32_t *bits,
               int       height,
               uint32_t  xor)
 {
-    int short_stride = (stride * sizeof (uint32_t)) / sizeof (uint16_t);
+    int short_stride = (stride * (int) sizeof (uint32_t)) / (int) sizeof (uint16_t);
     uint16_t *dst = (uint16_t *)bits;
     uint16_t v = xor & 0xffff;
     int i;
@@ -141,9 +141,9 @@ pixman_fill32 (uint32_t *bits,
               uint32_t  xor)
 {
     int i;
-    
+
     bits = bits + y * stride + x;
-    
+
     while (height--)
     {
        for (i = 0; i < width; ++i)
@@ -167,7 +167,7 @@ pixman_fill (uint32_t *bits,
     printf ("filling: %d %d %d %d (stride: %d, bpp: %d)   pixel: %x\n",
            x, y, width, height, stride, bpp, xor);
 #endif
-    
+
 #ifdef USE_MMX
     if (!pixman_have_mmx() || !pixman_fill_mmx (bits, stride, bpp, x, y, width, height, xor))
 #endif
@@ -177,11 +177,11 @@ pixman_fill (uint32_t *bits,
        case 8:
            pixman_fill8 (bits, stride, x, y, width, height, xor);
            break;
-           
+
        case 16:
            pixman_fill16 (bits, stride, x, y, width, height, xor);
            break;
-           
+
        case 32:
            pixman_fill32 (bits, stride, x, y, width, height, xor);
            break;
@@ -191,10 +191,10 @@ pixman_fill (uint32_t *bits,
            break;
        }
     }
-       
+
     return TRUE;
 }
-           
+
 
 /*
  * Compute the smallest value no less than y which is on a
@@ -206,7 +206,7 @@ pixman_sample_ceil_y (pixman_fixed_t y, int n)
 {
     pixman_fixed_t   f = pixman_fixed_frac(y);
     pixman_fixed_t   i = pixman_fixed_floor(y);
-    
+
     f = ((f + Y_FRAC_FIRST(n)) / STEP_Y_SMALL(n)) * STEP_Y_SMALL(n) + Y_FRAC_FIRST(n);
     if (f > Y_FRAC_LAST(n))
     {
@@ -227,7 +227,7 @@ pixman_sample_floor_y (pixman_fixed_t y, int n)
 {
     pixman_fixed_t   f = pixman_fixed_frac(y);
     pixman_fixed_t   i = pixman_fixed_floor (y);
-    
+
     f = _div(f - Y_FRAC_FIRST(n), STEP_Y_SMALL(n)) * STEP_Y_SMALL(n) + Y_FRAC_FIRST(n);
     if (f < Y_FRAC_FIRST(n))
     {
@@ -246,9 +246,9 @@ pixman_edge_step (pixman_edge_t *e, int n)
     pixman_fixed_48_16_t       ne;
 
     e->x += n * e->stepx;
-    
+
     ne = e->e + n * (pixman_fixed_48_16_t) e->dx;
-    
+
     if (n >= 0)
     {
        if (ne > 0)
@@ -278,7 +278,7 @@ _pixman_edge_tMultiInit (pixman_edge_t *e, int n, pixman_fixed_t *stepx_p, pixma
 {
     pixman_fixed_t     stepx;
     pixman_fixed_48_16_t       ne;
-    
+
     ne = n * (pixman_fixed_48_16_t) e->dx;
     stepx = n * e->stepx;
     if (ne > 0)
@@ -328,7 +328,7 @@ pixman_edge_init (pixman_edge_t     *e,
            e->dx = -dx % dy;
            e->e = 0;
        }
-    
+
        _pixman_edge_tMultiInit (e, STEP_Y_SMALL(n), &e->stepx_small, &e->dx_small);
        _pixman_edge_tMultiInit (e, STEP_Y_BIG(n), &e->stepx_big, &e->dx_big);
     }