Skip to content

Commit

Permalink
style: Comments of encoding functions have been normalized
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor-pelykh committed Jul 15, 2024
1 parent 661552d commit 35f7663
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 31 deletions.
13 changes: 1 addition & 12 deletions src/formats/bmp-encoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
20 changes: 10 additions & 10 deletions src/formats/decoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
Expand Down
7 changes: 4 additions & 3 deletions src/formats/encoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
/**
Expand All @@ -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;

Expand Down
1 change: 0 additions & 1 deletion src/formats/gif-encoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion src/formats/jpeg-encoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
4 changes: 1 addition & 3 deletions src/formats/png-encoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions src/formats/tiff-encoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/formats/win-encoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 35f7663

Please sign in to comment.