MCPcopy Create free account
hub / github.com/Moddable-OpenSource/moddable / readJPEG

Method readJPEG

tools/image2cs.js:181–228  ·  view source on GitHub ↗
(path, frames)

Source from the content-addressed store, hash-verified

179 }
180 readGIF(buffer) @ "Tool_readGIF";
181 readJPEG(path, frames) {
182 var data = this.readFileBuffer(path);
183 var jpeg = new JPEG(data, { pixelFormat:Bitmap.RGB565LE });
184 var jpegWidth = jpeg.width;
185 var jpegHeight = jpeg.height;
186 if (this.quality == 0) {
187 this.format = Bitmap.JPEG;
188 frames.push(data);
189 frames.width = jpegWidth;
190 frames.height = jpegHeight;
191 return;
192 }
193 var padWidth = this.pad(jpegWidth);
194 var padHeight = this.pad(jpegHeight);
195 var copy, width, height;
196 switch (this.rotation) {
197 case 0:
198 copy = this.copy0;
199 width = padWidth;
200 height = padHeight;
201 break;
202 case 90:
203 copy = this.copy90;
204 width = padHeight;
205 height = padWidth;
206 break;
207 case 180:
208 copy = this.copy180;
209 width = padWidth;
210 height = padHeight;
211 break;
212 case 270:
213 copy = this.copy270;
214 width = padHeight;
215 height = padWidth;
216 break;
217 }
218 var pixels = new Uint16Array(width * height);
219 for (;;) {
220 var block = jpeg.read();
221 if (!block)
222 break;
223 copy.call(this, block, pixels, padWidth, padHeight);
224 }
225 frames.push(this.compress(pixels.buffer, width, height));
226 frames.width = width;
227 frames.height = height;
228 }
229 readPNG(path, frames) {
230 var data = this.readFileBuffer(path);
231 var png = new PNG(data);

Callers 1

runMethod · 0.80

Calls 4

readMethod · 0.95
pushMethod · 0.45
padMethod · 0.45
compressMethod · 0.45

Tested by

no test coverage detected