如何表示从16bit颜色深度到18bit颜色深度? [英] How to represent from 16bit color depth to 18bit color depth?

查看:723
本文介绍了如何表示从16bit颜色深度到18bit颜色深度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

如何表示18位颜色深度到16位颜色深度?

我正在移植一个从16位色深设备到18位色深设备的软件?如何表示18位颜色深度?谢谢。

I'm porting a software that build from 16-bit color depth device to 18-bit color depth device? How can I represent the 18-bit color depth? Thanks.

推荐答案

注意:这只是我对上一个问题的回答的编辑,

NOTE: This is just an edit of my answer to your previous question, since the two are so similar - you just have to reverse the process.

您将首先访问每个的颜色成分(即,提取R值,G值和B值)。这样做的方式将完全取决于颜色存储在内存中的方式。如果它存储为RGB,组件的5-6-5位,您可以使用像这样:

You will first of all have to access each of the colour components (i.e. extract the R value, the G value, and the B value). The way to do this will depend totally on the way that the colour is stored in memory. If it is stored as RGB, with 5-6-5 bits for the components, you could use something like this:

blueComponent  = (colour & 0x3F);
greenComponent = (colour >>  6) & 0x3F;
redComponent   = (colour >> 12) & 0x3F;

这将为您提取颜色组件,然后您可以使用上述方法将每个组件(我假设18位将使用每个组件6位):

This will extract the colour components for you, then you can use the method outlined above to convert each of the components (I presume 18-bit will use 6 bits per component):

blueComponent  = (blueComponent  / 64.0) * 32;
//greenComponent = (greenComponent / 64.0) * 64;    //not needed
redComponent   = (redComponent   / 64.0) * 32;

请注意,使用上述代码,请务必使用 64.0 ,或一些其他方法,将确保您的程序将数字表示为浮点数。然后,将组件合并为18位颜色,请使用:

Note that with the above code, it is important that you use 64.0, or some other method that will ensure that your program represents the number as a floating point number. Then to combine the components into your 18-bit colour, use:

colour = (redComponent << 11) | (greenComponent << 5) | blueComponent;

这篇关于如何表示从16bit颜色深度到18bit颜色深度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆