Skip to content

Commit

Permalink
fix a scaling bug introduced a long time ago, shit shit shit
Browse files Browse the repository at this point in the history
  • Loading branch information
Dahie committed Apr 29, 2012
1 parent 54be921 commit 2e43122
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 26 deletions.
27 changes: 8 additions & 19 deletions DDSUtils/src/ddsutil/ByteBufferedImage.java
Expand Up @@ -12,6 +12,8 @@
import java.nio.ByteBuffer;
import java.nio.IntBuffer;

import javax.activation.UnsupportedDataTypeException;

import util.ImageUtils;


Expand Down Expand Up @@ -131,31 +133,18 @@ private static byte[] convertDataBufferToARGBArray(final int width,

int r, g, b, a;
int count = 0;
System.out.println(width);
System.out.println(height);
System.out.println(bufferedImageType);
// if(length != dataBuffer.getSize())
// throw new IllegalStateException("Databuffer has not the expected length: " + dataBuffer.getSize()+ " instead of " + length);
// if() TODO FIXME, what is the other supported?
// throw new UnsupportedDataTypeException("BufferedImages types TYPE_4BYTE_ABGR supported")
if(length != dataBuffer.getSize())
throw new IllegalStateException("Databuffer has not the expected length: " + dataBuffer.getSize()+ " instead of " + length);

for (int i = 0; i < dataBuffer.getSize(); i=i+componentCount) {
// databuffer has unsigned integers, they must be converted to signed byte

// original order from BufferedImage
// System.out.println(componentCount);
// System.out.println(length);
// System.out.println(i);

//
if(componentCount > 3) {
// 32bit image
if (bufferedImageType == BufferedImage.TYPE_INT_ARGB) {
int value = (dataBuffer.getElem(count) );
int[] channels = ImageOperations.readPixelARGB(value);
a = channels[0];
r = channels[1];
g = channels[2];
b = channels[3];
count ++;
} else if (bufferedImageType != BufferedImage.TYPE_4BYTE_ABGR) {
if (bufferedImageType != BufferedImage.TYPE_4BYTE_ABGR) {
/* working with png+alpha */
a = (dataBuffer.getElem(i) );
r = (dataBuffer.getElem(i+1));
Expand Down
14 changes: 7 additions & 7 deletions DDSUtils/src/ddsutil/ImageRescaler.java
Expand Up @@ -3,9 +3,7 @@
*/
package ddsutil;

import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;

/**
Expand Down Expand Up @@ -44,11 +42,13 @@ public ImageRescaler(final int scaleMethod) {
public BufferedImage rescaleBI(final BufferedImage originalImage,
final int newWidth, final int newHeight) {

BufferedImage bi = new BufferedImage(newWidth, newHeight, BufferedImage.TYPE_INT_ARGB);
Graphics2D g = bi.createGraphics();
g.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_BILINEAR);
g.drawImage(originalImage, 0, 0, newWidth, newHeight, null);
Image rescaledImage = originalImage.getScaledInstance(newWidth, newHeight, scaleAlgorithm);
BufferedImage bi;
if(rescaledImage instanceof BufferedImage)
bi = (BufferedImage)rescaledImage;
else
bi = BIUtil.convertImageToBufferedImage(rescaledImage, BufferedImage.TYPE_4BYTE_ABGR);

return bi;
}

Expand Down

0 comments on commit 2e43122

Please sign in to comment.