From 35f76632454a0267da7f90bd3edce5078e9cdff4 Mon Sep 17 00:00:00 2001 From: Yegor Pelykh Date: Mon, 15 Jul 2024 23:32:55 +0300 Subject: [PATCH] style: Comments of encoding functions have been normalized --- src/formats/bmp-encoder.ts | 13 +------------ src/formats/decoder.ts | 20 ++++++++++---------- src/formats/encoder.ts | 7 ++++--- src/formats/gif-encoder.ts | 1 - src/formats/jpeg-encoder.ts | 3 ++- src/formats/png-encoder.ts | 4 +--- src/formats/tiff-encoder.ts | 1 + src/formats/win-encoder.ts | 2 +- src/index.ts | 4 ++++ 9 files changed, 24 insertions(+), 31 deletions(-) diff --git a/src/formats/bmp-encoder.ts b/src/formats/bmp-encoder.ts index 37f70d7..dd97672 100644 --- a/src/formats/bmp-encoder.ts +++ b/src/formats/bmp-encoder.ts @@ -30,18 +30,7 @@ export class BmpEncoder implements Encoder { /** * Encodes an image into BMP format. * @param {EncoderEncodeOptions} opt - The options for encoding. - * @param {Object} opt.image - The image to encode. - * @param {number} opt.image.numChannels - The number of channels in the image. - * @param {Object} [opt.image.palette] - The palette of the image, if any. - * @param {Format} opt.image.format - The format of the image. - * @param {boolean} opt.image.isHdrFormat - Indicates if the image is in HDR format. - * @param {boolean} opt.image.hasPalette - Indicates if the image has a palette. - * @param {number} opt.image.bitsPerChannel - The number of bits per channel in the image. - * @param {number} opt.image.rowStride - The row stride of the image. - * @param {number} opt.image.width - The width of the image. - * @param {number} opt.image.height - The height of the image. - * @param {number} opt.image.byteLength - The byte length of the image. - * @param {ArrayBuffer} [opt.image.buffer] - The buffer of the image, if any. + * @param {MemoryImage} opt.image - The image to encode. * @returns {Uint8Array} The encoded BMP image. */ public encode(opt: EncoderEncodeOptions): Uint8Array { diff --git a/src/formats/decoder.ts b/src/formats/decoder.ts index 9865618..8d1b38e 100644 --- a/src/formats/decoder.ts +++ b/src/formats/decoder.ts @@ -5,12 +5,17 @@ import { DecodeInfo } from './decode-info.js'; import { ImageFormat } from './image-format.js'; /** - * Object interface for specifying Decoder.decode parameters. + * Options for decoding image data. */ export interface DecoderDecodeOptions { - /** The byte array of the image data to decode. */ + /** + * The byte array containing the image data to be decoded. + */ bytes: Uint8Array; - /** The index of the frame to decode, if the image is animated. */ + + /** + * Optional. The index of the specific frame to decode. + */ frameIndex?: number; } @@ -60,14 +65,9 @@ export interface Decoder { startDecode(bytes: Uint8Array): DecodeInfo | undefined; /** - * Decode the file and extract a single image from it. If the file is - * animated, and **frameIndex** is specified, that particular frame will be decoded. - * Otherwise if the image is animated and **frameIndex** is undefined, the returned - * MemoryImage will include all frames. If there was a problem decoding the - * MemoryImage, undefined will be returned. - * @param {DecoderDecodeOptions} opt - The options for decoding, including the byte array and optional frame index. + * Decodes the provided image file. + * @param {DecodeImageOptions} opt - The options for decoding, including the byte array and optional frame index. * @param {Uint8Array} opt.bytes - The byte array of the image data to decode. - * @param {number} [opt.frameIndex] - The optional index of the frame to decode. * @returns {MemoryImage | undefined} The decoded MemoryImage, or undefined if decoding fails. */ decode(opt: DecoderDecodeOptions): MemoryImage | undefined; diff --git a/src/formats/encoder.ts b/src/formats/encoder.ts index 09b4076..f59fc8c 100644 --- a/src/formats/encoder.ts +++ b/src/formats/encoder.ts @@ -3,7 +3,7 @@ import { MemoryImage } from '../image/image.js'; /** - * Object interface for specifying Encoder.encode parameters. + * Options for encoding an image. */ export interface EncoderEncodeOptions { /** @@ -12,8 +12,9 @@ export interface EncoderEncodeOptions { image: MemoryImage; /** - * If true, only a single frame of the image will be encoded. - * If false or undefined, all frames of the image will be encoded if the encoder supports animation. + * Flag to indicate if only a single frame should be encoded. + * - true: Encode only the first frame. + * - false or undefined: Encode all frames if the encoder supports animation. */ singleFrame?: boolean; diff --git a/src/formats/gif-encoder.ts b/src/formats/gif-encoder.ts index 69efd87..39e2f49 100644 --- a/src/formats/gif-encoder.ts +++ b/src/formats/gif-encoder.ts @@ -693,7 +693,6 @@ export class GifEncoder implements Encoder { /** * Encode a single frame image. - * * @param {EncoderEncodeOptions} opt - The options for encoding. * @param {MemoryImage} opt.image - The image to encode. * @param {boolean} [opt.singleFrame] - Optional flag to encode a single frame. diff --git a/src/formats/jpeg-encoder.ts b/src/formats/jpeg-encoder.ts index cec0654..e9df613 100644 --- a/src/formats/jpeg-encoder.ts +++ b/src/formats/jpeg-encoder.ts @@ -929,7 +929,8 @@ export class JpegEncoder implements Encoder { /** * Encodes the image using the JPEG format. * @param {JpegEncoderEncodeOptions} opt - The options for encoding. - * @param {Image} opt.image - The image to encode. + * @param {MemoryImage} opt.image - The image to encode. + * @param {boolean} [opt.skipExif] - Whether to skip embedding EXIF metadata (optional). * @param {JpegChroma} [opt.chroma] - The chroma subsampling format (optional). * @returns {Uint8Array} The encoded JPEG image as a Uint8Array. */ diff --git a/src/formats/png-encoder.ts b/src/formats/png-encoder.ts index 6274280..41335d2 100644 --- a/src/formats/png-encoder.ts +++ b/src/formats/png-encoder.ts @@ -668,11 +668,9 @@ export class PngEncoder implements Encoder { /** * Encode **image** to the PNG format. - * * @param {EncoderEncodeOptions} opt - The encoding options. * @param {MemoryImage} opt.image - The image to encode. - * @param {boolean} [opt.singleFrame] - Whether to encode a single frame (default is false). - * + * @param {boolean} [opt.singleFrame] - Optional flag to encode a single frame. * @returns {Uint8Array} The encoded PNG bytes. */ public encode(opt: EncoderEncodeOptions): Uint8Array { diff --git a/src/formats/tiff-encoder.ts b/src/formats/tiff-encoder.ts index 7040d5f..395edc0 100644 --- a/src/formats/tiff-encoder.ts +++ b/src/formats/tiff-encoder.ts @@ -50,6 +50,7 @@ export class TiffEncoder implements Encoder { * Encodes the given image to the TIFF format. * @param {EncoderEncodeOptions} opt - The encoding options. * @param {MemoryImage} opt.image - The image to encode. + * @param {boolean} [opt.skipExif] - Whether to skip embedding EXIF metadata (optional). * @returns {Uint8Array} The encoded image. */ public encode(opt: EncoderEncodeOptions): Uint8Array { diff --git a/src/formats/win-encoder.ts b/src/formats/win-encoder.ts index f58f574..47a2187 100644 --- a/src/formats/win-encoder.ts +++ b/src/formats/win-encoder.ts @@ -62,7 +62,7 @@ export abstract class WinEncoder implements Encoder { * Encodes the given image into a Uint8Array. * @param {EncoderEncodeOptions} opt - The encoding options. * @param {MemoryImage} opt.image - The image to encode. - * @param {boolean} [opt.singleFrame] - Whether to encode a single frame. + * @param {boolean} [opt.singleFrame] - Optional flag to encode a single frame. * @returns {Uint8Array} The encoded data. */ public encode(opt: EncoderEncodeOptions): Uint8Array { diff --git a/src/index.ts b/src/index.ts index 69e025b..7550271 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1009,6 +1009,7 @@ export function decodeNamedImage( * @param {EncodeImageByMimeTypeOptions} opt - Options for encoding the image. * @param {MemoryImage} opt.image - The MemoryImage to encode. * @param {string} opt.mimeType - The MIME type to encode the image to. + * @param {boolean} [opt.skipExif=false] - Whether to skip embedding EXIF metadata (default is false). * @returns {Uint8Array | undefined} The encoded image bytes or undefined if no encoder is found. */ export function encodeImageByMimeType( @@ -1033,6 +1034,7 @@ export function encodeImageByMimeType( * @param {EncodeNamedImageOptions} opt - Options for encoding the image. * @param {MemoryImage} opt.image - The MemoryImage to encode. * @param {string} opt.name - The filename extension to determine the format. + * @param {boolean} [opt.skipExif=false] - Whether to skip embedding EXIF metadata (default is false). * @returns {Uint8Array | undefined} The encoded image bytes or undefined if no encoder is found. */ export function encodeNamedImage( @@ -1068,6 +1070,7 @@ export function decodeJpg(opt: DecodeOptions): MemoryImage | undefined { * * @param {EncodeJpgOptions} opt - Options for encoding the image. * @param {MemoryImage} opt.image - The MemoryImage to encode. + * @param {boolean} [opt.skipExif=false] - Whether to skip embedding EXIF metadata (default is false). * @param {number} [opt.quality] - The quality of the JPEG encoding (default is 100). * @param {JpegChroma} [opt.chroma] - The chroma subsampling (default is yuv444). * @returns {Uint8Array} The encoded image bytes. @@ -1297,6 +1300,7 @@ export function decodeTiff( * @param {EncodeAnimatedOptions} opt - Options for encoding the image. * @param {MemoryImage} opt.image - The MemoryImage to encode. * @param {boolean} [opt.singleFrame=false] - Whether to encode a single frame (default is false). + * @param {boolean} [opt.skipExif=false] - Whether to skip embedding EXIF metadata (default is false). * @returns {Uint8Array} The encoded image bytes. */ export function encodeTiff(opt: EncodeAnimatedOptions): Uint8Array {