@@ -176,7 +176,7 @@ public void run(
176
176
}
177
177
178
178
@ Test
179
- public void testCanParseWebpWithAlpha () throws IOException {
179
+ public void testCanParseLosslessWebpWithAlpha () throws IOException {
180
180
byte [] data =
181
181
new byte [] {
182
182
0x52 ,
@@ -194,12 +194,12 @@ public void testCanParseWebpWithAlpha() throws IOException {
194
194
0x56 ,
195
195
0x50 ,
196
196
0x38 ,
197
- 0x4c ,
197
+ 0x4c , // Lossless
198
198
0x30 ,
199
199
0x50 ,
200
200
0x00 ,
201
201
0x00 ,
202
- 0x2f ,
202
+ 0x2f , // Flags
203
203
(byte ) 0xef ,
204
204
(byte ) 0x80 ,
205
205
0x15 ,
@@ -231,15 +231,15 @@ public void run(
231
231
}
232
232
233
233
@ Test
234
- public void testCanParseWebpWithoutAlpha () throws IOException {
234
+ public void testCanParseLosslessWebpWithoutAlpha () throws IOException {
235
235
byte [] data =
236
236
new byte [] {
237
237
0x52 ,
238
238
0x49 ,
239
239
0x46 ,
240
240
0x46 ,
241
- 0x72 ,
242
- 0x1c ,
241
+ 0x3c ,
242
+ 0x50 ,
243
243
0x00 ,
244
244
0x00 ,
245
245
0x57 ,
@@ -249,23 +249,133 @@ public void testCanParseWebpWithoutAlpha() throws IOException {
249
249
0x56 ,
250
250
0x50 ,
251
251
0x38 ,
252
- 0x20 ,
253
- 0x66 ,
254
- 0x1c ,
252
+ 0x4c , // Lossless
253
+ 0x30 ,
254
+ 0x50 ,
255
255
0x00 ,
256
256
0x00 ,
257
+ 0x00 , // Flags
258
+ (byte ) 0xef ,
259
+ (byte ) 0x80 ,
260
+ 0x15 ,
261
+ 0x10 ,
262
+ (byte ) 0x8d ,
257
263
0x30 ,
264
+ 0x68 ,
265
+ 0x1b ,
266
+ (byte ) 0xc9 ,
267
+ (byte ) 0x91 ,
268
+ (byte ) 0xb2
269
+ };
270
+ runTest (
271
+ data ,
272
+ new ParserTestCase () {
273
+ @ Override
274
+ public void run (DefaultImageHeaderParser parser , InputStream is , ArrayPool byteArrayPool )
275
+ throws IOException {
276
+ assertEquals (ImageType .WEBP , parser .getType (is ));
277
+ }
278
+
279
+ @ Override
280
+ public void run (
281
+ DefaultImageHeaderParser parser , ByteBuffer byteBuffer , ArrayPool byteArrayPool )
282
+ throws IOException {
283
+ assertEquals (ImageType .WEBP , parser .getType (byteBuffer ));
284
+ }
285
+ });
286
+ }
287
+
288
+ @ Test
289
+ public void testCanParseExtendedWebpWithAlpha () throws IOException {
290
+ byte [] data =
291
+ new byte [] {
292
+ 0x52 ,
293
+ 0x49 ,
294
+ 0x46 ,
295
+ 0x46 ,
258
296
0x3c ,
259
- 0x01 ,
260
- (byte ) 0x9d ,
261
- 0x01 ,
262
- 0x2a ,
297
+ 0x50 ,
298
+ 0x00 ,
299
+ 0x00 ,
300
+ 0x57 ,
301
+ 0x45 ,
302
+ 0x42 ,
303
+ 0x50 ,
304
+ 0x56 ,
305
+ 0x50 ,
306
+ 0x38 ,
307
+ 0x58 , // Extended
308
+ 0x30 ,
309
+ 0x50 ,
310
+ 0x00 ,
311
+ 0x00 ,
312
+ 0x10 , // flags
313
+ (byte ) 0xef ,
314
+ (byte ) 0x80 ,
315
+ 0x15 ,
316
+ 0x10 ,
317
+ (byte ) 0x8d ,
318
+ 0x30 ,
319
+ 0x68 ,
320
+ 0x1b ,
321
+ (byte ) 0xc9 ,
322
+ (byte ) 0x91 ,
323
+ (byte ) 0xb2
324
+ };
325
+ runTest (
326
+ data ,
327
+ new ParserTestCase () {
328
+ @ Override
329
+ public void run (DefaultImageHeaderParser parser , InputStream is , ArrayPool byteArrayPool )
330
+ throws IOException {
331
+ assertEquals (ImageType .WEBP_A , parser .getType (is ));
332
+ }
333
+
334
+ @ Override
335
+ public void run (
336
+ DefaultImageHeaderParser parser , ByteBuffer byteBuffer , ArrayPool byteArrayPool )
337
+ throws IOException {
338
+ assertEquals (ImageType .WEBP_A , parser .getType (byteBuffer ));
339
+ }
340
+ });
341
+ }
342
+
343
+ @ Test
344
+ public void testCanParseExtendedWebpWithoutAlpha () throws IOException {
345
+ byte [] data =
346
+ new byte [] {
263
347
0x52 ,
264
- 0x02 ,
265
- (byte ) 0x94 ,
266
- 0x03 ,
348
+ 0x49 ,
349
+ 0x46 ,
350
+ 0x46 ,
351
+ 0x3c ,
352
+ 0x50 ,
353
+ 0x00 ,
267
354
0x00 ,
268
- (byte ) 0xc7
355
+ 0x57 ,
356
+ 0x45 ,
357
+ 0x42 ,
358
+ 0x50 ,
359
+ 0x56 ,
360
+ 0x50 ,
361
+ 0x38 ,
362
+ 0x58 , // Extended
363
+ 0x30 ,
364
+ 0x50 ,
365
+ 0x00 ,
366
+ 0x00 ,
367
+ 0x00 , // flags
368
+ (byte ) 0xef ,
369
+ (byte ) 0x80 ,
370
+ 0x15 ,
371
+ 0x10 ,
372
+ (byte ) 0x8d ,
373
+ 0x30 ,
374
+ 0x68 ,
375
+ 0x1b ,
376
+ (byte ) 0xc9 ,
377
+ (byte ) 0x91 ,
378
+ (byte ) 0xb2
269
379
};
270
380
runTest (
271
381
data ,
@@ -285,6 +395,137 @@ public void run(
285
395
});
286
396
}
287
397
398
+ @ Test
399
+ public void testCanParseExtendedWebpWithoutAlphaAndWithAnimation () throws IOException {
400
+ byte [] data =
401
+ new byte [] {
402
+ 0x52 ,
403
+ 0x49 ,
404
+ 0x46 ,
405
+ 0x46 ,
406
+ 0x3c ,
407
+ 0x50 ,
408
+ 0x00 ,
409
+ 0x00 ,
410
+ 0x57 ,
411
+ 0x45 ,
412
+ 0x42 ,
413
+ 0x50 ,
414
+ 0x56 ,
415
+ 0x50 ,
416
+ 0x38 ,
417
+ 0x58 , // Extended
418
+ 0x30 ,
419
+ 0x50 ,
420
+ 0x00 ,
421
+ 0x00 ,
422
+ 0x02 , // Flags
423
+ (byte ) 0xef ,
424
+ (byte ) 0x80 ,
425
+ 0x15 ,
426
+ 0x10 ,
427
+ (byte ) 0x8d ,
428
+ 0x30 ,
429
+ 0x68 ,
430
+ 0x1b ,
431
+ (byte ) 0xc9 ,
432
+ (byte ) 0x91 ,
433
+ (byte ) 0xb2
434
+ };
435
+ runTest (
436
+ data ,
437
+ new ParserTestCase () {
438
+ @ Override
439
+ public void run (DefaultImageHeaderParser parser , InputStream is , ArrayPool byteArrayPool )
440
+ throws IOException {
441
+ assertEquals (ImageType .ANIMATED_WEBP , parser .getType (is ));
442
+ }
443
+
444
+ @ Override
445
+ public void run (
446
+ DefaultImageHeaderParser parser , ByteBuffer byteBuffer , ArrayPool byteArrayPool )
447
+ throws IOException {
448
+ assertEquals (ImageType .ANIMATED_WEBP , parser .getType (byteBuffer ));
449
+ }
450
+ });
451
+ }
452
+
453
+ @ Test
454
+ public void testCanParseExtendedWebpWithAlphaAndAnimation () throws IOException {
455
+ byte [] data =
456
+ new byte [] {
457
+ 0x52 ,
458
+ 0x49 ,
459
+ 0x46 ,
460
+ 0x46 ,
461
+ 0x3c ,
462
+ 0x50 ,
463
+ 0x00 ,
464
+ 0x00 ,
465
+ 0x57 ,
466
+ 0x45 ,
467
+ 0x42 ,
468
+ 0x50 ,
469
+ 0x56 ,
470
+ 0x50 ,
471
+ 0x38 ,
472
+ 0x58 , // Extended
473
+ 0x30 ,
474
+ 0x50 ,
475
+ 0x00 ,
476
+ 0x00 ,
477
+ (byte ) 0x12 , // Flags
478
+ (byte ) 0xef ,
479
+ (byte ) 0x80 ,
480
+ 0x15 ,
481
+ 0x10 ,
482
+ (byte ) 0x8d ,
483
+ 0x30 ,
484
+ 0x68 ,
485
+ 0x1b ,
486
+ (byte ) 0xc9 ,
487
+ (byte ) 0x91 ,
488
+ (byte ) 0xb2
489
+ };
490
+ runTest (
491
+ data ,
492
+ new ParserTestCase () {
493
+ @ Override
494
+ public void run (DefaultImageHeaderParser parser , InputStream is , ArrayPool byteArrayPool )
495
+ throws IOException {
496
+ assertEquals (ImageType .ANIMATED_WEBP , parser .getType (is ));
497
+ }
498
+
499
+ @ Override
500
+ public void run (
501
+ DefaultImageHeaderParser parser , ByteBuffer byteBuffer , ArrayPool byteArrayPool )
502
+ throws IOException {
503
+ assertEquals (ImageType .ANIMATED_WEBP , parser .getType (byteBuffer ));
504
+ }
505
+ });
506
+ }
507
+
508
+ @ Test
509
+ public void testCanParseRealAnimatedWebpFile () throws IOException {
510
+ byte [] data = Util .readBytes (TestResourceUtil .openResource (getClass (), "animated_webp.webp" ));
511
+ runTest (
512
+ data ,
513
+ new ParserTestCase () {
514
+ @ Override
515
+ public void run (DefaultImageHeaderParser parser , InputStream is , ArrayPool byteArrayPool )
516
+ throws IOException {
517
+ assertThat (parser .getType (is )).isEqualTo (ImageType .ANIMATED_WEBP );
518
+ }
519
+
520
+ @ Override
521
+ public void run (
522
+ DefaultImageHeaderParser parser , ByteBuffer byteBuffer , ArrayPool byteArrayPool )
523
+ throws IOException {
524
+ assertThat (parser .getType (byteBuffer )).isEqualTo (ImageType .ANIMATED_WEBP );
525
+ }
526
+ });
527
+ }
528
+
288
529
@ Test
289
530
public void testCanParseAvifMajorBrand () throws IOException {
290
531
byte [] data =
0 commit comments