阿木 2008-2-12 15:37
sRGB和scRGB的区别
.net FrameWork 3.0 后,我们会发现有两个Color数据结构。
一个是:System.Drawing.Color
一个是:System.Windows.Media.Color
[b]这两个结构有啥区别呢?[/b]
下面是对这两个类的属性的一个简单比较:
[table=98%][tr][td=1,1,69] [/td][td=1,1,249][b]System.Drawing.Color Structure[/b][/td][td=1,1,295][b]System.Windows.Media.Color Structure[/b][/td][/tr][tr][td=1,1,70]所在组件[/td][td=1,1,249]System.Drawing.dll[/td][td=1,1,295]PresentationCore.dll[/td][/tr][tr][td=1,1,71]支持的版本[/td][td=1,1,249].NET Framework
Supported in: 3.5, 3.0 SP1, 3.0, 2.0 SP1, 2.0, 1.1, 1.0 .NET Compact Framework
Supported in: 3.5, 2.0, 1.0 XNA Framework
Supported in: 1.0
[/td][td=1,1,295].NET Framework
Supported in: 3.5, 3.0 SP1, 3.0
[/td][/tr][tr][td=1,1,71]A[/td][td=1,1,249]Gets the alpha component value of this Color structure. [/td][td=1,1,295]Gets or sets the sRGB alpha channel value of the color.[/td][/tr][tr][td=1,1,72]B[/td][td=1,1,249]Gets the blue component value of this Color structure.[/td][td=1,1,295]Gets or sets the sRGB blue channel value of the color.[/td][/tr][tr][td=1,1,72]G[/td][td=1,1,249]Gets the green component value of this Color structure.[/td][td=1,1,295]Gets or sets the sRGB green channel value of the color.[/td][/tr][tr][td=1,1,72]R[/td][td=1,1,249]Gets the red component value of this Color structure.[/td][td=1,1,295]Gets or sets the sRGB red channel value of the color.[/td][/tr][tr][td=1,1,72]ScA[/td][td=1,1,249]不支持[/td][td=1,1,295]Gets or sets the ScRGB alpha channel value of the color.[/td][/tr][tr][td=1,1,72]ScB[/td][td=1,1,249]不支持[/td][td=1,1,295]Gets or sets the ScRGB blue channel value of the color.[/td][/tr][tr][td=1,1,72]ScG[/td][td=1,1,249]不支持[/td][td=1,1,295]Gets or sets the ScRGB green channel value of the color.[/td][/tr][tr][td=1,1,72]ScR[/td][td=1,1,249]不支持[/td][td=1,1,295]Gets or sets the ScRGB red channel value of the color.[/td][/tr][tr][td=1,1,72]获得系统支持的一些颜色[/td][td=1,1,249]在Color中定义了141种系统预定义的颜色
调用方法如下:
System.Drawing.Color.AliceBlue[/td][td=1,1,295]不在Color中定义,而是Colors中定义,获得方法类似下面写法:
System.Windows.Media.Colors.AliceBlue
系统一共预定义了141个颜色。[/td][/tr][tr][td=1,1,72]小结[/td][td=1,1,249]只支持 sRGB。向下兼容[/td][td=1,1,295]同时支持 sRGB、ScRGB。不兼容3.0以下的版本[/td][/tr][/table]我们可以在上面看到,关键是sRGB和ScRGB两种颜色表示方法。这两种有啥差别呢?我们来看下面三副图,先来感性的看看: [img]http://blog.joycode.com/images/blog.joycode.com/ghj/1489/r_srbg.png[/img]
这幅图的巧妙之外在于它通过“归一化”,用两维平面来表示三个数据。X轴是红色的比例,Y轴是绿色的比例,而Z轴是蓝色的比例,虽然Z轴没有画出来,但它的比例数据可以很方便地计算出来。比方红是0.2,绿是0.3,那么蓝就是0.5。因为它们三者加起来必须等于1,不然怎么叫“归一化”呢!图上任何一点的蓝色分量,你都可以用这个方法计算出来。 图中的“舌形”色域空间,是人眼能够辨别的色彩空间,它的边缘围绕一道从波长从380到700(毫微米)的光谱,中间就是用红、绿、蓝三种颜色按不同比例调配出来的颜色。 而图中的三角的区域,是 sRGB 可以表示的颜色范围。显然有一些我们人类可以看到的颜色,但是sRGB来描述的。 [img]http://blog.joycode.com/images/blog.joycode.com/ghj/1489/r_scrgb.gif[/img] 上面这幅图对比了 sRGB、人眼、ScRGB 可以表示的颜色范围。 [img]http://blog.joycode.com/images/blog.joycode.com/ghj/1489/r_sRGBandscRGB.jpg[/img] 上面这幅图是sRGB和ScRGB两幅图的比较,注意看放大了的云彩。 [b]sRGB 和 scRGB 的转换[/b]
在 System.Windows.Media.Color 结构中,scRGB原色其实是被储存成单精度(single-precision)的浮点数。想要容纳scRGB颜色空间,Color 结构包含四个主要的property,类型都是float,分别为ScA、ScR、ScG、ScB。
这些property和A、R、G、B property 会相互影响,改编G property也会造成ScG property的改变,反之亦然。
当G property 为0,ScG property 也会为0;当G property 为255,ScG property 就会为1。在这个范围之内,
关系并非是线性的,如下表所示。
[table=298][tr][td=1,1,137]scG[/td][td=1,1,153]G[/td][/tr][tr][td=1,1,137]<= 0[/td][td=1,1,153]0[/td][/tr][tr][td=1,1,137]0.1[/td][td=1,1,153]89[/td][/tr][tr][td=1,1,137]0.2[/td][td=1,1,153]124[/td][/tr][tr][td=1,1,137]0.3[/td][td=1,1,153]149[/td][/tr][tr][td=1,1,137]0.4[/td][td=1,1,153]170[/td][/tr][tr][td=1,1,137]0.5[/td][td=1,1,153]188[/td][/tr][tr][td=1,1,137]0.6[/td][td=1,1,153]203[/td][/tr][tr][td=1,1,137]0.7[/td][td=1,1,153]218[/td][/tr][tr][td=1,1,137]0.8[/td][td=1,1,153]231[/td][/tr][tr][td=1,1,137]0.9[/td][td=1,1,153]243[/td][/tr][tr][td=1,1,137]>=1.0[/td][td=1,1,154]255[/td][/tr][/table]ScR 与 R 之间的关系,ScB与B之间的关系,以及ScG与G之间的关系,也都是一样的。ScG的值可以小于0或者大于1,以容纳超出显示器和sRGB数字范围的颜色。
sRGB和scRGB的比较
sRGB目标是使同一网页在不同计算机上显示时的色彩更一致,但只适用于CRT显示器。微软HD Photo项目负责人克劳说,sRGB的挑战在于它只是完整色彩空间的一个子集,当使用sRGB编码时,我们会丢掉一些色彩。
scRGB色彩空间是sRGB扩展,对于黑色和纯绿色而言,这二者没有任何分别。二者的差别就在于scRGB能够显示人眼无法分辨的颜色,其精细程度也超过了sRGB。 scRGB描述每个点所需要的位数是sRGB 2倍,甚至是4倍。不仅能够使用整数,还能够使用浮点数,提高图像的精细程度。