-
-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
174 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
// Copyright Dirk Lemstra https://github.com/dlemstra/magick-wasm. | ||
// Licensed under the Apache License, Version 2.0. | ||
|
||
import { ByteArray } from "./byte-array"; | ||
import { ColorSpace } from "./enums/color-space"; | ||
import { CompressionMethod } from "./enums/compression-method"; | ||
import { Density } from "./types/density"; | ||
import { Interlace } from "./enums/interlace"; | ||
import { MagickFormat } from "./enums/magick-format"; | ||
import { MagickReadSettings } from "./settings/magick-read-settings"; | ||
import { MagickImage } from "./magick-image"; | ||
|
||
export interface IMagickImageInfo { | ||
/** | ||
* Gets the color space of the image | ||
*/ | ||
readonly colorSpace: ColorSpace; | ||
|
||
/** | ||
* Gets the compression method of the image | ||
*/ | ||
readonly compression: CompressionMethod; | ||
|
||
/** | ||
* Gets the density of the image | ||
*/ | ||
readonly density: Density; | ||
|
||
/** | ||
* Gets the format of the image. | ||
*/ | ||
readonly format: MagickFormat; | ||
|
||
/** | ||
* Gets the height of the image. | ||
*/ | ||
readonly height: number; | ||
|
||
/** | ||
* Gets the type of interlacing. | ||
*/ | ||
readonly interlace: Interlace; | ||
|
||
/** | ||
* Gets the JPEG/MIFF/PNG compression level. | ||
*/ | ||
readonly quality: number; | ||
|
||
/** | ||
* Gets the width of the image. | ||
*/ | ||
readonly width: number; | ||
|
||
/** | ||
* Read single image frame. | ||
* @param array - The byte array to read the image from. | ||
* @param settings - The settings to use when reading the image. | ||
*/ | ||
read(array: ByteArray, settings?: MagickReadSettings): void | ||
} | ||
|
||
export class MagickImageInfo implements IMagickImageInfo { | ||
private _colorSpace: ColorSpace = ColorSpace.Undefined; | ||
private _compression: CompressionMethod = CompressionMethod.Undefined; | ||
private _density: Density = new Density(0, 0); | ||
private _format: MagickFormat = MagickFormat.Unknown; | ||
private _height: number = 0; | ||
private _interlace: Interlace = Interlace.Undefined; | ||
private _quality: number = 0; | ||
private _width: number = 0; | ||
|
||
get colorSpace(): ColorSpace { | ||
return this._colorSpace; | ||
} | ||
|
||
get compression(): CompressionMethod { | ||
return this._compression; | ||
} | ||
|
||
get density(): Density { | ||
return this._density; | ||
} | ||
|
||
get format(): MagickFormat { | ||
return this._format; | ||
} | ||
|
||
get height(): number { | ||
return this._height; | ||
} | ||
|
||
get interlace(): Interlace { | ||
return this._interlace; | ||
} | ||
|
||
get quality(): number { | ||
return this._quality; | ||
} | ||
|
||
get width(): number { | ||
return this._width; | ||
} | ||
|
||
constructor() { | ||
} | ||
|
||
read(array: ByteArray, settings?: MagickReadSettings): void { | ||
MagickImage._create(image => { | ||
image.ping(array, settings); | ||
|
||
this._colorSpace = image.colorSpace; | ||
this._compression = image.compression; | ||
this._density = image.density; | ||
this._format = image.format; | ||
this._height = image.height; | ||
this._interlace = image.interlace; | ||
this._quality = image.quality; | ||
this._width = image.width; | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright Dirk Lemstra https://github.com/dlemstra/magick-wasm. | ||
// Licensed under the Apache License, Version 2.0. | ||
|
||
import { ColorSpace } from '@src/enums/color-space'; | ||
import { CompressionMethod } from '@src/enums/compression-method'; | ||
import { DensityUnit } from '@src/enums/density-unit'; | ||
import { Interlace } from '@src/enums/interlace'; | ||
import { MagickFormat } from '@src/enums/magick-format'; | ||
import { MagickImageInfo } from '@src/magick-image-info'; | ||
|
||
describe('MagickImageInfo#constructor', () => { | ||
it('should create empty uninitialized instance', () => { | ||
const magickImageInfo = new MagickImageInfo(); | ||
expect(magickImageInfo.colorSpace).toBe(ColorSpace.Undefined); | ||
expect(magickImageInfo.compression).toBe(CompressionMethod.Undefined); | ||
expect(magickImageInfo.density.x).toBe(0); | ||
expect(magickImageInfo.density.y).toBe(0); | ||
expect(magickImageInfo.density.units).toBe(DensityUnit.Undefined); | ||
expect(magickImageInfo.format).toBe(MagickFormat.Unknown); | ||
expect(magickImageInfo.height).toBe(0); | ||
expect(magickImageInfo.interlace).toBe(Interlace.Undefined); | ||
expect(magickImageInfo.quality).toBe(0); | ||
expect(magickImageInfo.width).toBe(0); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright Dirk Lemstra https://github.com/dlemstra/magick-wasm. | ||
// Licensed under the Apache License, Version 2.0. | ||
|
||
import { ColorSpace } from '@src/enums/color-space'; | ||
import { CompressionMethod } from '@src/enums/compression-method'; | ||
import { DensityUnit } from '@src/enums/density-unit'; | ||
import { Interlace } from '@src/enums/interlace'; | ||
import { MagickFormat } from '@src/enums/magick-format'; | ||
import { MagickImageInfo } from '@src/magick-image-info'; | ||
import { TestImages } from '@test/test-images'; | ||
|
||
describe('MagickImageInfo#constructor', () => { | ||
it('should read the information of the image', () => { | ||
const magickImageInfo = new MagickImageInfo(); | ||
magickImageInfo.read(TestImages.fujiFilmFinePixS1ProJpg.data); | ||
expect(magickImageInfo.colorSpace).toBe(ColorSpace.sRGB); | ||
expect(magickImageInfo.compression).toBe(CompressionMethod.JPEG); | ||
expect(magickImageInfo.density.x).toBe(300); | ||
expect(magickImageInfo.density.y).toBe(300); | ||
expect(magickImageInfo.density.units).toBe(DensityUnit.PixelsPerInch); | ||
expect(magickImageInfo.format).toBe(MagickFormat.Jpeg); | ||
expect(magickImageInfo.height).toBe(400); | ||
expect(magickImageInfo.interlace).toBe(Interlace.NoInterlace); | ||
expect(magickImageInfo.quality).toBe(70); | ||
expect(magickImageInfo.width).toBe(600); | ||
}); | ||
}); |