MCPcopy Index your code
hub / github.com/EmulatorJS/EmulatorJS / screenshot

Method screenshot

data/src/emulator.js:5931–6021  ·  view source on GitHub ↗
(callback, source, format, upscale)

Source from the content-addressed store, hash-verified

5929 }
5930
5931 screenshot(callback, source, format, upscale) {
5932 const imageFormat = format || this.getSettingValue("screenshotFormat") || this.capture.photo.format;
5933 const imageUpscale = upscale || parseInt(this.getSettingValue("screenshotUpscale") || this.capture.photo.upscale);
5934 const screenshotSource = source || this.getSettingValue("screenshotSource") || this.capture.photo.source;
5935 const videoRotation = parseInt(this.getSettingValue("videoRotation") || 0);
5936 const aspectRatio = this.gameManager.getVideoDimensions("aspect") || 1.333333;
5937 const gameWidth = this.gameManager.getVideoDimensions("width") || 256;
5938 const gameHeight = this.gameManager.getVideoDimensions("height") || 224;
5939 const videoTurned = (videoRotation === 1 || videoRotation === 3);
5940 let width = this.canvas.width;
5941 let height = this.canvas.height;
5942 let scaleHeight = imageUpscale;
5943 let scaleWidth = imageUpscale;
5944 let scale = 1;
5945
5946 if (screenshotSource === "retroarch") {
5947 if (width >= height) {
5948 width = height * aspectRatio;
5949 } else if (width < height) {
5950 height = width / aspectRatio;
5951 }
5952 this.gameManager.screenshot().then(screenshot => {
5953 const blob = new Blob([screenshot], { type: "image/png" });
5954 if (imageUpscale === 0) {
5955 callback(blob, "png");
5956 } else if (imageUpscale > 1) {
5957 scale = imageUpscale;
5958 const img = new Image();
5959 const screenshotUrl = URL.createObjectURL(blob);
5960 img.src = screenshotUrl;
5961 img.onload = () => {
5962 const canvas = document.createElement("canvas");
5963 canvas.width = width * scale;
5964 canvas.height = height * scale;
5965 const ctx = canvas.getContext("2d", { alpha: false });
5966 ctx.imageSmoothingEnabled = false;
5967 ctx.scale(scaleWidth, scaleHeight);
5968 ctx.drawImage(img, 0, 0, width, height);
5969 canvas.toBlob((blob) => {
5970 callback(blob, imageFormat);
5971 img.remove();
5972 URL.revokeObjectURL(screenshotUrl);
5973 canvas.remove();
5974 }, "image/" + imageFormat, 1);
5975 }
5976 }
5977 });
5978 } else if (screenshotSource === "canvas") {
5979 if (width >= height && !videoTurned) {
5980 width = height * aspectRatio;
5981 } else if (width < height && !videoTurned) {
5982 height = width / aspectRatio;
5983 } else if (width >= height && videoTurned) {
5984 width = height * (1/aspectRatio);
5985 } else if (width < height && videoTurned) {
5986 width = height / (1/aspectRatio);
5987 }
5988 if (imageUpscale === 0) {

Callers 2

createContextMenuMethod · 0.95
takeScreenshotMethod · 0.95

Calls 4

getSettingValueMethod · 0.95
getVideoDimensionsMethod · 0.80
createElementMethod · 0.80
removeMethod · 0.45

Tested by

no test coverage detected