位移符号错误记录

本文介绍了一种针对NV21格式图像数据的旋转方法,并详细展示了具体的Java代码实现过程。在实现过程中遇到了使用位左移操作替代乘法运算导致数组越界的问题,并给出了修正方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在进行nv21旋转的时候遇到将*2替换成<<1时超出数组范围的错误,在此记录一下

    private static byte[] rote(byte[] nv21, int width, int height) {
        int ySize = width * height;
        byte[] ret = new byte[ySize * 3 >> 1];
        for (int y = 0; y < width; ++y) {
            for (int x = 0; x < height; ++x) {
                ret[y * height + x] = nv21[x * width + width - y];
                ret[ySize + (y >> 1) * height + (x >> 1) * 2] = nv21[ySize + (x >> 1) * width + ((width - y - 1) >> 1) * 2];
                ret[ySize + (y >> 1) * height + (x >> 1) * 2 + 1] = nv21[ySize + (x >> 1) * width + ((width - y - 1) >> 1) * 2 + 1];
            }
        }
        return ret;
    }


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值