| 1915 | var self = this; |
| 1916 | |
| 1917 | function isBlankFrame(frame, _pixTolerance, _frameTolerance) { |
| 1918 | var localCanvas = document.createElement('canvas'); |
| 1919 | localCanvas.width = canvas.width; |
| 1920 | localCanvas.height = canvas.height; |
| 1921 | var context2d = localCanvas.getContext('2d'); |
| 1922 | |
| 1923 | var sampleColor = { |
| 1924 | r: 0, |
| 1925 | g: 0, |
| 1926 | b: 0 |
| 1927 | }; |
| 1928 | var maxColorDifference = Math.sqrt( |
| 1929 | Math.pow(255, 2) + |
| 1930 | Math.pow(255, 2) + |
| 1931 | Math.pow(255, 2) |
| 1932 | ); |
| 1933 | var pixTolerance = _pixTolerance && _pixTolerance >= 0 && _pixTolerance <= 1 ? _pixTolerance : 0; |
| 1934 | var frameTolerance = _frameTolerance && _frameTolerance >= 0 && _frameTolerance <= 1 ? _frameTolerance : 0; |
| 1935 | |
| 1936 | var matchPixCount, endPixCheck, maxPixCount; |
| 1937 | |
| 1938 | var image = new Image(); |
| 1939 | image.src = frame.image; |
| 1940 | context2d.drawImage(image, 0, 0, canvas.width, canvas.height); |
| 1941 | var imageData = context2d.getImageData(0, 0, canvas.width, canvas.height); |
| 1942 | matchPixCount = 0; |
| 1943 | endPixCheck = imageData.data.length; |
| 1944 | maxPixCount = imageData.data.length / 4; |
| 1945 | |
| 1946 | for (var pix = 0; pix < endPixCheck; pix += 4) { |
| 1947 | var currentColor = { |
| 1948 | r: imageData.data[pix], |
| 1949 | g: imageData.data[pix + 1], |
| 1950 | b: imageData.data[pix + 2] |
| 1951 | }; |
| 1952 | var colorDifference = Math.sqrt( |
| 1953 | Math.pow(currentColor.r - sampleColor.r, 2) + |
| 1954 | Math.pow(currentColor.g - sampleColor.g, 2) + |
| 1955 | Math.pow(currentColor.b - sampleColor.b, 2) |
| 1956 | ); |
| 1957 | // difference in color it is difference in color vectors (r1,g1,b1) <=> (r2,g2,b2) |
| 1958 | if (colorDifference <= maxColorDifference * pixTolerance) { |
| 1959 | matchPixCount++; |
| 1960 | } |
| 1961 | } |
| 1962 | |
| 1963 | if (maxPixCount - matchPixCount <= maxPixCount * frameTolerance) { |
| 1964 | return false; |
| 1965 | } else { |
| 1966 | return true; |
| 1967 | } |
| 1968 | } |
| 1969 | |
| 1970 | function dropBlackFrames(_frames, _framesToCheck, _pixTolerance, _frameTolerance) { |
| 1971 | var localCanvas = document.createElement('canvas'); |