2012-02-16 42 views
1

如何在下面的代碼中避免編譯器警告(警告:cast會增加所需的目標類型對齊)?ARM上的字對齊?

static int fill_color24 (VisVideo *video, VisColor *color) 
{ 
    int x, y; 
    uint32_t *buf; 
    uint8_t *rbuf = visual_video_get_pixels (video); 
    uint8_t *buf8; 

    int32_t cola = 
     (color->b << 24) | 
     (color->g << 16) | 
     (color->r << 8) | 
     (color->b); 
    int32_t colb = 
     (color->g << 24) | 
     (color->r << 16) | 
     (color->b << 8) | 
     (color->g); 
    int32_t colc = 
     (color->r << 24) | 
     (color->b << 16) | 
     (color->g << 8) | 
     (color->r); 

    for (y = 0; y < video->height; y++) { 
     buf = (uint32_t *) rbuf; // warning is for this line 

     for (x = video->width; x >= video->bpp; x -= video->bpp) { 
      *(buf++) = cola; 
      *(buf++) = colb; 
      *(buf++) = colc; 
     } 

     buf8 = (uint8_t *) buf; 
     *(buf8++) = color->b; 
     *(buf8++) = color->g; 
     *(buf8++) = color->r; 


     rbuf += video->pitch; 
    } 

    return VISUAL_OK; 
} 

回答

1

我不確定你可以。該函數可能會返回未對齊的顏色數組。你無法做任何事情來閱讀那裏的文字。 您必須按組件(uint8_t)讀取顏色,然後通過添加和移位來構造uint32_t。