Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a simple example #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions src/Hqx2xUpscalerExample.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@

import java.awt.image.*;
import java.io.*;
import javax.imageio.*;
import hqx.*;

class Hqx2xUpscalerExample {
public static void main(String[] args) {

// Load an image
BufferedImage bi = null;
try {
bi = ImageIO.read(new File("sampleImage_original.png"));
}
catch (java.io.IOException e) {
System.err.println("Error loading image file: " + e);
}
if (bi != null) {
// Convert image to ARGB if on another format
if (bi.getType() != BufferedImage.TYPE_INT_ARGB && bi.getType() != BufferedImage.TYPE_INT_ARGB_PRE) {
final BufferedImage temp = new BufferedImage(bi.getWidth(), bi.getHeight(), BufferedImage.TYPE_INT_ARGB);
temp.getGraphics().drawImage(bi, 0, 0, null);
bi = temp;
}
// Obtain pixel data for source image
final int[] data = ((DataBufferInt) bi.getRaster().getDataBuffer()).getData();

// Initialize lookup tables
RgbYuv.hqxInit();

// Create the destination image, twice as large for 2x algorithm
final BufferedImage biDest2 = new BufferedImage(bi.getWidth() * 2, bi.getHeight() * 2, BufferedImage.TYPE_INT_ARGB);
// Obtain pixel data for destination image
final int[] dataDest2 = ((DataBufferInt) biDest2.getRaster().getDataBuffer()).getData();
// Resize it
Hqx_2x.hq2x_32_rb(data, dataDest2, bi.getWidth(), bi.getHeight());
// Save our result
try {
ImageIO.write(biDest2, "PNG", new File("sampleImage_hqx2.png"));
}
catch(java.io.IOException e) {
System.err.println("Error loading image file: " + e);
}

// More calls to hq[234]x_32_rb() methods
// ....

// Release the lookup table
RgbYuv.hqxDeinit();
}
}
}
Binary file added src/sampleImage_original.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.