硬汉嵌入式论坛

 找回密码
 立即注册
查看: 653|回复: 0
收起左侧

[Lua] LUA做的RGB565转RGB555

[复制链接]

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
107462
QQ
发表于 2022-9-28 12:49:02 | 显示全部楼层 |阅读模式


这效率一般,得弄个更高效的。

[Lua] 纯文本查看 复制代码
function SwitchStr(stryy, len)
	local r
	local g
	local b
    local str44
    local str55  
    local byte0
    local byte1
    local pixel
    local Color16

    str44=""

    for ii=1, len//2, 1 do
        byte0, byte1 = string.byte(stryy,  2*ii-1, 2*ii)
        pixel = byte1*256+byte0
        r = ((pixel & 0xF800) >> 8)		
		g = ((pixel & 0x07E0) >> 3)
		b = ((pixel & 0x001F) << 3)

        --16 bpp Bitmaps in windows are 555: rrrrrgggggbbbbb
        r = ( r * 31 + 127) // 255
        g = ( g * 31 + 127) // 255
        b = ( b * 31 + 127) // 255

        Color16 = (r << 10) | (g << 5) | b

        byte1 = Color16//256
        byte0 = Color16%256

        str55 = string.format("%c%c", byte0, byte1)

        str44 = str44..str55
    end

    printf(string.len(str44))
	
	return str44

end

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|Archiver|手机版|硬汉嵌入式论坛

GMT+8, 2024-6-2 12:08 , Processed in 0.237249 second(s), 26 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表