设置手机拍照光线怎么设置: al.setColor(ColorRGBA.White.mult(1.3f));什么意思

CSS 合法颜色值
CSS 合法颜色值
可以用以下方法来规定 CSS 中的颜色:
十六进制色
预定义/跨浏览器颜色名
十六进制颜色
所有浏览器都支持十六进制颜色值。
十六进制颜色是这样规定的:#RRGGBB,其中的 RR(红色)、GG(绿色)、BB(蓝色)十六进制整数规定了颜色的成分。所有值必须介于 0 与 FF 之间。
举例说,#0000ff 值显示为蓝色,这是因为蓝色成分被设置为最高值(ff),而其他成分被设置为 0。
background-color:#0000
所有浏览器都支持 RGB 颜色值。
RGB 颜色值是这样规定的:rgb(red, green, blue)。每个参数 (red、green 以及 blue) 定义颜色的强度,可以是介于 0 与 255 之间的整数,或者是百分比值(从 0% 到 100%)。
举例说,rgb(0,0,255) 值显示为蓝色,这是因为 blue 参数被设置为最高值(255),而其他被设置为 0。
同样地,下面的值定义了相同的颜色:rgb(0,0,255) 和 rgb(0%,0%,100%)。
background-color:rgb(255,0,0);
RGBA 颜色值得到以下浏览器的支持:IE9+、Firefox 3+、Chrome、Safari 以及 Opera 10+。
RGBA 颜色值是 RGB 颜色值的扩展,带有一个
alpha 通道 - 它规定了对象的不透明度。
RGBA 颜色值是这样规定的:rgba(red, green, blue, alpha)。alpha 参数是介于 0.0(完全透明)与 1.0(完全不透明)的数字。
background-color:rgba(255,0,0,0.5);
HSL 颜色值得到以下浏览器的支持:IE9+、Firefox、Chrome、Safari 以及 Opera 10+。
HSL 指的是 hue(色调)、saturation(饱和度)、lightness(亮度) - 表示颜色柱面坐标表示法。
HSL 颜色值是这样规定的:hsl(hue, saturation, lightness)。
Hue 是色盘上的度数(从 0 到 360) - 0 (或 360) 是红色,120 是绿色,240 是蓝色。Saturation 是百分比值;0% 意味着灰色,而 100% 是全彩。Lightness 同样是百分比值;0% 是黑色,100% 是白色。
background-color:hsl(120,65%,75%);
HSLA 颜色值得到以下浏览器的支持:IE9+、Firefox 3+、Chrome、Safari 以及 Opera 10+。
HSLA 颜色值是 HSL 颜色值的扩展,带有一个 alpha 通道 - 它规定了对象的不透明度。
HSLA 颜色值是这样规定的:hsla(hue, saturation, lightness, alpha),其中的 alpha 参数定义不透明度。alpha 参数是介于 0.0(完全透明)与 1.0(完全不透明)的数字。
background-color:hsla(120,65%,75%,0.3);CSS color 属性
CSS color 属性
为不同元素设置文本颜色:
color:#00ff00;
color:rgb(0,0,255);
浏览器支持
所有浏览器都支持 color 属性。
注释:任何的版本的 Internet Explorer (包括 IE8)都不支持属性值 &inherit&。
定义和用法
color 属性规定文本的颜色。
这个属性设置了一个元素的前景色(在 HTML 表现中,就是元素文本的颜色);光栅图像不受 color 影响。这个颜色还会应用到元素的所有边框,除非被 border-color 或另外某个边框颜色属性覆盖。
要设置一个元素的前景色,最容易的方法是使用 color 属性。
not specified
JavaScript 语法:
object.style.color=&#FF0000&
提示和注释
提示:请使用合理的背景颜色和文本颜色搭配,这样可以提高文本的可读性。
color_name
规定颜色值为颜色名称的颜色(比如 red)。
hex_number
规定颜色值为十六进制值的颜色(比如 #ff0000)。
rgb_number
规定颜色值为 rgb 代码的颜色(比如 rgb(255,0,0))。
规定应该从父元素继承颜色。
本例演示如何设置文本的颜色。
CSS 教程:
HTML DOM 参考手册:JME基础教程代码分析9 碰撞、刚体、场景加载
编辑:www.fx114.net
本篇文章主要介绍了"JME基础教程代码分析9 碰撞、刚体、场景加载 ",主要涉及到JME基础教程代码分析9 碰撞、刚体、场景加载 方面的内容,对于JME基础教程代码分析9 碰撞、刚体、场景加载 感兴趣的同学可以参考一下。
package com.
import com.jme3.app.SimpleA
import com.jme3.asset.TextureK
import com.jme3.asset.plugins.ZipL
import com.jme3.bullet.BulletAppS
import com.jme3.bullet.collision.shapes.CapsuleCollisionS
import com.jme3.bullet.collision.shapes.CollisionS
import com.jme3.bullet.control.CharacterC
import com.jme3.bullet.control.RigidBodyC
import com.jme3.bullet.util.CollisionShapeF
import com.jme3.input.KeyI
import com.jme3.input.controls.ActionL
import com.jme3.input.controls.KeyT
import com.jme3.light.AmbientL
import com.jme3.light.DirectionalL
import com.jme3.material.M
import com.jme3.math.ColorRGBA;
import com.jme3.math.FastM
import com.jme3.math.Q
import com.jme3.math.Vector3f;
import com.jme3.scene.G
import com.jme3.scene.N
import com.jme3.scene.S
import com.jme3.scene.shape.B
import com.jme3.texture.T
&
/**
&* Example 9 - How to make walls and floors solid.
&* This version uses Physics and a custom Action Listener.
&* @author normen, with edits by Zathras
&*/
public class HelloCollision extends SimpleApplication
&&implements ActionListener {
&
&&private Spatial sceneM
&&private BulletAppState bulletAppS
&&private RigidBodyC
&&private CharacterC
&&private Vector3f walkDirection = new Vector3f();
&&private boolean left = false, right = false, up = false, down =
&&
&&private boolean isTrans =
&
&&private G
&&
&&public static void main(String[] args) {
&& &HelloCollision app = new HelloCollision();
&& &app.start();
&&}
&
&&public void simpleInitApp() {
&& &/** Set up Physics */
&&//设置物理状态,声明一个弹道应用状态
&& &bulletAppState = new BulletAppState();
&& &//将弹道应用状态附加给状态管理对象
&& &stateManager.attach(bulletAppState);
&& &
&& &Box b = new Box(new Vector3f(0f, 4f, 0f), 1, 1, 1);
&& &geom = new Geometry("Box", b);
&& &Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
&& &TextureKey key = new TextureKey("/zw.jpg");
&& &key.setGenerateMips(true);
&& &Texture tex = assetManager.loadTexture(key);
&& &mat.setTexture("ColorMap", tex);
&& &geom.setMaterial(mat);
&& &rootNode.attachChild(geom);
&& &
&& &// We re-use the flyby camera for rotation, while positioning is handled by physics
&& &//为旋转视角再次使用飞行相机,它是通过物理方法定位的
&& &//viewPort是视角范围,设置天空的颜色
&& &viewPort.setBackgroundColor(new ColorRGBA(0.7f,0.8f,1f,1f));
&& &//飞行相机的移动速度
&& &flyCam.setMoveSpeed(100);
&& &setUpKeys();
&& &setUpLight();
&
&& &// We load the scene from the zip file and adjust its size.
&& &//加载场景文件,这里是个.zip文件,包含了场景模型所有文件
&& &assetManager.registerLocator("town.zip", ZipLocator.class.getName());
&& &//加载模型的起始文件名
&& &sceneModel = assetManager.loadModel("main.scene");
&& &sceneModel.setLocalScale(2f);
&
&& &// We set up collision detection for the scene by creating a
&& &// compound collision shape and a static physics node with mass zero.
&& &//使用场景文件创建一个符合碰撞造型
&& &CollisionShape sceneShape =
&& & &CollisionShapeFactory.createMeshShape((Node) sceneModel);
&& &//刚体控制对象,第一个参数是要设置的刚体对象,第二个参数是他的质量,质量为零表示不受物理引力影响,呵呵,效果是悬浮着的
&& &landscape = new RigidBodyControl(sceneShape, 0);
&& &sceneModel.addControl(landscape);
&
&& &// We set up collision detection for the player by creating
&& &// a capsule collision shape and a physics character node.
&& &// The physics character node offers extra settings for
&& &// size, stepheight, jumping, falling, and gravity.
&& &// We also put the player in its starting position.
&& &//这段有点不好理解,可以说是一个胶囊形状的&人&,步幅高度是0.05f,跳跃速度是20,下落速度是30,所受重力是30,并设置了物理位置
&& &//有一点必须注意,这个胶囊&人&没有被渲染,无论如何都无法被看到的。
&& &CapsuleCollisionShape capsuleShape = new CapsuleCollisionShape(1.5f, 6f, 1);
&& &player = new CharacterControl(capsuleShape, 0.05f);
&& &player.setJumpSpeed(20);
&& &player.setFallSpeed(30);
&& &player.setGravity(30);
&& &player.setPhysicsLocation(new Vector3f(0, 10, 0));
&& &// We attach the scene and the player to the rootnode and the physics space,
&& &// to make them appear in the game world.
&& &//附加场景模型到根节点,弹道物理应用状态加载空间对象和player对象到物理空间
&& &rootNode.attachChild(sceneModel);
&& &//加载顺序是无关紧要的,不会因为先加载player,就受重力影响而下落,但是y轴方向的加载位置比较重要,如果没有加载到空间刚体对象的上方,就会无奈的受到重力影响了。
&& &bulletAppState.getPhysicsSpace().add(landscape);
&& &bulletAppState.getPhysicsSpace().add(player);
&&}
&
&& &private void setUpLight() {
&& & & &// We add light so we see the scene
&& & //加载两组光线,环境光,定向光
&& & & &AmbientLight al = new AmbientLight();
&& & & &al.setColor(ColorRGBA.White.mult(1.3f));
&& & & &rootNode.addLight(al);
&
&& & & &DirectionalLight dl = new DirectionalLight();
&& & & &dl.setColor(ColorRGBA.White);
&& & & &dl.setDirection(new Vector3f(2.8f, -2.8f, -2.8f).normalizeLocal());
&& & & &rootNode.addLight(dl);
&& &}
&
&&/** We over-write some navigational key mappings here, so we can
&& * add physics-controlled walking and jumping: */
&&private void setUpKeys() {
&& &inputManager.addMapping("Lefts", &new KeyTrigger(KeyInput.KEY_A));
&& &inputManager.addMapping("Rights", new KeyTrigger(KeyInput.KEY_D));
&& &inputManager.addMapping("Ups", & &new KeyTrigger(KeyInput.KEY_W));
&& &inputManager.addMapping("Downs", &new KeyTrigger(KeyInput.KEY_S));
&& &inputManager.addMapping("Jumps", &new KeyTrigger(KeyInput.KEY_SPACE));
&& &
&& &inputManager.addMapping("Scale", new KeyTrigger(KeyInput.KEY_C));
&& &inputManager.addMapping("Min", new KeyTrigger(KeyInput.KEY_M));
&& &
&& &inputManager.addListener(this, "Lefts");
&& &inputManager.addListener(this, "Rights");
&& &inputManager.addListener(this, "Ups");
&& &inputManager.addListener(this, "Downs");
&& &inputManager.addListener(this, "Jumps");
&& &
&& &inputManager.addListener(this, "Scale");
&& &inputManager.addListener(this, "Min");
&&}
&
&&/** These are our custom actions triggered by key presses.
&& * We do not walk yet, we just keep track of the direction the user pressed. */
&&public void onAction(String binding, boolean value, float tpf) {
&& &if (binding.equals("Lefts")) {
&& & &left =
&& &} else if (binding.equals("Rights")) {
&& & &right =
&& &} else if (binding.equals("Ups")) {
&& & &up =
&& &} else if (binding.equals("Downs")) {
&& & &down =
&& &} else if (binding.equals("Jumps")) {
&& & &player.jump();
&& &} else if (binding.equals("Scale")) {
&& & isTrans =
&& & transPic(geom.getMaterial());
&& & geom.setLocalScale(2);
&& &} else if (binding.equals("Min")) {
&& & isTrans =
&& & transPic(geom.getMaterial());
&& & geom.setLocalScale(1);
&& &}
&& &
&&}
&
&&/**
&& * This is the main event loop--walking happens here.
&& * We check in which direction the player is walking by interpreting
&& * the camera direction forward (camDir) and to the side (camLeft).
&& * The setWalkDirection() command is what lets a physics-controlled player walk.
&& * We also make sure here that the camera moves with player.
&& */
&&@Override
&&public void simpleUpdate(float tpf) {
&& &Vector3f camDir = cam.getDirection().clone().multLocal(0.6f);
&& &Vector3f camLeft = cam.getLeft().clone().multLocal(0.4f);
&& &walkDirection.set(0, 0, 0);
&& &if (left) &{ walkDirection.addLocal(camLeft); }
&& &if (right) { walkDirection.addLocal(camLeft.negate()); }
&& &if (up) & &{ walkDirection.addLocal(camDir); }
&& &if (down) &{ walkDirection.addLocal(camDir.negate()); }
&& &player.setWalkDirection(walkDirection);
&& &cam.setLocation(player.getPhysicsLocation());
&& &Quaternion qt = new Quaternion();
qt.fromAngles(0, FastMath.HALF_PI/4*tpf, 0);
geom.rotate(qt);
&&}
&&
&&private Material transPic(Material src) {
&&if(isTrans) {
&&picname = "/zw.jpg";
&&} else {
&&picname = "/mypic.jpg";
& TextureKey key = new TextureKey(picname);
&& &key.setGenerateMips(true);
&& &Texture tex = assetManager.loadTexture(key);
&& &src.setTexture("ColorMap", tex);
一、不得利用本站危害国家安全、泄露国家秘密,不得侵犯国家社会集体的和公民的合法权益,不得利用本站制作、复制和传播不法有害信息!
二、互相尊重,对自己的言论和行为负责。
本文标题:
本页链接:CSS 文本字体颜色设置方法(CSS color)
互联网 & 发布时间: 21:27:41 & 作者:佚名 &
这篇文章主要介绍了CSS 文本字体颜色设置方法(CSS color),需要的朋友可以参考下
一、认识CSS 颜色(CSS color)
这里要介绍的是网页设置颜色包含有哪些;网页颜色规定规范。
1、常用颜色地方包含:字体颜色、超链接颜色、网页背景颜色、边框颜色2、颜色规范与颜色规定:网页使用RGB模式颜色
二、颜色基础知识
网页中颜色的运用是网页必不可少的一个元素。使用颜色目的在于有区别、有动感(特别是超链接中运用)、美观之用,同时颜色也是各种各样网页的样式表现元素之一,了解CSS 字体颜色。
传统的html颜色与w3c标准下的css颜色对比和DIV CSS运用颜色
CSS color颜色语法:
color:#000000;
Css样式中color后直接加RGB颜色值(#FFFFFF 、#000000 、#F00)RGB颜色值在实际布局时候确定,可以使用Photoshop(简称PS)拾取工具进行获取获得。
三、两种方法设置对象颜色样式
1、在DIV标签内使用color颜色样式&div style=&color:#F00&&www.jb51.net&/div&
2、在CSS选择器中使用color颜色样式CSS代码:
.divcss5{color:#00F}
/* 设置对象divcss5内文字为蓝色 */
扩展阅读:这里运用了CSS注释对此样式设置说明,了解CSS 注释
3、DIV+CSS颜色样式完整案例:
代码如下:.divcss5{color:#00F}/* 设置对象divcss5内文字为蓝色 */
HTML代码:
代码如下:&p& 标签内使用color css样式 &div style="color:#F00"&www.jb51.net 红色&/div& &/p& &p&外部样式表设置对象color颜色 &div class="divcss5"&www.jb51.net 蓝色&/div& &/p&
4、实例结构图:以上使用标签内使用color颜色样式和css代码使用color颜色样式。
四、文字颜色控制一样&&
传统html和css 文字颜色相同使用&color:&+&RGB颜色取值&即可,如颜色为黑色字即对应设置CSS属性选择器内添加&color:#000;&即可。
五、网页背景颜色设置区别&&
传统设置背景颜色使用&bgcolor=颜色取值&,而CSS中则&background:&+颜色取值。例如:设置背景为黑色,传统Html设置,即在标签内加入&bgcolor=&#000&&即可实现颜色为黑色背景,如果在W3C中即在对应CSS选择器中始终&background:#000&实现。
六、设置边框颜色区别&&
传统&bordercolor=取值&,CSS中&border-color:&+颜色取值。例如:在传统html直接在table标签加入&bordercolor=&#000&&即可,在现在CSS中设置&border-color:#000;&即可让边框颜色为黑色,同时记得对包括设置宽度和样式(虚线、实现)。
DIV+CSS颜色值扩展知识:颜色值是一个关键字或一个数字的RGB规范。
16个关键字是采取从Windows的VGA调色板: 水色 , 黑色 , 蓝色 , 紫红色 , 灰 , 绿 , 灰 , 褐红色 ,藏青色, 橄榄色 , 紫色 , 红色 , 银色 , 青色 , 白色 , 黄色 。
七、RGB颜色给出了四种方法之一&&
1、#rrggbb( 如 ,#00cc00) (强烈推荐使用此表示颜色取值)2、#的RGB( 如 ,#0c0) 3、RGB(十中,x,x)的x是一个包容性的0和255之间的整数( 如 的RGB(0,204,0)) 4、RGB(&Y%,&Y%,&Y%),其中 y是一个包容性的数量介于0.0和100.0( 如 的RGB(0%,80%,0%))
八、以下是RGB颜色表当然一般的网页开发软件都有颜色取值器: 网页开发软件DW软件中CSS取色器 如何获得CSS颜色值? 我们又不能记住颜色值,以及如何确定准确的与美工图相同颜色值呢?其实很简单通常我们是在PS软件里通过识色器工具进行获得准确颜色值,当然也可以借用其它专门识别颜色工具进行获取准确的color颜色值。 九、div css color颜色样式总结 使用css样式设置对象内容color颜色样式,我们可以使用命名CSS类对象设置其颜色样式,还有直接在html标签内设置color样式。以上我们也详细介绍和实践这2种对文字内容设置颜色方法。
大家感兴趣的内容
12345678910
最近更新的内容http://topic.csdn.net/u//feb4c317-6aeb-4ba0-9fc1-020bc86a02de.html
RGBA格式图像中HSBC(色相、饱和度、明度、对比度)调整
最近项目中有一个需求:
美术给定一张图片,通过配置文件,在不同建筑等级时使用同一张图片,但是在不同等级时通过程序不断调整hsbc(photoshop中也可以调整)显示出不同的效果。通过搜索,有两种方法解决:
首先介绍下HSL和HSV、HSB:
HSL 和 HSV(也叫HSB)是对中点的两种有关系的表示,它们尝试描述比 RGB 更准确的感知颜色联系,并仍保持在计算上简单。
H指hue()、S指saturation()、L指lightness()、V指value()、B指brightness()
(H)是色彩的基本属性,就是平常所说的名称,如、等。(S)是指色彩的纯度,越高色彩越纯,低则逐渐变灰,取0-100%的数值。(V),亮度(B),取0-100%。
因此要调整RGBA格式的的hsbc,可以先将像素的RGB值转换成HSB格式,然后调整HSB再转换成RGB值就可以了,本人用这种方法处理一张的图片在pc上执行是时间大约是200ms,在每秒30帧的游戏中这样的速度显然是不行的,如果不考虑效率,这种方法也是非常方便的,建议不用担心效率的时候使用该方法。
有没有不用转换格式直接对RGB做特殊处理呢,答案是肯定的:参照AS中
参考链接:
这里的matrix其实是一个Array;
matrix:Array
[read-write]
由 20 个项目组成的数组,适用于 4 x 5 颜色转换。
颜色矩阵滤镜将每个源像素分离成它的红色、绿色、蓝色和 Alpha 成分,分别以 srcR、srcG、srcB 和 srcA 表示。 若要计算四个通道中每个通道的结果,可将图像中每个像素的值乘以转换矩阵中的值。 (可选)可以将偏移量(介于 -255 至 255 之间)添加到每个结果(矩阵的每行中的第五项)中。 滤镜将各颜色成分重新组合为单一像素,并写出结果。 在下列公式中,a[0] 到 a[19] 对应于由 20 个项目组成的数组中的条目 0 至 19,该数组已传递到 matrix 属性:
redResult = (a[0] * srcR) + (a[1] * srcG) + (a[2] * srcB) + (a[3] * srcA) + a[4]
greenResult = (a[5] * srcR) + (a[6] * srcG) + (a[7] * srcB) + (a[8] * srcA) + a[9]
blueResult = (a[10] * srcR) + (a[11] * srcG) + (a[12] * srcB) + (a[13] * srcA) + a[14]
alphaResult = (a[15] * srcR) + (a[16] * srcG) + (a[17] * srcB) + (a[18] * srcA) + a[19]
对于数组中的每个颜色值,值 1 等于正发送到输出的通道的 100%,同时保留颜色通道的值。
所以整个过程中最重要的是求出这个a数组,请参考以下C++的实现,稍微看得懂C++的就可以将其转换成C代码或者其他语言的~
AdjustColor:传入色相、饱和度、明度、对比度值,得出结果的类
ColorMatrix:根据色相、饱和度、明度、对比度值的值分别调整数组内容的类
调用方式可以参考AdjustColor.h中的C接口void ColorAdjust(ColorHSB_T& hsb, void* SrcData, int width, int height)
下面是用到的几个文件:
AdjustColor.h
#ifndef ADJUSTCOLOR_H_
#define ADJUSTCOLOR_H_
#include "ColorMatrix.h"
struct ColorHSB_T
ColorHSB_T(int h = 0, int s = 0, int b = 0, int c = 0):hue(h),saturation(s),brightness(b),contrast(c)
#define PI (3.)
class AdjustColor
AdjustColor();
~AdjustColor();
void setbrightness(float value);
void setcontrast(float value);
void setsaturation(float value);
void sethue(float value);
float** CalculateFinalFlatArray();
bool AllValuesAreSet();
bool CalculateFinalMatrix();
protected:
static float s_arrayOfDeltaIndex[];
ColorMatrix* m_brightnessM
ColorMatrix* m_contrastM
ColorMatrix* m_saturationM
ColorMatrix* m_hueM
ColorMatrix* m_finalM
void ColorAdjust(ColorHSB_T& hsb, void* SrcData, int width, int height);
#endifAdjustColor.cpp
#include "AdjustColor.h"
#include &math.h&
#include &stdlib.h&
#include &stdio.h&
float** s_arr = NULL;
float AdjustColor::s_arrayOfDeltaIndex[]= {
0.01, 0.02, 0.04, 0.05, 0.06, 0.07, 0.08, 0.1,
0.12, 0.14, 0.15, 0.16, 0.17, 0.18, 0.20, 0.21, 0.22, 0.24,
0.25, 0.27, 0.28, 0.30, 0.32, 0.34, 0.36, 0.38, 0.40, 0.42,
0.44, 0.46, 0.48, 0.5,
0.53, 0.56, 0.59, 0.62, 0.65, 0.68,
0.71, 0.74, 0.77, 0.80, 0.83, 0.86, 0.89, 0.92, 0.95, 0.98,
1.06, 1.12, 1.18, 1.24, 1.30, 1.36, 1.42, 1.48, 1.54,
1.60, 1.66, 1.72, 1.78, 1.84, 1.90, 1.96, 2.0,
2.12, 2.25,
2.37, 2.50, 2.62, 2.75, 2.87, 3.0,
AdjustColor::AdjustColor():
m_brightnessMatrix(NULL),
m_contrastMatrix(NULL),
m_saturationMatrix(NULL),
m_hueMatrix(NULL),
m_finalMatrix(NULL)
AdjustColor::~AdjustColor()
if (m_brightnessMatrix)
delete m_brightnessM
if(m_contrastMatrix)
delete m_contrastM
if (m_saturationMatrix)
delete m_saturationM
if (m_finalMatrix)
delete m_finalM
// AdjustColor* AdjustColor::GetInstance()
if (s_adjust)
s_adjust = new AdjustC
void AdjustColor::setbrightness(float value)
if(m_brightnessMatrix == NULL)
m_brightnessMatrix = new ColorMatrix();
if(value != 0)
// brightness does not need to be denormalized
m_brightnessMatrix-&SetBrightnessMatrix(value);
void AdjustColor::setcontrast(float value)
// denormalized contrast value
float deNormVal =
if(value == 0)
deNormVal = 127;
else if(value & 0)
deNormVal = s_arrayOfDeltaIndex[int(value)] * 127 + 127;
deNormVal = (value / 100 * 127) + 127;
if(m_contrastMatrix == NULL)
m_contrastMatrix = new ColorMatrix();
m_contrastMatrix-&SetContrastMatrix(deNormVal);
void AdjustColor::setsaturation(float value)
// denormalized saturation value
float deNormVal =
if (value == 0)
deNormVal = 1;
else if (value & 0)
deNormVal = 1.0 + (3 * value / 100); // max value is 4
deNormVal = value / 100 + 1;
if(m_saturationMatrix == NULL)
m_saturationMatrix = new ColorMatrix();
m_saturationMatrix-&SetSaturationMatrix(deNormVal);
void AdjustColor::sethue(float value)
// hue value does not need to be denormalized
if(m_hueMatrix == NULL)
m_hueMatrix = new ColorMatrix();
if(value != 0)
// Convert to radian
m_hueMatrix-&SetHueMatrix(value * PI / 180.0);
bool AdjustColor::AllValuesAreSet()
return (m_brightnessMatrix && m_contrastMatrix && m_saturationMatrix && m_hueMatrix);
float** AdjustColor::CalculateFinalFlatArray()
if(CalculateFinalMatrix())
return m_finalMatrix-&GetFlatArray();
return NULL;
bool AdjustColor::CalculateFinalMatrix()
if(!AllValuesAreSet())
if (!m_finalMatrix)
m_finalMatrix = new ColorMatrix();
m_finalMatrix-&Multiply(*m_brightnessMatrix);
m_finalMatrix-&Multiply(*m_contrastMatrix);
m_finalMatrix-&Multiply(*m_saturationMatrix);
m_finalMatrix-&Multiply(*m_hueMatrix);
void ColorAdjust(int brightness, int contrast, int saturation, int hue, void* SrcData, int width, int height)
if (NULL == SrcData)
printf("ColorAdjustColorAdjustColorAdjustColorAdjustColorAdjustColorAdjustColorAdjust!!!\n");
AdjustColor
s_adjustColor.setbrightness(brightness);
s_adjustColor.setcontrast(contrast);
s_adjustColor.setsaturation(saturation);
s_adjustColor.sethue(hue);
float** arr = s_adjustColor.CalculateFinalFlatArray();
unsigned char* pData = (unsigned char*)SrcD
for (long i =0; i & width * height * 4; i+=4)
int R,G,B,A;
R=pData[i];
G=pData[i+1];
B=pData[i+2];
A=pData[i+3];
if (0 == A)
for(int j = 0; j & 3; j++)
int res = arr[j][0]*R + arr[j][1]*G + arr[j][2]*B +arr[j][3]*A + arr[j][4];
if (res & 0)
if (res & 255)
res = 255;
pData[i + j] =
AdjustColor
void SetColorAdjust(int brightness, int contrast, int saturation, int hue)
s_adjustColor.setbrightness(brightness);
s_adjustColor.setcontrast(contrast);
s_adjustColor.setsaturation(saturation);
s_adjustColor.sethue(hue);
s_arr = s_adjustColor.CalculateFinalFlatArray();
float GetResult(int row, int col)
float val = 0;
if (s_arr && row & 5 && col & 5)
val = s_arr[row][col];
ColorMatrix.h#ifndef COLORMATRIE_H_
#define COLORMATRIE_H_
#include &stdlib.h&
#if defined COLORMATRIX_DLL_EXPORT
#define COLORMATRIX_DECLDIR __declspec(dllexport)
#define COLORMATRIX_DECLDIR __declspec(dllimport)
class COLORMATRIX_DECLDIR DynamicMatrix
static const int MATRIX_ORDER_PREPEND = 0;
static const int MATRIX_ORDER_APPEND = 1;
DynamicMatrix(int w, int h);
~DynamicMatrix();
int GetWidth();
int GetHeight();
float GetValue(int row, int col);
void SetValue(int row, int col, float value);
void LoadIdentity();
void LoadZeros();
bool Multiply(DynamicMatrix& inMatrix, int order = MATRIX_ORDER_PREPEND);
bool MultiplyNumber(float value);
bool Add(DynamicMatrix&inMatrix);
protected:
void Create(int width, int height);
void Destroy();
float** m_
class ColorMatrix:public DynamicMatrix
ColorMatrix();
void SetBrightnessMatrix(float value);
void SetContrastMatrix(float value);
void SetSaturationMatrix(float value);
void SetHueMatrix(float angle);
float** GetFlatArray();
protected:
static float LUMINANCER;
static float LUMINANCEG;
static float LUMINANCEB;
ColorMatrix.cpp
#include "ColorMatrix.h"
#include &math.h&
int max(int a, int b)
return a & b ? a:b;
DynamicMatrix::DynamicMatrix(int w, int h)
m_width = 0;
m_height = 0;
m_matrix = NULL;
Create(w, h);
void DynamicMatrix::Create(int width, int height)
if(width &= 0 || height &= 0)
m_height =
m_matrix = new float*[height];
for(int i = 0; i & i++)
m_matrix[i] = new float[width];
for(int j = 0; j & j++)
m_matrix[i][j] = 0;
DynamicMatrix::~DynamicMatrix()
Destroy();
void DynamicMatrix::Destroy()
if (m_matrix)
for(int i = 0; i & m_ i++)
delete [](m_matrix[i]);
m_matrix = NULL;
int DynamicMatrix::GetWidth()
int DynamicMatrix::GetHeight()
float DynamicMatrix::GetValue(int row, int col)
float val = 0;
if (row &= 0 && row & m_height && col &= 0 && col &= m_width)
val = m_matrix[row][col];
void DynamicMatrix::SetValue(int row, int col, float value)
if(row &= 0 && row & m_height && col &= 0 && col &= m_width)
m_matrix[row][col] =
void DynamicMatrix::LoadIdentity()
if(NULL == m_matrix)
for(int i = 0; i & m_ i++)
for(int j = 0; j & m_ j++)
if(i == j)
m_matrix[i][j] = 1;
m_matrix[i][j] = 0;
void DynamicMatrix::LoadZeros()
if(NULL == m_matrix)
for(int i = 0; i & m_ i++)
for(int j = 0; j & m_ j++)
m_matrix[i][j] = 0;
bool DynamicMatrix::Multiply(DynamicMatrix& inMatrix, int order)
if(!m_matrix)
int inHeight = inMatrix.GetHeight();
int inWidth = inMatrix.GetWidth();
int i = 0;
int j = 0;
int k = 0;
int m = 0;
float total = 0;
DynamicMatrix* result = NULL;
if(order == MATRIX_ORDER_APPEND)
//inMatrix on the left
if(m_width != inHeight)
DynamicMatrix result(inWidth, m_height);
for(i = 0; i & m_ i++)
for(j = 0; j & inW j++)
total = 0;
for(k = 0, m = 0; k & max(m_height, inHeight) && m & max(m_width, inWidth); k++, m++)
total = total + (inMatrix.GetValue(k, j) * m_matrix[i][m]);
result.SetValue(i, j, total);
// destroy self and recreate with a new dimension
Destroy();
Create(inWidth, m_height);
// assign result back to self
for(i = 0; i & inH i++)
for(j = 0; j & m_ j++)
m_matrix[i][j] = result.GetValue(i, j);
// inMatrix on the right
if(m_height != inWidth)
DynamicMatrix result(m_width, inHeight);
for(i = 0; i & inH i++)
for(j = 0; j & m_ j++)
total = 0;
for(k = 0, m = 0; k & max(inHeight, m_height) && m & max(inWidth, m_width); k++, m++)
total = total + ( (m_matrix[k][j]) * (inMatrix.GetValue(i, m)));
result.SetValue(i, j, total);
// destroy self and recreate with a new dimension
Destroy();
Create(m_width, inHeight);
// assign result back to self
for(i = 0; i & inH i++)
for(j = 0; j & m_ j++)
m_matrix[i][j] = result.GetValue(i, j);
bool DynamicMatrix::MultiplyNumber(float value)
if(!m_matrix)
for(int i = 0; i & m_ i++)
for(int j = 0; j & m_ j++)
float total = 0;
total = m_matrix[i][j] *
m_matrix[i][j] =
bool DynamicMatrix::Add(DynamicMatrix&inMatrix)
if(!m_matrix)
int inHeight = inMatrix.GetHeight();
int inWidth = inMatrix.GetWidth();
if(m_width != inWidth || m_height != inHeight)
for(int i = 0; i & m_ i++)
for(int j = 0; j & m_ j++)
float total = 0;
total = m_matrix[i][j] + inMatrix.GetValue(i, j);
m_matrix[i][j] =
///////////////////////////////////////////////////
float ColorMatrix::LUMINANCER = 0.3086;
float ColorMatrix::LUMINANCEG = 0.6094;
float ColorMatrix::LUMINANCEB = 0.0820;
ColorMatrix::ColorMatrix():DynamicMatrix(5, 5)
LoadIdentity();
void ColorMatrix::SetBrightnessMatrix(float value)
if (!m_matrix)
m_matrix[0][4] =
m_matrix[1][4] =
m_matrix[2][4] =
void ColorMatrix::SetContrastMatrix(float value)
if(!m_matrix)
float brightness= 0.5 * (127.0 - value);
value = value / 127.0;
m_matrix[0][0] =
m_matrix[1][1] =
m_matrix[2][2] =
m_matrix[0][4] =
m_matrix[1][4] =
m_matrix[2][4] =
void ColorMatrix::SetSaturationMatrix(float value)
if(!m_matrix)
float subVal = 1.0 -
float mulVal= subVal * LUMINANCER;
m_matrix[0][0] = mulVal +
m_matrix[1][0] = mulV
m_matrix[2][0] = mulV
mulVal = subVal * LUMINANCEG;
m_matrix[0][1] = mulV
m_matrix[1][1] = mulVal +
m_matrix[2][1] = mulV
mulVal = subVal * LUMINANCEB;
m_matrix[0][2] = mulV
m_matrix[1][2] = mulV
m_matrix[2][2] = mulVal +
void ColorMatrix::SetHueMatrix(float angle)
if(!m_matrix)
LoadIdentity();
DynamicMatrix baseMat(3, 3);
DynamicMatrix cosBaseMat(3, 3);
DynamicMatrix sinBaseMat(3, 3);
float cosValue = cos(angle);
float sinValue = sin(angle);
// slightly smaller luminance values from SVG
float lumR = 0.213;
float lumG = 0.715;
float lumB = 0.072;
baseMat.SetValue(0, 0, lumR);
baseMat.SetValue(1, 0, lumR);
baseMat.SetValue(2, 0, lumR);
baseMat.SetValue(0, 1, lumG);
baseMat.SetValue(1, 1, lumG);
baseMat.SetValue(2, 1, lumG);
baseMat.SetValue(0, 2, lumB);
baseMat.SetValue(1, 2, lumB);
baseMat.SetValue(2, 2, lumB);
cosBaseMat.SetValue(0, 0, (1 - lumR));
cosBaseMat.SetValue(1, 0, -lumR);
cosBaseMat.SetValue(2, 0, -lumR);
cosBaseMat.SetValue(0, 1, -lumG);
cosBaseMat.SetValue(1, 1, (1 - lumG));
cosBaseMat.SetValue(2, 1, -lumG);
cosBaseMat.SetValue(0, 2, -lumB);
cosBaseMat.SetValue(1, 2, -lumB);
cosBaseMat.SetValue(2, 2, (1 - lumB));
cosBaseMat.MultiplyNumber(cosValue);
sinBaseMat.SetValue(0, 0, -lumR);
sinBaseMat.SetValue(1, 0, 0.143);
// not sure how this value is computed
sinBaseMat.SetValue(2, 0, -(1 - lumR));
sinBaseMat.SetValue(0, 1, -lumG);
sinBaseMat.SetValue(1, 1, 0.140);
// not sure how this value is computed
sinBaseMat.SetValue(2, 1, lumG);
sinBaseMat.SetValue(0, 2, (1 - lumB));
sinBaseMat.SetValue(1, 2, -0.283);
// not sure how this value is computed
sinBaseMat.SetValue(2, 2, lumB);
sinBaseMat.MultiplyNumber(sinValue);
baseMat.Add(cosBaseMat);
baseMat.Add(sinBaseMat);
for(int i = 0; i & 3; i++)
for(int j = 0; j & 3; j++)
m_matrix[i][j] = baseMat.GetValue(i, j);
float** ColorMatrix::GetFlatArray()
if(!m_matrix)
return NULL;
通过测试使用同样一张的图片,用这个方法使用的时间在40ms左右,效率相对来说比较高。但是效果和photoshop的同样的值调整出来的不一样,可能是经验值导致的,具体原因还不清楚。如果需要可以做一个工具让美术根据这个算法调整相应值。
没有更多推荐了,

我要回帖

更多关于 ios光线感应设置 的文章

 

随机推荐