| 227 | frames.height = height; |
| 228 | } |
| 229 | readPNG(path, frames) { |
| 230 | var data = this.readFileBuffer(path); |
| 231 | var png = new PNG(data); |
| 232 | let pngChannels = png.channels; |
| 233 | let pngDepth = png.depth; |
| 234 | let pngWidth = png.width; |
| 235 | let pngHeight = png.height; |
| 236 | if (((pngChannels != 3) && (pngChannels != 4)) || (pngDepth != 8)) |
| 237 | throw new Error("'" + pngPath + "': invalid PNG format!"); |
| 238 | if (this.quality == 0) { |
| 239 | this.format = Bitmap.PNG; |
| 240 | frames.push(data); |
| 241 | frames.width = pngWidth; |
| 242 | frames.height = pngHeight; |
| 243 | return; |
| 244 | } |
| 245 | let padWidth = this.pad(pngWidth); |
| 246 | let padHeight = this.pad(pngHeight); |
| 247 | let bufferRGBA32 = new Uint8Array(padWidth * padHeight * 4); |
| 248 | let offset = 0; |
| 249 | let y = 0; |
| 250 | while (y < pngHeight) { |
| 251 | let pngLine = png.read(); |
| 252 | let pngOffset = 0; |
| 253 | let x = 0; |
| 254 | while (x < pngWidth) { |
| 255 | bufferRGBA32[offset++] = pngLine[pngOffset++]; |
| 256 | bufferRGBA32[offset++] = pngLine[pngOffset++]; |
| 257 | bufferRGBA32[offset++] = pngLine[pngOffset++]; |
| 258 | bufferRGBA32[offset++] = (pngChannels == 4) ? pngLine[pngOffset++] : 255; |
| 259 | x++; |
| 260 | } |
| 261 | while (x < padWidth) { |
| 262 | bufferRGBA32[offset++] = 0; |
| 263 | bufferRGBA32[offset++] = 0; |
| 264 | bufferRGBA32[offset++] = 0; |
| 265 | bufferRGBA32[offset++] = 255; |
| 266 | x++; |
| 267 | } |
| 268 | y++; |
| 269 | } |
| 270 | while (y < padHeight) { |
| 271 | let x = 0; |
| 272 | while (x < padWidth) { |
| 273 | bufferRGBA32[offset++] = 0; |
| 274 | bufferRGBA32[offset++] = 0; |
| 275 | bufferRGBA32[offset++] = 0; |
| 276 | bufferRGBA32[offset++] = 255; |
| 277 | x++; |
| 278 | } |
| 279 | y++; |
| 280 | } |
| 281 | let bufferRGB565LE = new Uint16Array(padWidth * padHeight); |
| 282 | var colorConvert = new Convert(Bitmap.RGBA32, Bitmap.RGB565LE); |
| 283 | colorConvert.process(bufferRGBA32.buffer, bufferRGB565LE.buffer); |
| 284 | var pixels, width, height; |
| 285 | switch (this.rotation) { |
| 286 | case 0: |