| 1 |
// Copyright (c) the JPEG XL Project Authors. All rights reserved. |
| 2 |
// |
| 3 |
// Use of this source code is governed by a BSD-style |
| 4 |
// license that can be found in the LICENSE file. |
| 5 |
|
| 6 |
package org.jpeg.jpegli.wrapper; |
| 7 |
|
| 8 |
import static java.nio.charset.StandardCharsets.UTF_8; |
| 9 |
|
| 10 |
import java.io.ByteArrayOutputStream; |
| 11 |
import java.io.IOException; |
| 12 |
import java.util.Base64; |
| 13 |
|
| 14 |
/** |
| 15 |
* Tests for jpegli encoder wrapper. |
| 16 |
*/ |
| 17 |
public class EncoderTest { |
| 18 |
static void checkTrue(boolean condition) { |
| 19 |
if (!condition) { |
| 20 |
throw new IllegalStateException("check failed"); |
| 21 |
} |
| 22 |
} |
| 23 |
|
| 24 |
static void test64x64() throws IOException { |
| 25 |
int width = 64; |
| 26 |
int height = 64; |
| 27 |
int[] pixels = new int[width * height]; |
| 28 |
for (int y = 0; y < 64; ++y) { |
| 29 |
for (int x = 0; x < 64; ++x) { |
| 30 |
pixels[x + 64 * y] = (x * 4) + ((y * 4) << 8); |
| 31 |
} |
| 32 |
} |
| 33 |
ByteArrayOutputStream out = new ByteArrayOutputStream(); |
| 34 |
Encoder.encode(pixels, width, height, 99, out); |
| 35 |
System.err.println("Encoded size: " + out.size()); |
| 36 |
checkTrue(out.size() > 0); |
| 37 |
byte[] encoded = Base64.getEncoder().encode(out.toByteArray()); |
| 38 |
System.err.println("Base64: " + new String(encoded, UTF_8)); |
| 39 |
} |
| 40 |
|
| 41 |
// Simple executable to avoid extra dependencies. |
| 42 |
public static void main(String[] args) throws IOException { |
| 43 |
test64x64(); |
| 44 |
} |
| 45 |
} |