Develop and Download Open Source Software

Browse Subversion Repository

Diff of /trunk/src/js/jgame.js

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 27 by tsugehara, Tue Feb 26 07:26:45 2013 UTC revision 28 by tsugehara, Tue Feb 26 13:42:17 2013 UTC
# Line 1755  var GameRenderer = (function (_super) { Line 1755  var GameRenderer = (function (_super) {
1755              }              }
1756          }          }
1757          if(hasUpdate) {          if(hasUpdate) {
1758              if(this.filter && this.filter.has()) {              if(this.filter) {
1759                  var imageData = this.bc.getImageData(0, 0, this.game.width, this.game.height);                  var imageData = this.bc.getImageData(0, 0, this.game.width, this.game.height);
1760                  this.filter.filter(imageData);                  this.filter.filter(imageData);
1761                  this.fc.putImageData(imageData, 0, 0);                  this.fc.putImageData(imageData, 0, 0);
# Line 1826  var BufferedRenderer = (function (_super Line 1826  var BufferedRenderer = (function (_super
1826      BufferedRenderer.prototype.clear = function () {      BufferedRenderer.prototype.clear = function () {
1827          this.c.clearRect(0, 0, this.size.width, this.size.height);          this.c.clearRect(0, 0, this.size.width, this.size.height);
1828      };      };
1829      BufferedRenderer.prototype.createSprite = function (area, distArea) {      BufferedRenderer.prototype.createImage = function (area, distArea) {
1830          if(!area) {          if(!area) {
1831              area = new Area(0, 0, this.size.width, this.size.height);              area = new Area(0, 0, this.size.width, this.size.height);
1832          }          }
# Line 1836  var BufferedRenderer = (function (_super Line 1836  var BufferedRenderer = (function (_super
1836          var canvas = window.createCanvas(area.width, area.height);          var canvas = window.createCanvas(area.width, area.height);
1837          var context = canvas.getContext("2d");          var context = canvas.getContext("2d");
1838          context.drawImage(this.buffer, area.x, area.y, area.width, area.height, distArea.x, distArea.y, distArea.width, distArea.height);          context.drawImage(this.buffer, area.x, area.y, area.width, area.height, distArea.x, distArea.y, distArea.width, distArea.height);
1839          return new Sprite(area.width, area.height, canvas);          if(this.filter) {
1840                this.applyFilter(context, area);
1841            }
1842            return canvas;
1843        };
1844        BufferedRenderer.prototype.createSprite = function (area, distArea) {
1845            return new Sprite(area.width, area.height, this.createImage(area, distArea));
1846        };
1847        BufferedRenderer.prototype.applyFilter = function (c, size) {
1848            var imageData = c.getImageData(0, 0, size.width, size.height);
1849            this.filter.filter(imageData);
1850            c.putImageData(imageData, 0, 0);
1851      };      };
1852      BufferedRenderer.prototype.renderUnit = function (entity) {      BufferedRenderer.prototype.renderUnit = function (entity) {
1853          var area = new Area(0, 0, entity.width, entity.height);          var area = new Area(0, 0, entity.width, entity.height);
# Line 2358  var ImageFilter; Line 2369  var ImageFilter;
2369              }              }
2370              return src;              return src;
2371          };          };
2372            Filter.prototype.applyMatrix = function (pixels, matrix, amount) {
2373                var data = pixels.data, imgWidth = pixels.width, height = pixels.height;
2374                var datalen = data.length;
2375                var bufferedData = new Array(data.length);
2376                for(var i = 0; i < datalen; i++) {
2377                    bufferedData[i] = data[i];
2378                }
2379                var matrixSize = Math.sqrt(matrix.length);
2380                var kernelRadius = Math.floor(matrixSize / 2);
2381                for(var i = 1; i < imgWidth - 1; i++) {
2382                    for(var j = 1; j < height - 1; j++) {
2383                        var sumR = 0, sumG = 0, sumB = 0;
2384                        for(var h = 0; h < matrixSize; h++) {
2385                            for(var w = 0; w < matrixSize; w++) {
2386                                var i2 = ((i + w - kernelRadius) + (j + h - kernelRadius) * imgWidth) << 2;
2387                                sumR += bufferedData[i2] * matrix[w + h * matrixSize];
2388                                sumG += bufferedData[i2 + 1] * matrix[w + h * matrixSize];
2389                                sumB += bufferedData[i2 + 2] * matrix[w + h * matrixSize];
2390                            }
2391                        }
2392                        var ref = (i + j * imgWidth) << 2;
2393                        var r = data[ref], g = data[ref + 1], b = data[ref + 2];
2394                        data[ref] = this.findColorDifference(amount, sumR, r);
2395                        data[ref + 1] = this.findColorDifference(amount, sumG, g);
2396                        data[ref + 2] = this.findColorDifference(amount, sumB, b);
2397                    }
2398                }
2399                return (pixels);
2400            };
2401            Filter.prototype.checkRGBBoundary = function (val) {
2402                if(val < 0) {
2403                    return 0;
2404                } else if(val > 255) {
2405                    return 255;
2406                }
2407                return val;
2408            };
2409          return Filter;          return Filter;
2410      })();      })();
2411      ImageFilter.Filter = Filter;          ImageFilter.Filter = Filter;    
# Line 2426  var ImageFilter; Line 2474  var ImageFilter;
2474          return TintFilter;          return TintFilter;
2475      })(Filter);      })(Filter);
2476      ImageFilter.TintFilter = TintFilter;          ImageFilter.TintFilter = TintFilter;    
2477        var EdgesFilter = (function (_super) {
2478            __extends(EdgesFilter, _super);
2479            function EdgesFilter(amount) {
2480                    _super.call(this);
2481                this.opt.amount = amount;
2482            }
2483            EdgesFilter.prototype.filter = function (pixels) {
2484                var matrix = [
2485                    0,
2486                    1,
2487                    0,
2488                    1,
2489                    -4,
2490                    1,
2491                    0,
2492                    1,
2493                    0
2494                ];
2495                this.applyMatrix(pixels, matrix, this.getOption("amount", 1));
2496            };
2497            return EdgesFilter;
2498        })(Filter);
2499        ImageFilter.EdgesFilter = EdgesFilter;    
2500        var EmbossFilter = (function (_super) {
2501            __extends(EmbossFilter, _super);
2502            function EmbossFilter(amount) {
2503                    _super.call(this);
2504                this.opt.amount = amount;
2505            }
2506            EmbossFilter.prototype.filter = function (pixels) {
2507                var matrix = [
2508                    -2,
2509                    -1,
2510                    0,
2511                    -1,
2512                    1,
2513                    1,
2514                    0,
2515                    1,
2516                    2
2517                ];
2518                this.applyMatrix(pixels, matrix, this.getOption("amount", 0.5));
2519            };
2520            return EmbossFilter;
2521        })(Filter);
2522        ImageFilter.EmbossFilter = EmbossFilter;    
2523        var SharpenFilter = (function (_super) {
2524            __extends(SharpenFilter, _super);
2525            function SharpenFilter(amount) {
2526                    _super.call(this);
2527                this.opt.amount = amount;
2528            }
2529            SharpenFilter.prototype.filter = function (pixels) {
2530                var matrix = [
2531                    -1,
2532                    -1,
2533                    -1,
2534                    -1,
2535                    9,
2536                    -1,
2537                    -1,
2538                    -1,
2539                    -1
2540                ];
2541                this.applyMatrix(pixels, matrix, this.getOption("amount", 0.5));
2542            };
2543            return SharpenFilter;
2544        })(Filter);
2545        ImageFilter.SharpenFilter = SharpenFilter;    
2546        var MatrixFilter = (function (_super) {
2547            __extends(MatrixFilter, _super);
2548            function MatrixFilter(amount, matrix) {
2549                    _super.call(this);
2550                this.opt.amount = amount;
2551                this.opt.matrix = matrix;
2552            }
2553            MatrixFilter.prototype.filter = function (pixels) {
2554                var matrix = this.getOption("matrix", [
2555                    0.111,
2556                    0.111,
2557                    0.111,
2558                    0.111,
2559                    0.111,
2560                    0.111,
2561                    0.111,
2562                    0.111,
2563                    0.111
2564                ]);
2565                this.applyMatrix(pixels, matrix, this.getOption("amount", 0.5));
2566            };
2567            return MatrixFilter;
2568        })(Filter);
2569        ImageFilter.MatrixFilter = MatrixFilter;    
2570        var BlurFilter = (function (_super) {
2571            __extends(BlurFilter, _super);
2572            function BlurFilter(amount) {
2573                    _super.call(this);
2574                this.opt.amount = amount;
2575            }
2576            BlurFilter.prototype.filter = function (pixels) {
2577                var width = pixels.width;
2578                var width4 = width << 2;
2579                var height = pixels.height;
2580                var amount = this.getOption("amount", 2);
2581                if(pixels) {
2582                    var data = pixels.data;
2583                    var q;
2584                    if(amount < 0.0) {
2585                        amount = 0.0;
2586                    }
2587                    if(amount >= 2.5) {
2588                        q = 0.98711 * amount - 0.9633;
2589                    } else if(amount >= 0.5) {
2590                        q = 3.97156 - 4.14554 * Math.sqrt(1.0 - 0.26891 * amount);
2591                    } else {
2592                        q = 2 * amount * (3.97156 - 4.14554 * Math.sqrt(1.0 - 0.26891 * 0.5));
2593                    }
2594                    var qq = q * q;
2595                    var qqq = qq * q;
2596                    var b0 = 1.57825 + (2.44413 * q) + (1.4281 * qq) + (0.422205 * qqq);
2597                    var b1 = ((2.44413 * q) + (2.85619 * qq) + (1.26661 * qqq)) / b0;
2598                    var b2 = (-((1.4281 * qq) + (1.26661 * qqq))) / b0;
2599                    var b3 = (0.422205 * qqq) / b0;
2600                    var bigB = 1.0 - (b1 + b2 + b3);
2601                    for(var c = 0; c < 3; c++) {
2602                        for(var y = 0; y < height; y++) {
2603                            var index = y * width4 + c;
2604                            var indexLast = y * width4 + ((width - 1) << 2) + c;
2605                            var pixel = data[index];
2606                            var ppixel = pixel;
2607                            var pppixel = ppixel;
2608                            var ppppixel = pppixel;
2609                            for(; index <= indexLast; index += 4) {
2610                                pixel = bigB * data[index] + b1 * ppixel + b2 * pppixel + b3 * ppppixel;
2611                                data[index] = pixel;
2612                                ppppixel = pppixel;
2613                                pppixel = ppixel;
2614                                ppixel = pixel;
2615                            }
2616                            index = y * width4 + ((width - 1) << 2) + c;
2617                            indexLast = y * width4 + c;
2618                            pixel = data[index];
2619                            ppixel = pixel;
2620                            pppixel = ppixel;
2621                            ppppixel = pppixel;
2622                            for(; index >= indexLast; index -= 4) {
2623                                pixel = bigB * data[index] + b1 * ppixel + b2 * pppixel + b3 * ppppixel;
2624                                data[index] = pixel;
2625                                ppppixel = pppixel;
2626                                pppixel = ppixel;
2627                                ppixel = pixel;
2628                            }
2629                        }
2630                    }
2631                    for(var c = 0; c < 3; c++) {
2632                        for(var x = 0; x < width; x++) {
2633                            var index = (x << 2) + c;
2634                            var indexLast = (height - 1) * width4 + (x << 2) + c;
2635                            var pixel = data[index];
2636                            var ppixel = pixel;
2637                            var pppixel = ppixel;
2638                            var ppppixel = pppixel;
2639                            for(; index <= indexLast; index += width4) {
2640                                pixel = bigB * data[index] + b1 * ppixel + b2 * pppixel + b3 * ppppixel;
2641                                data[index] = pixel;
2642                                ppppixel = pppixel;
2643                                pppixel = ppixel;
2644                                ppixel = pixel;
2645                            }
2646                            index = (height - 1) * width4 + (x << 2) + c;
2647                            indexLast = (x << 2) + c;
2648                            pixel = data[index];
2649                            ppixel = pixel;
2650                            pppixel = ppixel;
2651                            ppppixel = pppixel;
2652                            for(; index >= indexLast; index -= width4) {
2653                                pixel = bigB * data[index] + b1 * ppixel + b2 * pppixel + b3 * ppppixel;
2654                                data[index] = pixel;
2655                                ppppixel = pppixel;
2656                                pppixel = ppixel;
2657                                ppixel = pixel;
2658                            }
2659                        }
2660                    }
2661                }
2662            };
2663            return BlurFilter;
2664        })(Filter);
2665        ImageFilter.BlurFilter = BlurFilter;    
2666        var MosaicFilter = (function (_super) {
2667            __extends(MosaicFilter, _super);
2668            function MosaicFilter(size, opacity) {
2669                    _super.call(this);
2670                this.opt.size = size;
2671                this.opt.opacity = opacity;
2672            }
2673            MosaicFilter.prototype.filter = function (pixels) {
2674                var opacity = this.getOption("opacity", 1);
2675                var size = this.getOption("size", 5);
2676                var width = pixels.width;
2677                for(var i = 0, data = pixels.data, length = data.length; i < length >> 2; i++) {
2678                    var index = i << 2;
2679                    var r = data[index], g = data[index + 1], b = data[index + 2];
2680                    var pos = index >> 2;
2681                    var stepY = Math.floor(pos / width);
2682                    var stepY1 = stepY % size;
2683                    var stepX = pos - (stepY * width);
2684                    var stepX1 = stepX % size;
2685                    if(stepY1) {
2686                        pos -= stepY1 * width;
2687                    }
2688                    if(stepX1) {
2689                        pos -= stepX1;
2690                    }
2691                    pos = pos << 2;
2692                    data[index] = this.findColorDifference(opacity, data[pos], r);
2693                    data[index + 1] = this.findColorDifference(opacity, data[pos + 1], g);
2694                    data[index + 2] = this.findColorDifference(opacity, data[pos + 2], b);
2695                }
2696            };
2697            return MosaicFilter;
2698        })(Filter);
2699        ImageFilter.MosaicFilter = MosaicFilter;    
2700        (function (NoiseType) {
2701            NoiseType._map = [];
2702            NoiseType._map[0] = "Mono";
2703            NoiseType.Mono = 0;
2704            NoiseType._map[1] = "Color";
2705            NoiseType.Color = 1;
2706        })(ImageFilter.NoiseType || (ImageFilter.NoiseType = {}));
2707        var NoiseType = ImageFilter.NoiseType;
2708        var NoiseFilter = (function (_super) {
2709            __extends(NoiseFilter, _super);
2710            function NoiseFilter(amount, type) {
2711                    _super.call(this);
2712                this.opt.amount = amount;
2713                this.opt.type = type;
2714            }
2715            NoiseFilter.prototype.filter = function (pixels) {
2716                var amount = this.getOption("amount", 30);
2717                var type = this.getOption("type", NoiseType.Mono);
2718                for(var i = 0, data = pixels.data, length = data.length; i < length >> 2; i++) {
2719                    var index = i << 2;
2720                    var r = data[index], g = data[index + 1], b = data[index + 2];
2721                    if(type == NoiseType.Mono) {
2722                        var val = Math.floor((amount >> 1) - (Math.random() * amount));
2723                        data[index] = this.checkRGBBoundary(r + val);
2724                        data[index + 1] = this.checkRGBBoundary(g + val);
2725                        data[index + 2] = this.checkRGBBoundary(b + val);
2726                    } else {
2727                        data[index] = this.checkRGBBoundary(r + Math.floor((amount >> 1) - (Math.random() * amount)));
2728                        data[index + 1] = this.checkRGBBoundary(g + Math.floor((amount >> 1) - (Math.random() * amount)));
2729                        data[index + 2] = this.checkRGBBoundary(b + Math.floor((amount >> 1) - (Math.random() * amount)));
2730                    }
2731                }
2732            };
2733            return NoiseFilter;
2734        })(Filter);
2735        ImageFilter.NoiseFilter = NoiseFilter;    
2736        var PosterizeFilter = (function (_super) {
2737            __extends(PosterizeFilter, _super);
2738            function PosterizeFilter(amount, opacity) {
2739                    _super.call(this);
2740                this.opt.opacity = opacity;
2741                this.opt.amount = amount;
2742            }
2743            PosterizeFilter.prototype.filter = function (pixels) {
2744                var opacity = this.getOption("opacity", 1);
2745                var amount = this.getOption("amount", 2);
2746                var areas = 256 / amount;
2747                var values = 255 / (amount - 1);
2748                for(var i = 0, data = pixels.data, length = data.length; i < length >> 2; i++) {
2749                    var index = i << 2;
2750                    var r = data[index], g = data[index + 1], b = data[index + 2];
2751                    data[index] = this.findColorDifference(opacity, Math.round(values * Math.round(r / areas)), r);
2752                    data[index + 1] = this.findColorDifference(opacity, Math.round(values * Math.round(g / areas)), g);
2753                    data[index + 2] = this.findColorDifference(opacity, Math.round(values * Math.round(b / areas)), b);
2754                }
2755            };
2756            return PosterizeFilter;
2757        })(Filter);
2758        ImageFilter.PosterizeFilter = PosterizeFilter;    
2759  })(ImageFilter || (ImageFilter = {}));  })(ImageFilter || (ImageFilter = {}));
2760  var Action = (function () {  var Action = (function () {
2761      function Action(param) {      function Action(param) {

Legend:
Removed from v.27  
changed lines
  Added in v.28

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26