2 CANVAS_SIZEはdraw.jsにおいてグローバルに宣言しているためこのファイル内では宣言していない。
7 var canvas = document.getElementById("canvas");
8 var context = canvas.getContext("2d");
10 var canvas2 = document.getElementById("canvas2");
11 var context2 = canvas2.getContext("2d");
13 var canvas3 = document.getElementById("blend_canvas");
14 var context3 = canvas3.getContext("2d");
15 canvas3.width = CANVAS_SIZE;
16 canvas3.height = CANVAS_SIZE;
18 var image = context.getImageData(0,0,canvas.width,canvas.height);
19 var image2 = context2.getImageData(0,0,canvas2.width,canvas2.height);
20 image3 = context3.createImageData(canvas3.width,canvas3.height);
23 var image_rgba = image.data;
24 var image2_rgba = image2.data;
25 var image3_rgba = image3.data;
27 image_rgba = color_change(image_rgba, 1);
28 image2_rgba = color_change(image2_rgba, 2);
29 image3_rgba = make_new_Image(image_rgba, image2_rgba, image3_rgba);
31 context3.putImageData(image3, 0, 0);
36 function color_change(image_rgba, mode){
40 var before_color,after_color;
43 //canvas選択 1-display1のcanvas ,2-display2のcanvas
45 before_color = parseInt(form4.before_color.value);
46 after_color = parseInt(form4.after_color.value);
48 before_color = parseInt(form4.before_color2.value);
49 after_color = parseInt(form4.after_color2.value);
51 diff_color = after_color - before_color;
53 /**************RGB->HSV*******************************/
54 for (var i = 0; i < image_rgba.length ; i++){
55 R = image_rgba[i * 4] / 255;//RGBAの値は0-255で与えられている
56 G = image_rgba[i * 4 + 1] / 255;
57 B = image_rgba[i * 4 + 2] / 255;
61 }else if(R >= G && R >= B){
69 }else if(G >= R && G >= B){
77 }else if(B >= R && B >= G){
88 H = 60 * (G - B)/(max - min);
91 H = (60 * (B - R) / (max - min)) + 120;
94 H = (60 * (R - G) / (max - min)) + 240;
98 /*****************color change*********************/
100 if (before_color != 1 && after_color != 1){
101 if(H >= (before_color-1) * 60 -30 && H < (before_color * 60 -30)){
102 H = H + 60 * diff_color;
104 }else if(before_color == 1 && after_color != 1){
105 if(H >= 0 && H < 30){
106 H = H + 60 * diff_color;
107 }else if(H >= 330 && H <= 360){
108 H = H - 60 * (6 - diff_color);
110 }else if(before_color != 1 && after_color == 1){
111 if(H >= (before_color - 1) * 60 -30 && H < (before_color - 1) * 60 ){
112 H = H + 60 * (6 + diff_color);
113 }else if(H >= (before_color - 1) * 60 && H < before_color * 60 -30){
114 H = H + 60 * diff_color;
120 /***********************HSV->RGB************************/
121 if(H >= 0 && H < 60){
123 G = (H / 60) * (max - min) + min;
125 }else if(H >= 60 && H < 120){
126 R = -((H-120) / 60) * (max - min) + min;
129 }else if(H >= 120 && H < 180){
132 B = ((H-120) / 60) * (max - min) + min;
133 }else if(H >= 180 && H < 240){
135 G = -((H-240) / 60) * (max - min) + min;
137 }else if(H >= 240 && H < 300){
138 R = ((H-240) / 60) * (max - min) + min;
141 }else if(H >= 300 && H <= 360){
144 B = (-(H-360) / 60) * (max - min) + min;
149 image_rgba[i * 4] = R * 255;
150 image_rgba[i * 4 + 1] = G * 255;
151 image_rgba[i * 4 + 2] = B * 255;
158 /*************create new image data*************/
160 image_rgba[count * 4] //R
161 image_rgba[count * 4 + 1] //G
162 image_rgba[count * 4 + 2] //B
163 image_rgba[count * 4 + 3] //A
165 image2_rgba[count * 4] //R
166 image2_rgba[count * 4 + 1] //G
167 image2_rgba[count * 4 + 2] //B
168 image2_rgba[count * 4 + 3] //A
170 function make_new_Image(image_rgba, image2_rgba, image3_rgba){
172 var alpha = parseFloat(form4.alpha.value);
173 var beta = parseFloat(form4.beta.value);
175 for(var count = 0; count < image3_rgba.length; count++){
176 image3_rgba[count * 4] = (image_rgba[count * 4] * alpha) + (image2_rgba[count * 4] * beta);
177 image3_rgba[count * 4 + 1] = (image_rgba[count * 4 + 1] * alpha) + (image2_rgba[count * 4 + 1] * beta);
178 image3_rgba[count * 4 + 2] = (image_rgba[count * 4 + 2] * alpha) + (image2_rgba[count * 4 + 2] * beta);
179 image3_rgba[count * 4 + 3] = 255;
186 function set_alpha(){
187 var alpha = parseFloat(form4.alpha.value);
188 var beta = parseFloat(form4.beta.value); //beta = 1 - alpha
190 var comp = 1.00 - alpha
191 form4.beta.value = comp.toFixed(2);
195 var alpha = parseFloat(form4.alpha.value);
196 var beta = parseFloat(form4.beta.value);
198 var comp = 1.00 - beta;
199 form4.alpha.value = comp.toFixed(2);