| 1 |
|
|---|
| 2 |
/** |
|---|
| 3 |
* - SirdsAS3 - |
|---|
| 4 |
* RDS/SISステレオグラム生成ライブラリ |
|---|
| 5 |
* |
|---|
| 6 |
* RDSColorImageCreatorクラス |
|---|
| 7 |
* SIRDSのカラーイメージを生成 |
|---|
| 8 |
* |
|---|
| 9 |
* @author dsler |
|---|
| 10 |
* @version 1.0.0 |
|---|
| 11 |
* @update 2009/07/02 |
|---|
| 12 |
* |
|---|
| 13 |
* Licensed under The MIT License |
|---|
| 14 |
* Copyright (c) 2009 dsler |
|---|
| 15 |
* Permission is hereby granted, free of charge, to any person obtaining a copy |
|---|
| 16 |
* of this software and associated documentation files (the "Software"), to deal |
|---|
| 17 |
* in the Software without restriction, including without limitation the rights |
|---|
| 18 |
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|---|
| 19 |
* copies of the Software, and to permit persons to whom the Software is |
|---|
| 20 |
* furnished to do so, subject to the following conditions: |
|---|
| 21 |
* The above copyright notice and this permission notice shall be included in |
|---|
| 22 |
* all copies or substantial portions of the Software. |
|---|
| 23 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|---|
| 24 |
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|---|
| 25 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|---|
| 26 |
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|---|
| 27 |
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|---|
| 28 |
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
|---|
| 29 |
* THE SOFTWARE. |
|---|
| 30 |
*/ |
|---|
| 31 |
|
|---|
| 32 |
/** |
|---|
| 33 |
* convertHSV, convertRGBは下記の著作者、及びライセンスのもと公開されたコードです |
|---|
| 34 |
* |
|---|
| 35 |
* Copyright 2007 Michiyasu Wada |
|---|
| 36 |
* |
|---|
| 37 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
|---|
| 38 |
* you may not use this file except in compliance with the License. |
|---|
| 39 |
* You may obtain a copy of the License at |
|---|
| 40 |
* |
|---|
| 41 |
* http://www.apache.org/licenses/LICENSE-2.0 |
|---|
| 42 |
* |
|---|
| 43 |
* Unless required by applicable law or agreed to in writing, software |
|---|
| 44 |
* distributed under the License is distributed on an "AS IS" BASIS, |
|---|
| 45 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|---|
| 46 |
* See the License for the specific language governing permissions and |
|---|
| 47 |
* limitations under the License. |
|---|
| 48 |
* |
|---|
| 49 |
* コード改変:AS3対応、パフォーマンスチューン |
|---|
| 50 |
*/ |
|---|
| 51 |
|
|---|
| 52 |
package org.libspark.dsler.SirdsAS3 |
|---|
| 53 |
{ |
|---|
| 54 |
import __AS3__.vec.Vector; |
|---|
| 55 |
import flash.display.BitmapData; |
|---|
| 56 |
|
|---|
| 57 |
public class RDSColorImageCreator extends RDSImageCreator |
|---|
| 58 |
{ |
|---|
| 59 |
private var _hsv:Vector.<Number>; |
|---|
| 60 |
|
|---|
| 61 |
public function RDSColorImageCreator(canvasWidth:int, canvasHeight:int, rdsPatternWidth:int=100, depthRange:int=20, density:Number=1, color:uint = 0xff0000) |
|---|
| 62 |
{ |
|---|
| 63 |
super(canvasWidth, canvasHeight, rdsPatternWidth, depthRange, density); |
|---|
| 64 |
_hsv = convertHSV(color >> 16, (color & 0x00ff00) >> 8, color & 0x0000ff); |
|---|
| 65 |
} |
|---|
| 66 |
|
|---|
| 67 |
//新しいランダムドットパターンを生成(カラー) |
|---|
| 68 |
override protected function createNewRandomPattern(width:int):BitmapData{ |
|---|
| 69 |
var randomPattern:BitmapData = new BitmapData(width, 1); |
|---|
| 70 |
for(var xi:int = 0; xi < width; xi++){ |
|---|
| 71 |
var random:Number = Math.random()*100, seed:uint = random >> 0, rgb:Vector.<Number> = convertRGB(_hsv[0], seed, 100); |
|---|
| 72 |
if( (random - seed) < _density ) randomPattern.setPixel(xi, 0, rgb[0] << 16 | rgb[1] << 8 | rgb[2]); |
|---|
| 73 |
} |
|---|
| 74 |
return(randomPattern); |
|---|
| 75 |
} |
|---|
| 76 |
|
|---|
| 77 |
public function convertHSV( r:Number, g:Number, b:Number ):Vector.<Number> |
|---|
| 78 |
{ |
|---|
| 79 |
var hsv:Vector.<Number> = new Vector.<Number>, h:Number = 0, s:Number = 0, v:Number = 0, x:Number, y:Number;; |
|---|
| 80 |
r/=255; g/=255; b/=255; |
|---|
| 81 |
if(r>=g) x=r; else x=g; if(b>x) x=b; |
|---|
| 82 |
if(r<=g) y=r; else y=g; if(b<y) y=b; |
|---|
| 83 |
v=x; |
|---|
| 84 |
var c:Number = x - y; |
|---|
| 85 |
if(x==0) s=0; else s=c/x; |
|---|
| 86 |
if(s!=0){ |
|---|
| 87 |
if(r==x){ |
|---|
| 88 |
h=(g-b)/c; |
|---|
| 89 |
} else { |
|---|
| 90 |
if(g==x){ |
|---|
| 91 |
h=2+(b-r)/c; |
|---|
| 92 |
} else { |
|---|
| 93 |
if(b==x){ |
|---|
| 94 |
h=4+(r-g)/c; |
|---|
| 95 |
} |
|---|
| 96 |
} |
|---|
| 97 |
} |
|---|
| 98 |
h=h*60; |
|---|
| 99 |
if(h<0) h+=360; |
|---|
| 100 |
} |
|---|
| 101 |
hsv.push(h, s*100, v*100); |
|---|
| 102 |
return(hsv); |
|---|
| 103 |
} |
|---|
| 104 |
|
|---|
| 105 |
public function convertRGB( h:Number, s:Number, v:Number ):Vector.<Number> |
|---|
| 106 |
{ |
|---|
| 107 |
s=s*0.01, v=v*0.01; |
|---|
| 108 |
var rgb:Vector.<Number> = new Vector.<Number>, r:Number=0, g:Number=0, b:Number=0, i:Number, x:Number, y:Number, z:Number; |
|---|
| 109 |
if(s<0) s=0; if(s>1) s=1; if(v<0) v=0; if(v>1) v=1; |
|---|
| 110 |
h=h%360; if(h<0) h+=360; h/=60; |
|---|
| 111 |
i = h >> 0; |
|---|
| 112 |
x=v*(1-s); y=v*(1-s*(h-i)); z=v*(1-s*(1-h+i)); |
|---|
| 113 |
switch(i){ |
|---|
| 114 |
case 0 : r=v; g=z; b=x; break; |
|---|
| 115 |
case 1 : r=y; g=v; b=x; break; |
|---|
| 116 |
case 2 : r=x; g=v; b=z; break; |
|---|
| 117 |
case 3 : r=x; g=y; b=v; break; |
|---|
| 118 |
case 4 : r=z; g=x; b=v; break; |
|---|
| 119 |
case 5 : r=v; g=x; b=y; break; |
|---|
| 120 |
} |
|---|
| 121 |
rgb.push(r*255, g*255, b*255); |
|---|
| 122 |
return(rgb); |
|---|
| 123 |
} |
|---|
| 124 |
|
|---|
| 125 |
} |
|---|
| 126 |
} |
|---|