ace-colorpicker-rpk 0.0.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (238) hide show
  1. package/.babelrc +30 -0
  2. package/.github/ISSUE_TEMPLATE/bug_report.md +35 -0
  3. package/.github/ISSUE_TEMPLATE/feature_request.md +17 -0
  4. package/ChangeLogs.md +22 -0
  5. package/LICENSE +21 -0
  6. package/README.md +117 -0
  7. package/addon/ace-colorpicker.css +1074 -0
  8. package/addon/ace-colorpicker.js +9602 -0
  9. package/addon/sample/colorpicker.html +199 -0
  10. package/config/rollup.config.dev.js +52 -0
  11. package/config/rollup.config.prod.js +53 -0
  12. package/dist/ace-colorpicker.css +1074 -0
  13. package/dist/ace-colorpicker.js +9736 -0
  14. package/dist/ace-colorpicker.min.js +1 -0
  15. package/gl.html +56 -0
  16. package/index.html +172 -0
  17. package/package.json +87 -0
  18. package/resources/image/ace-editor.png +0 -0
  19. package/resources/image/colorpaletts.png +0 -0
  20. package/resources/image/colorpicker.png +0 -0
  21. package/resources/image/grapes.jpg +0 -0
  22. package/resources/image/palette-type.png +0 -0
  23. package/resources/image/scalecolors-title.png +0 -0
  24. package/resources/image/scalecolors.png +0 -0
  25. package/resources/image/screen-shot.png +0 -0
  26. package/resources/image/sketch-type.png +0 -0
  27. package/src/colorpicker/BaseBox.js +94 -0
  28. package/src/colorpicker/BaseColorPicker.js +404 -0
  29. package/src/colorpicker/BaseModule.js +19 -0
  30. package/src/colorpicker/BaseSlider.js +97 -0
  31. package/src/colorpicker/BaseStore.js +71 -0
  32. package/src/colorpicker/UIElement.js +46 -0
  33. package/src/colorpicker/VerticalSlider.js +57 -0
  34. package/src/colorpicker/chromedevtool/ColorControl.js +47 -0
  35. package/src/colorpicker/chromedevtool/index.js +36 -0
  36. package/src/colorpicker/index.js +37 -0
  37. package/src/colorpicker/macos/ColorControl.js +47 -0
  38. package/src/colorpicker/macos/index.js +38 -0
  39. package/src/colorpicker/mini/ColorControl.js +40 -0
  40. package/src/colorpicker/mini/index.js +24 -0
  41. package/src/colorpicker/mini-vertical/ColorControl.js +35 -0
  42. package/src/colorpicker/mini-vertical/index.js +23 -0
  43. package/src/colorpicker/module/ColorManager.js +111 -0
  44. package/src/colorpicker/module/ColorSetsList.js +132 -0
  45. package/src/colorpicker/ring/ColorControl.js +47 -0
  46. package/src/colorpicker/ring/index.js +42 -0
  47. package/src/colorpicker/ui/ColorInformation.js +216 -0
  48. package/src/colorpicker/ui/ColorPalette.js +130 -0
  49. package/src/colorpicker/ui/ColorRing.js +68 -0
  50. package/src/colorpicker/ui/ColorSetsChooser.js +96 -0
  51. package/src/colorpicker/ui/ColorWheel.js +257 -0
  52. package/src/colorpicker/ui/CurrentColorSets.js +81 -0
  53. package/src/colorpicker/ui/CurrentColorSetsContextMenu.js +63 -0
  54. package/src/colorpicker/ui/control/Hue.js +40 -0
  55. package/src/colorpicker/ui/control/Opacity.js +65 -0
  56. package/src/colorpicker/ui/control/Value.js +50 -0
  57. package/src/colorpicker/ui/control/VerticalHue.js +39 -0
  58. package/src/colorpicker/ui/control/VerticalOpacity.js +55 -0
  59. package/src/colorpicker/vscode/ColorControl.js +40 -0
  60. package/src/colorpicker/vscode/index.js +82 -0
  61. package/src/colorpicker/xd/ColorControl.js +36 -0
  62. package/src/colorpicker/xd/index.js +36 -0
  63. package/src/extension/ace/colorview.js +198 -0
  64. package/src/extension/ace/index.js +11 -0
  65. package/src/index.js +12 -0
  66. package/src/scss/colorpicker.scss +65 -0
  67. package/src/scss/colorview.scss +32 -0
  68. package/src/scss/component/button.scss +33 -0
  69. package/src/scss/component/colorchooser.scss +141 -0
  70. package/src/scss/component/colorsets-contextmenu.scss +33 -0
  71. package/src/scss/component/colorsets.scss +89 -0
  72. package/src/scss/component/control.scss +93 -0
  73. package/src/scss/component/gradient-editor.scss +260 -0
  74. package/src/scss/component/gradient-picker.scss +241 -0
  75. package/src/scss/component/information.scss +141 -0
  76. package/src/scss/component/palette.scss +45 -0
  77. package/src/scss/index.scss +5 -0
  78. package/src/scss/mixins.scss +21 -0
  79. package/src/scss/themes/macos.scss +71 -0
  80. package/src/scss/themes/mini-vertical.scss +94 -0
  81. package/src/scss/themes/mini.scss +76 -0
  82. package/src/scss/themes/palette.scss +85 -0
  83. package/src/scss/themes/ring.scss +57 -0
  84. package/src/scss/themes/sketch.scss +172 -0
  85. package/src/scss/themes/vscode.scss +93 -0
  86. package/src/scss/themes/xd.scss +88 -0
  87. package/src/util/Blender.js +29 -0
  88. package/src/util/Canvas.js +128 -0
  89. package/src/util/Color.js +27 -0
  90. package/src/util/ColorNames.js +14 -0
  91. package/src/util/Dom.js +361 -0
  92. package/src/util/Event.js +30 -0
  93. package/src/util/EventMachin.js +349 -0
  94. package/src/util/GL.js +8 -0
  95. package/src/util/HueColor.js +49 -0
  96. package/src/util/ImageFilter.js +9 -0
  97. package/src/util/ImageLoader.js +137 -0
  98. package/src/util/Kmeans.js +237 -0
  99. package/src/util/Matrix.js +196 -0
  100. package/src/util/State.js +42 -0
  101. package/src/util/blend/composite.js +124 -0
  102. package/src/util/blend/non-separable.js +118 -0
  103. package/src/util/blend/separable.js +76 -0
  104. package/src/util/filter/StackBlur.js +517 -0
  105. package/src/util/filter/functions.js +829 -0
  106. package/src/util/filter/image/crop.js +16 -0
  107. package/src/util/filter/image/flipH.js +23 -0
  108. package/src/util/filter/image/flipV.js +25 -0
  109. package/src/util/filter/image/histogram.js +45 -0
  110. package/src/util/filter/image/index.js +18 -0
  111. package/src/util/filter/image/resize.js +18 -0
  112. package/src/util/filter/image/rotate.js +39 -0
  113. package/src/util/filter/image/rotateDegree.js +53 -0
  114. package/src/util/filter/index.js +11 -0
  115. package/src/util/filter/matrix/blur.js +12 -0
  116. package/src/util/filter/matrix/emboss.js +17 -0
  117. package/src/util/filter/matrix/gaussian-blur-5x.js +17 -0
  118. package/src/util/filter/matrix/gaussian-blur.js +16 -0
  119. package/src/util/filter/matrix/grayscale2.js +16 -0
  120. package/src/util/filter/matrix/index.js +58 -0
  121. package/src/util/filter/matrix/kirsch-horizontal.js +13 -0
  122. package/src/util/filter/matrix/kirsch-vertical.js +13 -0
  123. package/src/util/filter/matrix/laplacian-5x.js +16 -0
  124. package/src/util/filter/matrix/laplacian.js +14 -0
  125. package/src/util/filter/matrix/motion-blur-2.js +18 -0
  126. package/src/util/filter/matrix/motion-blur-3.js +19 -0
  127. package/src/util/filter/matrix/motion-blur.js +18 -0
  128. package/src/util/filter/matrix/negative.js +16 -0
  129. package/src/util/filter/matrix/normal.js +11 -0
  130. package/src/util/filter/matrix/sepia2.js +16 -0
  131. package/src/util/filter/matrix/sharpen.js +14 -0
  132. package/src/util/filter/matrix/sobel-horizontal.js +11 -0
  133. package/src/util/filter/matrix/sobel-vertical.js +11 -0
  134. package/src/util/filter/matrix/stack-blur.js +15 -0
  135. package/src/util/filter/matrix/transparency.js +16 -0
  136. package/src/util/filter/matrix/unsharp-masking.js +16 -0
  137. package/src/util/filter/multi/index.js +9 -0
  138. package/src/util/filter/multi/kirsch.js +7 -0
  139. package/src/util/filter/multi/sobel.js +7 -0
  140. package/src/util/filter/multi/vintage.js +7 -0
  141. package/src/util/filter/pixel/bitonal.js +24 -0
  142. package/src/util/filter/pixel/brightness.js +19 -0
  143. package/src/util/filter/pixel/brownie.js +23 -0
  144. package/src/util/filter/pixel/clip.js +21 -0
  145. package/src/util/filter/pixel/contrast.js +18 -0
  146. package/src/util/filter/pixel/gamma.js +13 -0
  147. package/src/util/filter/pixel/gradient.js +52 -0
  148. package/src/util/filter/pixel/grayscale.js +27 -0
  149. package/src/util/filter/pixel/hue.js +28 -0
  150. package/src/util/filter/pixel/index.js +52 -0
  151. package/src/util/filter/pixel/invert.js +16 -0
  152. package/src/util/filter/pixel/kodachrome.js +23 -0
  153. package/src/util/filter/pixel/matrix.js +28 -0
  154. package/src/util/filter/pixel/noise.js +24 -0
  155. package/src/util/filter/pixel/opacity.js +14 -0
  156. package/src/util/filter/pixel/polaroid.js +23 -0
  157. package/src/util/filter/pixel/saturation.js +30 -0
  158. package/src/util/filter/pixel/sepia.js +28 -0
  159. package/src/util/filter/pixel/shade.js +21 -0
  160. package/src/util/filter/pixel/shift.js +23 -0
  161. package/src/util/filter/pixel/solarize.js +23 -0
  162. package/src/util/filter/pixel/technicolor.js +23 -0
  163. package/src/util/filter/pixel/threshold-color.js +35 -0
  164. package/src/util/filter/pixel/threshold.js +7 -0
  165. package/src/util/filter/pixel/tint.js +20 -0
  166. package/src/util/functions/formatter.js +99 -0
  167. package/src/util/functions/fromCMYK.js +17 -0
  168. package/src/util/functions/fromHSL.js +52 -0
  169. package/src/util/functions/fromHSV.js +64 -0
  170. package/src/util/functions/fromLAB.js +99 -0
  171. package/src/util/functions/fromRGB.js +220 -0
  172. package/src/util/functions/fromYCrCb.js +16 -0
  173. package/src/util/functions/func.js +194 -0
  174. package/src/util/functions/image.js +145 -0
  175. package/src/util/functions/math.js +56 -0
  176. package/src/util/functions/mixin.js +164 -0
  177. package/src/util/functions/parser.js +294 -0
  178. package/src/util/gl/filter/index.js +9 -0
  179. package/src/util/gl/filter/matrix/blur.js +9 -0
  180. package/src/util/gl/filter/matrix/emboss.js +17 -0
  181. package/src/util/gl/filter/matrix/gaussian-blur-5x.js +15 -0
  182. package/src/util/gl/filter/matrix/gaussian-blur.js +19 -0
  183. package/src/util/gl/filter/matrix/grayscale2.js +13 -0
  184. package/src/util/gl/filter/matrix/index.js +55 -0
  185. package/src/util/gl/filter/matrix/kirsch-horizontal.js +11 -0
  186. package/src/util/gl/filter/matrix/kirsch-vertical.js +11 -0
  187. package/src/util/gl/filter/matrix/laplacian-5x.js +13 -0
  188. package/src/util/gl/filter/matrix/laplacian.js +11 -0
  189. package/src/util/gl/filter/matrix/motion-blur-2.js +17 -0
  190. package/src/util/gl/filter/matrix/motion-blur-3.js +17 -0
  191. package/src/util/gl/filter/matrix/motion-blur.js +17 -0
  192. package/src/util/gl/filter/matrix/negative.js +13 -0
  193. package/src/util/gl/filter/matrix/normal.js +8 -0
  194. package/src/util/gl/filter/matrix/sepia2.js +13 -0
  195. package/src/util/gl/filter/matrix/sharpen.js +11 -0
  196. package/src/util/gl/filter/matrix/sobel-horizontal.js +11 -0
  197. package/src/util/gl/filter/matrix/sobel-vertical.js +11 -0
  198. package/src/util/gl/filter/matrix/transparency.js +13 -0
  199. package/src/util/gl/filter/matrix/unsharp-masking.js +14 -0
  200. package/src/util/gl/filter/multi/index.js +9 -0
  201. package/src/util/gl/filter/multi/kirsch.js +7 -0
  202. package/src/util/gl/filter/multi/sobel.js +7 -0
  203. package/src/util/gl/filter/multi/vintage.js +7 -0
  204. package/src/util/gl/filter/pixel/bitonal.js +22 -0
  205. package/src/util/gl/filter/pixel/brightness.js +14 -0
  206. package/src/util/gl/filter/pixel/brownie.js +11 -0
  207. package/src/util/gl/filter/pixel/chaos.js +20 -0
  208. package/src/util/gl/filter/pixel/clip.js +20 -0
  209. package/src/util/gl/filter/pixel/contrast.js +16 -0
  210. package/src/util/gl/filter/pixel/gamma.js +16 -0
  211. package/src/util/gl/filter/pixel/gradient.js +59 -0
  212. package/src/util/gl/filter/pixel/grayscale.js +22 -0
  213. package/src/util/gl/filter/pixel/hue.js +19 -0
  214. package/src/util/gl/filter/pixel/index.js +54 -0
  215. package/src/util/gl/filter/pixel/invert.js +18 -0
  216. package/src/util/gl/filter/pixel/kodachrome.js +11 -0
  217. package/src/util/gl/filter/pixel/matrix.js +29 -0
  218. package/src/util/gl/filter/pixel/noise.js +18 -0
  219. package/src/util/gl/filter/pixel/opacity.js +17 -0
  220. package/src/util/gl/filter/pixel/polaroid.js +11 -0
  221. package/src/util/gl/filter/pixel/saturation.js +20 -0
  222. package/src/util/gl/filter/pixel/sepia.js +19 -0
  223. package/src/util/gl/filter/pixel/shade.js +20 -0
  224. package/src/util/gl/filter/pixel/shift.js +11 -0
  225. package/src/util/gl/filter/pixel/solarize.js +21 -0
  226. package/src/util/gl/filter/pixel/technicolor.js +11 -0
  227. package/src/util/gl/filter/pixel/threshold-color.js +15 -0
  228. package/src/util/gl/filter/pixel/threshold.js +7 -0
  229. package/src/util/gl/filter/pixel/tint.js +25 -0
  230. package/src/util/gl/filter/util.js +185 -0
  231. package/src/util/gl/functions.js +158 -0
  232. package/src/util/gl/index.js +543 -0
  233. package/src/util/index.js +17 -0
  234. package/stand.html +975 -0
  235. package/test/util.Blend.spec.js +15 -0
  236. package/test/util.Color.spec.js +200 -0
  237. package/test/util.Filter.spec.js +12 -0
  238. package/test/util.ImageFilter.spec.js +16 -0
@@ -0,0 +1,543 @@
1
+ import GLFilter from './filter/index'
2
+ import {makeFragmentShaderSource, makeVertexShaderSource} from './filter/util'
3
+
4
+
5
+
6
+ let TEXTURE_INDEX = 0
7
+
8
+ class GLCanvas {
9
+
10
+ constructor (opt = {
11
+ width : '400px',
12
+ height: '300px'
13
+ }) {
14
+ this.img = opt.img;
15
+ this.width = parseFloat(this.img.width || opt.width || '400px');
16
+ this.height = parseFloat(this.img.height || opt.height || '300px');
17
+ this.init()
18
+
19
+
20
+ }
21
+
22
+ resize () {
23
+ this.canvas.width = this.width;
24
+ this.canvas.height = this.height;
25
+ this.canvas.style.width = this.width + 'px';
26
+ this.canvas.style.height = this.height + 'px';
27
+
28
+ this.viewport()
29
+ }
30
+
31
+ /* Canvas 비우기, 비울 때 색 지정하기 */
32
+ clear (r = 0, g = 0, b = 0, a = 0) {
33
+ const gl = this.gl
34
+
35
+ gl.clearColor(r, g, b, a);
36
+ gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
37
+ }
38
+
39
+ /* viewport 설정, 기본적으로 canvas 의 크기로 고정 */
40
+ viewport (x, y, width, height) {
41
+ const gl = this.gl
42
+
43
+ gl.viewport(x || 0, y || 0, width || gl.canvas.width, height || gl.canvas.height);
44
+ }
45
+
46
+ // canvas 초기화
47
+ // gl context 구하기
48
+
49
+ initCanvas (vertexSource, fragmentSource) {
50
+ this.canvas = document.createElement('canvas')
51
+
52
+ this.gl = this.canvas.getContext('webgl2');
53
+
54
+ if (!this.gl) {
55
+ throw new Error("you need webgl2 support")
56
+ }
57
+
58
+ // program 생성
59
+ this.program = this.createProgram (vertexSource, fragmentSource)
60
+
61
+
62
+ // this.clear()
63
+ this.resize()
64
+
65
+ // buffer 설정
66
+ this.initBuffer()
67
+ }
68
+
69
+ draw (primitiveType = 'TRIANGLES', offset = 0, count = 6) {
70
+ const gl = this.gl
71
+
72
+ gl.drawArrays(gl[primitiveType], offset, count)
73
+ }
74
+
75
+ triangles (offset = 0, count = 6) {
76
+ this.draw('TRIANGLES', offset, count)
77
+ }
78
+
79
+ uniform2f(...args) {
80
+
81
+ var key = args.shift()
82
+
83
+ this.gl.uniform2f(...[this.locations[key], ...args])
84
+ }
85
+
86
+ uniform1f(...args) {
87
+
88
+ var key = args.shift()
89
+
90
+ this.gl.uniform1f(...[this.locations[key], ...args])
91
+ }
92
+
93
+ uniform1fv(...args) {
94
+
95
+ var key = args.shift()
96
+
97
+ this.gl.uniform1fv(...[this.locations[key], ...args])
98
+ }
99
+
100
+ uniform1i(...args) {
101
+
102
+ var key = args.shift()
103
+
104
+ this.gl.uniform1i(...[this.locations[key], ...args])
105
+ }
106
+
107
+ useProgram () {
108
+ const gl = this.gl
109
+
110
+ gl.useProgram(this.program);
111
+
112
+ }
113
+
114
+ bindBuffer(key, data, drawType = 'STATIC_DRAW') {
115
+ const gl = this.gl
116
+
117
+ if (!this.buffers[key]) {
118
+ this.buffers[key] = gl.createBuffer()
119
+ }
120
+
121
+ gl.bindBuffer(gl.ARRAY_BUFFER, this.buffers[key])
122
+
123
+ if (data) {
124
+ gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(data), gl[drawType]);
125
+ }
126
+ }
127
+
128
+ enable (key) {
129
+ const gl = this.gl
130
+
131
+ // array attribute 를 활성화 시킴
132
+ gl.enableVertexAttribArray(this.locations[key])
133
+ }
134
+
135
+ location (key, type = "attribute") {
136
+ if (type === 'attribute') {
137
+ this.locations[key] = this.gl.getAttribLocation(this.program, key)
138
+ } else if (type === 'uniform') {
139
+ this.locations[key] = this.gl.getUniformLocation(this.program, key)
140
+ }
141
+ }
142
+
143
+ a (key) {
144
+ return this.location(key)
145
+ }
146
+
147
+ u (key) {
148
+ return this.location(key, "uniform")
149
+ }
150
+
151
+ pointer (key, type = 'FLOAT', size = 2, normalize = false, stride = 0, offset = 0) {
152
+ const gl = this.gl
153
+
154
+ gl.vertexAttribPointer(this.locations[key], size, gl[type], normalize, stride, offset);
155
+ }
156
+
157
+ bufferData (data = []) {
158
+ const gl = this.gl ;
159
+ gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(data), gl.STATIC_DRAW);
160
+ }
161
+
162
+ isPowerOf2(value) {
163
+ return (value & (value - 1)) == 0;
164
+ }
165
+
166
+
167
+ bindTexture (key, img = undefined, mipLevel = 0, internalFormat = 'RGBA', srcFormat = 'RGBA', srcType = 'UNSIGNED_BYTE') {
168
+ const gl = this.gl
169
+
170
+ if (arguments.length == 1) {
171
+ gl.bindTexture(gl.TEXTURE_2D, this.textures[key])
172
+ return;
173
+ }
174
+
175
+ if ( !this.textures[key] ) {
176
+ this.textures[key] = gl.createTexture()
177
+ }
178
+
179
+ this.textureIndex[key] = TEXTURE_INDEX++;
180
+ // this.activeTexture(key)
181
+ gl.bindTexture(gl.TEXTURE_2D, this.textures[key]);
182
+
183
+ this.setTextureParameter()
184
+
185
+ gl.texImage2D(gl.TEXTURE_2D, mipLevel, gl[internalFormat], gl[srcFormat], gl[srcType], img.newImage || img);
186
+ }
187
+
188
+ bindColorTexture (key, data, width = 256, height = 1, mipLevel = 0, internalFormat = 'RGBA', srcFormat = 'RGBA', srcType = 'UNSIGNED_BYTE') {
189
+ const gl = this.gl
190
+
191
+ if ( !this.textures[key] ) {
192
+ this.textures[key] = gl.createTexture()
193
+ }
194
+
195
+ this.textureIndex[key] = TEXTURE_INDEX++;
196
+ gl.bindTexture(gl.TEXTURE_2D, this.textures[key]);
197
+
198
+ this.setTextureParameter()
199
+
200
+ gl.texImage2D(gl.TEXTURE_2D, mipLevel, gl[internalFormat], width, height, 0, gl[srcFormat], gl[srcType], new Uint8Array(data));
201
+
202
+ }
203
+
204
+ bindEmptyTexture (key, width, height, mipLevel = 0, internalFormat = 'RGBA', srcFormat = 'RGBA', srcType = 'UNSIGNED_BYTE') {
205
+ const gl = this.gl
206
+
207
+ if ( !this.textures[key] ) {
208
+ this.textures[key] = gl.createTexture()
209
+ }
210
+
211
+ this.textureIndex[key] = TEXTURE_INDEX++;
212
+ gl.bindTexture(gl.TEXTURE_2D, this.textures[key]);
213
+
214
+ this.setTextureParameter()
215
+
216
+ var border = 0;
217
+ var data = null;
218
+
219
+ gl.texImage2D(gl.TEXTURE_2D, mipLevel, gl[internalFormat], width, height, border, gl[srcFormat], gl[srcType], data);
220
+
221
+ }
222
+
223
+ setTextureParameter() {
224
+ const gl = this.gl
225
+
226
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
227
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
228
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
229
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
230
+ }
231
+
232
+ bindFrameBufferWithTexture(key, textureKey, width, height) {
233
+ this.bindEmptyTexture(textureKey, width, height);
234
+ this.bindFrameBuffer(key, textureKey)
235
+ }
236
+
237
+ enumToString(value) {
238
+ const gl = this.gl
239
+
240
+ if (value === 0) {
241
+ return "NONE";
242
+ }
243
+ for (let key in gl) {
244
+ if (gl[key] === value) {
245
+ return key;
246
+ }
247
+ }
248
+ return "0x" + value.toString(16);
249
+ }
250
+
251
+ bindFrameBuffer (key, textureKey = null) {
252
+ const gl = this.gl
253
+
254
+ if (arguments.length === 1) {
255
+ gl.bindFramebuffer(gl.FRAMEBUFFER, key == null ? null : this.framebuffers[key]);
256
+ return;
257
+ }
258
+
259
+ if (!this.framebuffers[key]) {
260
+ // 프레임버퍼 생성하기
261
+ this.framebuffers[key] = gl.createFramebuffer()
262
+ }
263
+
264
+ gl.bindFramebuffer(gl.FRAMEBUFFER, this.framebuffers[key]);
265
+
266
+ // framebuffer 에 texture2d 연결
267
+ const mipLevel = 0
268
+ var attachmentPoint = gl.COLOR_ATTACHMENT0; // framebuffer 를 attachmentPoint 에 연결한다.
269
+ // framebuffer 는 데이타를 가지고 있지 않고 연결 고리만 가지고 있다.
270
+ gl.framebufferTexture2D(gl.FRAMEBUFFER, attachmentPoint, gl.TEXTURE_2D, this.textures[textureKey], mipLevel);
271
+
272
+ // framebuffer 상태 체크 하기
273
+ // framebuffer 를 더 이상 할당 못할 수도 있음.
274
+ const status = gl.checkFramebufferStatus(gl.FRAMEBUFFER);
275
+
276
+ // console.log(this.enumToString(attachmentPoint), this.enumToString(status), key, this.textures[textureKey]);
277
+
278
+ if (status !== gl.FRAMEBUFFER_COMPLETE) {
279
+ return;
280
+ }
281
+
282
+ }
283
+
284
+ bindVA () {
285
+ const gl = this.gl
286
+
287
+ if(!this.vao) {
288
+ this.vao = gl.createVertexArray();
289
+ }
290
+
291
+ gl.bindVertexArray(this.vao);
292
+ }
293
+
294
+ bindAttr (key, data, drawType = 'STATIC_DRAW', size = 2) {
295
+ // 버퍼를 만들고 데이타를 연결한다.
296
+ this.bindBuffer(key, data, drawType)
297
+
298
+ //array 변수를 사용할 수 있도록 활성화 시킨다.
299
+ this.enable(key)
300
+
301
+ // 포인터를 지정한다.
302
+ // array 변수가 어떻게 iteration 될지 지정한다. size 는 한번에 연산될 요소 개수
303
+ // size 가 2 라고 했을 때 2개씩 하나의 iteration 에 들어간다.
304
+ // 즉, (x, y) 가 한번에 들어감
305
+ this.pointer(key, 'FLOAT', size)
306
+ }
307
+
308
+ /*
309
+ shader 에서 사용하는 Attribute, Uniform 변수 설정
310
+ 변수 설정을 간소화 할 필요도 있을 듯 하다.
311
+ */
312
+ initBuffer () {
313
+
314
+ const { width, height } = this.canvas
315
+
316
+ // console.log(width, height)
317
+
318
+ // 선언된 변수 location 지정 하기
319
+ // location 을 지정해야 GLSL 에서 해당 변수와 연결할 수 있다. 언제?
320
+ this.a("a_position");
321
+ this.a("a_texCoord")
322
+ this.u("u_resolution")
323
+ this.u("u_image")
324
+ this.u("u_flipY")
325
+
326
+ this.u("u_kernelSelect");
327
+ this.u("u_filterIndex");
328
+
329
+ this.u("u_kernel9[0]");
330
+ this.u("u_kernel9Weight");
331
+ this.u("u_kernel25[0]");
332
+ this.u("u_kernel25Weight");
333
+ this.u("u_kernel49[0]");
334
+ this.u("u_kernel49Weight");
335
+ this.u("u_kernel81[0]");
336
+ this.u("u_kernel81Weight");
337
+
338
+ this.bindVA()
339
+
340
+ // 단순 변수를 초기화 하고
341
+ this.bindAttr("a_position", [
342
+ 0, 0,
343
+ width, 0,
344
+ 0, height,
345
+ 0, height,
346
+ width, 0,
347
+ width, height,
348
+ ], 'STATIC_DRAW', 2 /* components for iteration */);
349
+
350
+ // 변수에 데이타를 연결할다.
351
+ this.bindAttr("a_texCoord", [
352
+ 0.0, 0.0,
353
+ 1.0, 0.0,
354
+ 0.0, 1.0,
355
+
356
+ 0.0, 1.0,
357
+ 1.0, 0.0,
358
+ 1.0, 1.0
359
+ ], 'STATIC_DRAW', 2 /* components for iteration */);
360
+
361
+
362
+ // texture 는 img 로 할 수도 있고
363
+ this.bindTexture("u_image", this.img);
364
+
365
+ // 비어있는 texture 도 만들 수 있다.
366
+ // 객체로 제어할까?
367
+ // texture 를 framebuffer 로 바로 대응시킨다.
368
+ // 이후 framebuffer 가 변경되면 img_texture 가 바뀐다.
369
+ this.bindFrameBufferWithTexture("frame_buffer_0", "img_texture_0", width, height)
370
+ this.bindFrameBufferWithTexture("frame_buffer_1", "img_texture_1", width, height)
371
+ }
372
+
373
+ activeTexture(index = 0) {
374
+ const gl = this.gl
375
+
376
+ gl.activeTexture(gl.TEXTURE0 + index);
377
+ }
378
+
379
+ drawFilter () {
380
+ const gl = this.gl
381
+
382
+ this.resize()
383
+ this.clear()
384
+
385
+ this.useProgram()
386
+
387
+ this.bindVA()
388
+
389
+
390
+ this.activeTexture(0)
391
+ this.bindTexture('u_image')
392
+
393
+ this.uniform1i("u_image", 0)
394
+ this.uniform1f("u_flipY", 1);
395
+
396
+ const { width, height } = gl.canvas
397
+
398
+ this.eachFilter((f, index) => {
399
+
400
+ this.bindFrameBuffer(`frame_buffer_${index % 2}`);
401
+ this.uniform2f("u_resolution", width, height);
402
+ this.viewport(0, 0, width, height);
403
+
404
+ this.effectFilter(f);
405
+
406
+ // 다음 드로잉을 위해 방금 렌더링 한 텍스처를 사용합니다.
407
+ this.bindTexture(`img_texture_${index % 2}`)
408
+ })
409
+
410
+ this.uniform1f("u_flipY", -1);
411
+ this.bindFrameBuffer(null);
412
+ this.uniform2f("u_resolution", width, height);
413
+ this.viewport(0, 0, width, height);
414
+
415
+ // clear 가 있는 이유는?
416
+ this.clear()
417
+
418
+ this.effectFilter("normal");
419
+ }
420
+
421
+ effectFilter (filterFunction) {
422
+
423
+ if (typeof filterFunction == 'string') {
424
+ filterFunction = (GLFilter[filterFunction] || GLFilter.normal).call(GLFilter)
425
+ }
426
+
427
+ if (filterFunction.type == 'convolution') {
428
+ this.uniform1f("u_kernelSelect", filterFunction.length)
429
+ this.uniform1f("u_filterIndex", -1.0)
430
+ this.uniform1fv(`u_kernel${filterFunction.length}[0]`, filterFunction.content)
431
+ this.uniform1f(`u_kernel${filterFunction.length}Weight`, this.computeKernelWeight(filterFunction.content))
432
+ } else {
433
+
434
+ this.uniform1f("u_kernelSelect", -1.0)
435
+ this.uniform1f("u_filterIndex", filterFunction.index)
436
+ }
437
+
438
+
439
+ this.triangles(0 /* 시작 지점 */, 6 /* 좌표(vertex, 꼭지점) 개수 */) ; // 총 6개를 도는데 , triangles 니깐 3개씩 묶어서 2번 돈다.
440
+ }
441
+
442
+ computeKernelWeight(kernel) {
443
+ var weight = kernel.reduce(function(prev, curr) {
444
+ return prev + curr;
445
+ });
446
+ return weight <= 0 ? 1 : weight;
447
+ }
448
+
449
+ createProgram (vertexSource, fragmentSource) {
450
+
451
+ const gl = this.gl
452
+
453
+ var program = gl.createProgram()
454
+
455
+ this.vertexShader = this.createVertexShader (vertexSource)
456
+ this.fragmentShader = this.createFragmentShader(fragmentSource)
457
+
458
+ // console.log(fragmentSource)
459
+
460
+
461
+ gl.attachShader(program, this.vertexShader )
462
+ gl.attachShader(program, this.fragmentShader)
463
+
464
+ gl.linkProgram(program)
465
+
466
+ var success = gl.getProgramParameter(program, gl.LINK_STATUS);
467
+ if (success) {
468
+
469
+ return program
470
+ }
471
+
472
+ console.error(gl.getProgramInfoLog(program));
473
+ gl.deleteProgram(program)
474
+ }
475
+
476
+ createShader (type, source) {
477
+ const gl = this.gl
478
+
479
+ var shader = gl.createShader(type);
480
+ gl.shaderSource(shader, source);
481
+ gl.compileShader(shader);
482
+
483
+ var success = gl.getShaderParameter(shader, gl.COMPILE_STATUS);
484
+
485
+ if (success) {
486
+ return shader;
487
+ }
488
+
489
+ console.error(gl.getShaderInfoLog(shader));
490
+ gl.deleteShader(shader)
491
+ }
492
+
493
+ createVertexShader (vertexSource) {
494
+ const gl = this.gl
495
+
496
+ return this.createShader(gl.VERTEX_SHADER, vertexSource);
497
+ }
498
+
499
+ createFragmentShader (fragmentSource) {
500
+ const gl = this.gl
501
+
502
+ return this.createShader(gl.FRAGMENT_SHADER, fragmentSource);
503
+ }
504
+
505
+ eachFilter (callback) {
506
+ this.filterList.forEach(callback)
507
+ }
508
+
509
+ init () {
510
+ this.locations = {}
511
+ this.buffers = {}
512
+ this.framebuffers = {}
513
+ this.textures = {}
514
+ this.textureIndex = {}
515
+ this.hasTexParameter = {}
516
+ }
517
+
518
+ destroy () {
519
+ const gl = this.gl
520
+
521
+ this.init()
522
+
523
+ gl.deleteProgram(this.program)
524
+ }
525
+
526
+ filter(filterList, doneCallback) {
527
+
528
+ this.filterList = filterList
529
+
530
+ this.initCanvas(makeVertexShaderSource(), makeFragmentShaderSource(this.filterList))
531
+
532
+ this.drawFilter()
533
+
534
+ if (typeof doneCallback == 'function') {
535
+
536
+ doneCallback(this)
537
+ }
538
+ }
539
+ }
540
+
541
+ export default {
542
+ GLCanvas
543
+ }
@@ -0,0 +1,17 @@
1
+ import Color from './Color'
2
+ import HueColor from './HueColor'
3
+ import ColorNames from './ColorNames'
4
+ import ImageFilter from './ImageFilter'
5
+ import GL from './GL'
6
+ import Canvas from './Canvas'
7
+ import ImageLoader from './ImageLoader'
8
+
9
+ export default {
10
+ Color,
11
+ HueColor,
12
+ ColorNames,
13
+ ImageFilter,
14
+ GL,
15
+ Canvas,
16
+ ImageLoader
17
+ }