Skip to content

Commit

Permalink
feat: EXIF reading support for WebP
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor-pelykh committed May 17, 2024
1 parent 09265ad commit e029885
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
5 changes: 1 addition & 4 deletions src/formats/webp-decoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,7 @@ export class WebPDecoder implements Decoder {
input: InputBuffer<Uint8Array>,
webp: WebPInfoInternal
): boolean {
let found = false;
while (!input.isEOS && !found) {
while (!input.isEOS) {
const tag = input.readString(4);
const size = input.readUint32();
// For odd sized chunks, there's a 1 byte padding at the end.
Expand All @@ -122,13 +121,11 @@ export class WebPDecoder implements Decoder {
webp.vp8Position = input.position;
webp.vp8Size = size;
webp.format = WebPFormat.lossy;
found = true;
break;
case 'VP8L':
webp.vp8Position = input.position;
webp.vp8Size = size;
webp.format = WebPFormat.lossless;
found = true;
break;
case 'ALPH':
webp.alphaData = new InputBuffer<Uint8Array>({
Expand Down
9 changes: 9 additions & 0 deletions src/formats/webp/vp8.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import { VP8TopSamples } from './vp8-top-samples.js';
import { WebPAlpha } from './webp-alpha.js';
import { WebPInfo } from './webp-info.js';
import { WebPInfoInternal } from './webp-info-internal.js';
import { StringUtils } from '../../common/string-utils.js';
import { ExifData } from '../../exif/exif-data.js';

/**
* WebP lossy format
Expand Down Expand Up @@ -1712,6 +1714,13 @@ export class VP8 {
return undefined;
}

if (this._webp.exifData.length > 0) {
const input = new InputBuffer({
buffer: StringUtils.getCodePoints(this._webp.exifData),
});
this._output.exifData = ExifData.fromInputBuffer(input);
}

return this._output;
}

Expand Down
9 changes: 9 additions & 0 deletions src/formats/webp/vp8l.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import { WebPFormat } from './webp-format.js';
import { HuffmanTree } from './webp-huffman-tree.js';
import { HuffmanTreeGroup } from './webp-huffman-tree-group.js';
import { WebPInfo } from './webp-info.js';
import { StringUtils } from '../../common/string-utils.js';
import { ExifData } from '../../exif/exif-data.js';

export class VP8L {
private _lastPixel: number = 0;
Expand Down Expand Up @@ -905,6 +907,13 @@ export class VP8L {
return undefined;
}

if (this._webp.exifData.length > 0) {
const input = new InputBuffer({
buffer: StringUtils.getCodePoints(this._webp.exifData),
});
this._image.exifData = ExifData.fromInputBuffer(input);
}

return this._image;
}

Expand Down

0 comments on commit e029885

Please sign in to comment.