a script to change the color depth of a bitmapData.
A couple of months ago, I tried to make a color reduction script. It was based on a series of BitmapData copyChannel / paletteMaps but it caused a lot of artefacts for the script couldn’t manage very low nor very high colors.
So I took it from the start, I tried to replace the paletteMap with thresholds which appear to be much faster. Yet it wasn’t satisfying ; it kept creating temporary bitmaps and batch processing them was still notoriously killling the performances. For instance if I wanted to reduce the color depth by 2 the script would perform (4 * 127) thresholds(one per channel) + the copy operations, which is veeeery bad.
the good thing with this method was when you wanted to decrease significantly the color depth, it could run pretty well. with 20 or 24 thresholds in all, the speed was convincing.
But I started manipulating the pixels themselves. no more channel splitting which really did good.
First I tried with the ByteArray and my conclusion is that it is much much slower than a get/setPixel on a locked BitmapData. and it was indeed a bad surprise…
So I resigned myself to use the good old getPixel, perform a mathematic operation and then setPixel. And it works pretty well, of course the processing time is higher than big threshold reductions but it’s constant(for a given amount of pixels) and more accurate.
see for yourslef:
I didn’t count the colors and I am not clever enough to create a real professionnal, accurate script that would handle color profiles plus I don’t really care in fact, I’m only interested in the graphical output.
so from from left to right and top-down:
- the original BitmapData that is used to perform the tests
- ReduceColors.toCGA( original ) : 8 colors (few! Ican still count to 8 ^^)
- ReduceColors.toEGA( original ) : +/- 64 colors (there are dark shades too)
- ReduceColors.toVGA( original ) : +/- 256 colors
- ReduceColors.toHAM( original ) : +/- 4096 colors
- ReduceColors.toSVGA( original ) : +/- 65536 colors
The class itself is quite idiot-proof, you can choose one of the presets above and use them as follow:
ReduceColors.toCGA( original:BitmapData, grayscale:Boolean, alpha:Boolean )
where original is the original BitmapData, grayscale is a Boolean value to get a grayscaleoutput(wow!) and alpha another boolean that specifies wether the thresholding should be applied to the alpha channel or not. Both are set to false by default.
For the wildests amongst you, you can directly call:
ReduceColors.reduceColors( original:BitmapData, number:int, grayscale:Boolean, alpha:Boolean )
where the additional parameter number represents the number of steps that will be created to replace the original 255. During the process, colors will be snapped to the closest value they can find in the lookup table. And That’s the very thing I ‘m not proud of, to keep both black and white, I forced them in the array by making each step equal to (255/number+2).
This +2, is all but healthy and, even though it works as such, I’m sure that it could be done in a much more elegant way.
finally here’s a demo of a couple of settings to show you how to use the reduceColors() method:
and its little source file: reduceColors
I guess that was it,
enjoy :)
Tags: actionscript, actionscript 3, BitmapData, CGA, color depth, colors, EGA, HAM,process, VGA
相关推荐
android:background="@android:color/white"/> 即让TextView产生阴影其中属性z_depth是设置阴影的大小,是个枚举值:z_depth0、z_depth1、z_depth2、z_depth3、z_depth4、z_depth5, 值越大阴影越大。你也...
To overcome this problem, we propose to exploit depth information to provide more invariant body shape and skeleton information regardless of illumination and color change. More specifically, we ...
Bug fixes, new property - Fog Emission Color, now you can change fog and object emission separately! Make your unique atmosphere! NOTE: Per object shader, not support terrain - Perfect for creating ...
* Change to Color:颜色替换 * Channel Mixer:通道混合 * Color Balance:色彩平衡 * Color Balance (HIS):色彩平衡(HIS) * Color Link:色彩连接 * Color Stabilizer:色彩平衡器 * Colorama:彩光 * Curves:...
`CC Color Offset`色彩偏移,`CC Kernel`调整颜色核心,`CC Toner`实现特定色调,`Change Color`转换颜色,`Change to Color`替换颜色,`Channel Mixer`混合通道,`Color Balance`调整整体色彩平衡,`Color Balance...
-treedepth value color tree depth -transparent-color color transparent color -undercolor color annotation bounding box color -units type the units of image resolution -verbose print detailed ...
修改颜色深度 Change color depth 扫描(批量扫描)支持 Scan (batch scan) support 剪切/裁剪 Cut/crop 编辑IPTC IPTC editing 多种效果:锐化、模糊、Adobe 8BF、Filter Factory, Filters Unlimited等 Effects...
**描述**:Color Corrector是一款能够自动修正立体视频中颜色差异的插件,确保左右眼看到的画面在色彩上达到一致。 **使用步骤**: - 导入待处理的立体视频素材。 - 选择Color Corrector插件进行应用。 - 调整参数...
• Full support for sparse working copies with folder depth extension and reduction Integrated Compare View: • Compare text and images • Syntax coloring for C/C++, CSS, HTML, Javascript, Objective-...
- **Change Color**:更改图像中特定颜色的外观。 - **Change to Color**:将图像转换为单一颜色。 - **Color Balance**:调整红、绿、蓝三原色的比例。 - **Color Balance (HLS)**:基于色调、饱和度和亮度进行...
修改颜色深度 Change color depth 扫描(批量扫描)支持 Scan (batch scan) support 剪切/裁剪 Cut/crop 编辑IPTC IPTC editing 多种效果:锐化、模糊、Adobe 8BF、Filter Factory, Filters Unlimited等 Effects ...
10. **Change to Color (转换颜色)**:将图像转换为特定颜色。 11. **Channel Mixer (通道混合)**:混合不同颜色通道。 12. **Color Balance (色彩平衡)**:调整图像的色彩平衡。 13. **Color Balance (HLS) (色彩...
Thread depthChangeThread = new Thread(() => { /* processing to change color depth of image */ }); depthChangeThread.Name = "DepthChange Thread"; depthChangeThread.Start(); } ``` 在C# 3.0及更高...
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer glLoadIdentity(); // Reset The Current Modelview Matrix glTranslatef(0.0f,0.0f,-300.0f); // Move ...
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer glLoadIdentity(); glColor3f(0.5f,0.5f,1.0f); aa(); cc(); bb(); // Reset The Current Modelview Matrix return ...
Although the API is familiar, the new challenges of size and power consumption make for a great change of scenery. In his fleeting spare time, Benj tries to get outdoors for some hiking or kayaking. ...
• Blend, Cull, Stencil, Color Mask and Depth options can now reference properties. • Properties now can have custom attributes. • Improved editor rendering pipeline leading to huge performance ...
Contrast enhancement together with color restoration is a challenging mission for conventional fog-removal methods, as the degrading effect of fog is largely dependent on scene depth information....
The Radial Gap offers the option of providing a hole in the center of the Rose Chart - a subtle change, but it offers a similar visual difference in the way a Pie Chart can become a Doughnut Chart ...