ARM 上的字对齐?

发布于 2025-01-06 06:26:09 字数 1171 浏览 1 评论 0原文

如何避免以下代码中的编译器警告(警告:强制转换会增加目标类型所需的对齐方式)?

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;
}

How do I go about avoiding the compiler warning (warning: cast increases required alignment of target type) in the following code?

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;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

睫毛溺水了 2025-01-13 06:26:09

我不确定你可以。该函数可能返回未对齐的颜色数组。你无法做任何事情来从那里读取单词。
您必须按组件 (uint8_t) 读取颜色,然后通过添加和移位从这些组件构造 uint32_t。

I'm not sure you can. That function might return color array unaligned. You can't do anything to be able to read word from there.
You will have to read color by components (uint8_t) and then construct uint32_t from these by adding and shifting.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文