Skip to content

Commit da621a6

Browse files
authored
put the beutifier'd code in the right place
1 parent ff2ae37 commit da621a6

File tree

1 file changed

+22
-18
lines changed

1 file changed

+22
-18
lines changed

src/handlers/aperturePicture.ts

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,20 @@ import {
88
QuantizeSettings
99
} from "@imagemagick/magick-wasm";
1010

11-
import type { FileData, FileFormat, FormatHandler } from "../FormatHandler.ts";
11+
import type {
12+
FileData,
13+
FileFormat,
14+
FormatHandler
15+
} from "../FormatHandler.ts";
1216
import CommonFormats from "src/CommonFormats.ts";
1317

1418
class aperturePictureHandler implements FormatHandler {
1519
public name: string = "aperturePicture";
16-
public supportedFormats?: FileFormat[];
20+
public supportedFormats ? : FileFormat[];
1721
public ready: boolean = false;
1822

1923
async init() {
20-
this.supportedFormats = [
21-
{
24+
this.supportedFormats = [{
2225
name: "Aperture Picture Format",
2326
format: "apf",
2427
extension: "apf",
@@ -30,9 +33,9 @@ class aperturePictureHandler implements FormatHandler {
3033
lossless: true,
3134
},
3235
CommonFormats.BMP.builder("bmp")
33-
.allowFrom(true)
34-
.allowTo(true)
35-
.markLossless(),
36+
.allowFrom(true)
37+
.allowTo(true)
38+
.markLossless(),
3639
];
3740
this.ready = true;
3841
}
@@ -41,7 +44,7 @@ class aperturePictureHandler implements FormatHandler {
4144
inputFiles: FileData[],
4245
inputFormat: FileFormat,
4346
outputFormat: FileFormat,
44-
): Promise<FileData[]> {
47+
): Promise < FileData[] > {
4548
const outputFiles: FileData[] = [];
4649
const decoder = new TextDecoder();
4750

@@ -62,11 +65,10 @@ class aperturePictureHandler implements FormatHandler {
6265
name: file.name.replace(/\.[^/.]+$/, "") + ".bmp",
6366
});
6467
}
65-
}
66-
else if (inputFormat.internal === "bmp") { // we're just throwing science at the wall to see what sticks
68+
} else if (inputFormat.internal === "bmp") { // we're just throwing science at the wall to see what sticks
6769
const w = 320,
6870
h = 200;
69-
await initializeImageMagick();
71+
await initializeImageMagick();
7072

7173
const inputMagickFormat = inputFormat.internal as MagickFormat;
7274
const inputSettings = new MagickReadSettings();
@@ -83,7 +85,7 @@ class aperturePictureHandler implements FormatHandler {
8385
image.grayscale();
8486
const Qset = new QuantizeSettings();
8587
Qset.colors = 2;
86-
Qset.ditherMethod = 1;
88+
Qset.ditherMethod = 1;
8789
image.quantize(Qset); // 2 colors
8890

8991
let data = null // now you're thinking with NoneTypes
@@ -159,9 +161,9 @@ function APFarray(data: Uint8Array): Uint8Array {
159161
for (const b of data) {
160162
let uh = 0
161163
if (ispalflipped) {
162-
uh = (1-pal.indexOf(b))*255
164+
uh = (1 - pal.indexOf(b)) * 255
163165
} else {
164-
uh = pal.indexOf(b)*255
166+
uh = pal.indexOf(b) * 255
165167
}
166168
temparray.push(uh)
167169
if (temparray.length === 320) {
@@ -184,14 +186,17 @@ function encodeAPF(data: Uint8Array): String {
184186
for (const p of q_data) {
185187
if (p === currun) {
186188
runlen += 1
187-
if (runlen == 94) {runlen=0; apf += "~ "}
189+
if (runlen == 94) {
190+
runlen = 0;
191+
apf += "~ "
192+
}
188193
} else {
189-
apf += String.fromCharCode(runlen+32)
194+
apf += String.fromCharCode(runlen + 32)
190195
currun = p
191196
runlen = 1
192197
}
193198
}
194-
apf += String.fromCharCode(runlen+32);
199+
apf += String.fromCharCode(runlen + 32);
195200
return apf;
196201
}
197202

@@ -251,5 +256,4 @@ function bitmapTo1BitBMP( // note i initially used 24-bit BMPs but the filesize
251256

252257
export default aperturePictureHandler;
253258

254-
// logical next step is to go from BMP to APF but that is far beyond my level of knowledge. if anyone wants to take a crack at it the original basic code is in the old ARG Wiki at http://portalwiki.asshatter.org/index.php/Aperture_Image_Format.html#GW-Basic_AMF.2FAPF_Viewer_Source
255259
// if anyone wants to implement basic 1-bit colour, the .amf format is very simple, covered at http://portalwiki.asshatter.org/index.php/Aperture_Menu_Format.html. All you'd need to implement that is to check line 0 is APERTURE MENU FORMAT (c) 1985 and then line 1 is the colour info, comma separated. Idk what the RGB mappings for them are but the number meanings are at https://en.wikibooks.org/wiki/QBasic/Text_Output#Color_by_Number

0 commit comments

Comments
 (0)