|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.awt.Component | +--com.tjtieto.wap.wapix.WBMPMaster
Methods transform images to greyscale and finally black & white for two reasons: the images are only supposed to be 2 color images and they are more efficient this way.
Converts any java.awt.Image, JPG or GIF to WBMP format. Other formats are supported via Sun's JIMI package.
p = processing method (processing style)
w = (width)
h = (height)
s = (scaling method)
url = url to read the image from
k = (threshold limit for rendering (0-255), default 128)
b = (bgcolor, default white)
i = (invert (0 = false, 1 = true), default 0)
mh = (mirror horizontally (0 = false, 1 = true))
fv = (flip vertically (0 = false, 1 = true))
o = outputfilename
150500 Initial version after several tests and enhancements to previous systems 180500 Added Shiau et al error diffusion patterns 180500 Some minor optimizations to Burke pattern 190500 Added methods for decoding WBMP images
DISCLAIMER:
THE AUTHOR CANNOT BE HELD RESPONSIBLE FOR ANY HARM, FINANCIAL LOSS OR RELATED EVENT CAUSED BY THE USE OF THIS SOFTWARE. THE ALGORITHMS USED HERE WERE DESIGNED BY RESPECTIVE AUTHORS AND THE ACCURACY OF THEIR IMPLEMENTATION IS NOT GUARANTEED. YOU MAY NOT SELL THIS CODE OR INCLUDE IT IN COMMERCIAL PRODUCTS WITHOUT WRITTEN AUTHORIZATION AND LICENSE AGREEMENT. FURTHER, ANY ATTEMPT TO REVERSE ENGINEER, ALTER OR OTHERWISE MANIPULATE THE CODE IS PROHIBITED. YOU ARE ALLOWED TO USE THIS OBJECT FOR EVALUATION PURPOSES, BUT IN OTHER CASES CONTACT THE AUTHOR.
ALL RIGHTS RESERVED (C) Jarkko Viinamäki
Field Summary | |
static int |
PROCESS_DITHER_BURKE
Burke error diffusion pattern: - - X 8 4 2 4 8 4 2 |
static int |
PROCESS_DITHER_FLOYD_STEINBERG
Floyd and Steinberg error diffusion pattern: - X 7 3 5 1 |
static int |
PROCESS_DITHER_JARVIS
Jarvis, Judice, and Ninke error diffusion pattern: - - X 7 5 3 5 7 5 3 1 3 5 3 1 |
static int |
PROCESS_DITHER_ORDERED_2X2
Ordered dithering with map: 1 3 4 2 |
static int |
PROCESS_DITHER_ORDERED_3X3_1
Ordered dithering with map: 1 7 4 5 8 3 6 2 9 |
static int |
PROCESS_DITHER_ORDERED_3X3_2
Ordered dithering with map: 8 3 4 6 1 2 7 5 9 |
static int |
PROCESS_DITHER_ORDERED_4X4
Ordered dithering with map: 1 9 3 11 13 5 15 7 4 12 2 10 16 8 14 6 |
static int |
PROCESS_DITHER_SHIAU_1
Shiau et al error diffusion pattern 1: - - - X 8 1 1 2 4 0 |
static int |
PROCESS_DITHER_SHIAU_2
Shiau et al error diffusion pattern 2: - - - X 8 2 0 2 4 0 |
static int |
PROCESS_DITHER_STUCKI
Stucki error diffusion pattern: - - X 8 4 2 4 8 4 2 1 2 4 2 1 |
static int |
PROCESS_HORIZONTAL_MIRROR
Mirrors the image pixels horizontally |
static int |
PROCESS_THRESHOLD
Creates black and white image with defined threshold color |
static int |
PROCESS_VERTICAL_FLIP
Flips the image pixels vertically |
static int |
SCALE_AUTOFIT_BY_X
Scale image by width setting and adjust height proportionally |
static int |
SCALE_AUTOFIT_BY_Y
Scale image by height setting and adjust width proportionally |
static int |
SCALE_BY_X
Scale image by width but leave the height to its old value |
static int |
SCALE_BY_X_Y
Scale image by height & width setting |
static int |
SCALE_BY_Y
Scale image by height but leave the width to its old value |
Fields inherited from class java.awt.Component |
BOTTOM_ALIGNMENT,
CENTER_ALIGNMENT,
LEFT_ALIGNMENT,
RIGHT_ALIGNMENT,
TOP_ALIGNMENT |
Constructor Summary | |
WBMPMaster()
Constructor |
Method Summary | |
static java.awt.Image |
createImage(int[] ai,
int i,
int j)
Creates java.awt.Image object based on pixel values. |
static int |
decodeBytes(java.io.InputStream is)
Reads one Multibyte Integer from the InputStream. |
static int[] |
decodePixels(java.io.InputStream is)
Reads a WBMP image from the InputStream and returns the result as one dimensional int array or RGB values. |
static int[] |
ditherBurke(int[] ai,
int i,
int j,
int k,
java.awt.Color color,
boolean flag)
Burke pattern: - - X 8 4 2 4 8 4 2 Efficiency: 8 Quality: 8 Notice that this is just a simplification of the Stucki filter with the bottom row removed. |
static int[] |
ditherFloydSteinberg(int[] ai,
int i,
int j,
int k,
java.awt.Color color,
boolean flag)
Floyd-Steinberg pattern: - X 7 3 5 1 Efficiency: 9 Quality: 7 In this filter, the X represents the pixel you are currently scanning, and the numbers (called weights, for equally boring reasons) represent the proportion of the error distributed to the pixel in that position. |
static int[] |
ditherJarvis(int[] ai,
int i,
int j,
int k,
java.awt.Color color,
boolean flag)
Jarvis, Judice, and Ninke pattern: - - X 7 5 3 5 7 5 3 1 3 5 3 1 Efficiency: 6 Quality: 8 The divisor here is 48, which is a little more expensive to calculate, and the errors are distributed over three lines, requiring extra memory and time for processing. |
static int[] |
ditherOrdered(int[] ai,
int i,
int j,
int[] dithermap,
java.awt.Color bg,
boolean invert)
Dithers image governed by dithermap array using ordered dithering method. |
static int[] |
ditherShiau1(int[] ai,
int i,
int j,
int k,
java.awt.Color color,
boolean flag)
Shiau et al pattern 1: - - - X 8 1 1 2 4 0 This distribution scheme was proposed based on the hypothesis that worm creation was a result of the lack of error distribution beyond the direction of the diagonal defined by pixel (n,l) and pixel (n-1, l+1). |
static int[] |
ditherShiau2(int[] ai,
int i,
int j,
int k,
java.awt.Color color,
boolean flag)
Shiau et al pattern 2: - - - X 8 2 0 2 4 0 The present proposal improves the output of the Shiau et al distribution scheme in some circumstances, and improves the efficiency of the error diffusion process, by eliminating one of the distribution neighbors, thereby reducing the number of neighboring pixels that receive error. |
static int[] |
ditherSimple(int[] ai,
int i,
int j,
int k,
java.awt.Color color,
boolean flag)
Does simple threshold transformation of the image. |
static int[] |
ditherStucki(int[] ai,
int i,
int j,
int k,
java.awt.Color color,
boolean flag)
Stucki pattern: - - X 8 4 2 4 8 4 2 1 2 4 2 1 Efficiency: 7 Quality: 10 This one takes a division by 42 for each pixel and is therefore slow if math is done inside the loop. |
static void |
encodeBytes(java.io.OutputStream o,
int i)
Transforms bytes into Wireless Bitmap format. |
void |
encodePixels(java.io.OutputStream o,
java.awt.Image image)
Encodes java.awt.Image to Wireless Bitmap. |
static void |
encodePixels(java.io.OutputStream o,
int[] image,
int width,
int height)
Encodes image RGB pixels to Wireless Bitmap. |
static int[] |
flipPixels(int[] buffer,
int width,
int height)
Flips image vertically. |
java.awt.Image |
getImage(java.net.URL url)
Reads an image from the given URL |
java.awt.Image |
getScaledInstance(java.awt.Image img,
int w,
int h,
int mode)
Scales supplied image according to scaling mode. |
int[] |
grabPixels(java.awt.Image img)
Transforms java.awt.Image into an array of pixels |
static void |
main(java.lang.String[] arg)
This method is called when the object is invoked from command line. |
static int[] |
mirrorPixels(int[] buffer,
int width,
int height)
Mirrors image horizontally. |
void |
processImage(java.io.OutputStream o,
java.util.Properties prop)
Processes all arguments given in Properties container, reads an image from defined URL, does selected image processing tricks and writes the result to supplied outputstream. |
static int[] |
processPixels(int type,
int[] ai,
int i,
int j,
int k,
java.awt.Color color,
boolean flag)
Dithers image RGB values, renders image to greyscale and finally transforms it into 2 color black & white image. |
static byte[] |
readURL(java.net.URL addr)
Reads contents of certain URL as buffered stream. |
static int[] |
threshold(int[] ai,
int i,
int j,
int k,
java.awt.Color color,
boolean flag)
Transforms image into 2 color black & white by using param k as threshold value. |
Methods inherited from class java.awt.Component |
action,
add,
addComponentListener,
addFocusListener,
addInputMethodListener,
addKeyListener,
addMouseListener,
addMouseMotionListener,
addNotify,
addPropertyChangeListener,
addPropertyChangeListener,
bounds,
checkImage,
checkImage,
contains,
contains,
createImage,
createImage,
deliverEvent,
disable,
dispatchEvent,
doLayout,
enable,
enable,
enableInputMethods,
getAlignmentX,
getAlignmentY,
getBackground,
getBounds,
getBounds,
getColorModel,
getComponentAt,
getComponentAt,
getComponentOrientation,
getCursor,
getDropTarget,
getFont,
getFontMetrics,
getForeground,
getGraphics,
getHeight,
getInputContext,
getInputMethodRequests,
getLocale,
getLocation,
getLocation,
getLocationOnScreen,
getMaximumSize,
getMinimumSize,
getName,
getParent,
getPeer,
getPreferredSize,
getSize,
getSize,
getToolkit,
getTreeLock,
getWidth,
getX,
getY,
gotFocus,
handleEvent,
hasFocus,
hide,
imageUpdate,
inside,
invalidate,
isDisplayable,
isDoubleBuffered,
isEnabled,
isFocusTraversable,
isLightweight,
isOpaque,
isShowing,
isValid,
isVisible,
keyDown,
keyUp,
layout,
list,
list,
list,
list,
list,
locate,
location,
lostFocus,
minimumSize,
mouseDown,
mouseDrag,
mouseEnter,
mouseExit,
mouseMove,
mouseUp,
move,
nextFocus,
paint,
paintAll,
postEvent,
preferredSize,
prepareImage,
prepareImage,
print,
printAll,
remove,
removeComponentListener,
removeFocusListener,
removeInputMethodListener,
removeKeyListener,
removeMouseListener,
removeMouseMotionListener,
removeNotify,
removePropertyChangeListener,
removePropertyChangeListener,
repaint,
repaint,
repaint,
repaint,
requestFocus,
reshape,
resize,
resize,
setBackground,
setBounds,
setBounds,
setComponentOrientation,
setCursor,
setDropTarget,
setEnabled,
setFont,
setForeground,
setLocale,
setLocation,
setLocation,
setName,
setSize,
setSize,
setVisible,
show,
show,
size,
toString,
transferFocus,
update,
validate |
Methods inherited from class java.lang.Object |
equals,
getClass,
hashCode,
notify,
notifyAll,
wait,
wait,
wait |
Field Detail |
public static final int PROCESS_DITHER_JARVIS
public static final int PROCESS_DITHER_FLOYD_STEINBERG
public static final int PROCESS_DITHER_BURKE
public static final int PROCESS_DITHER_STUCKI
public static final int PROCESS_THRESHOLD
public static final int PROCESS_DITHER_ORDERED_2X2
public static final int PROCESS_DITHER_ORDERED_3X3_1
public static final int PROCESS_DITHER_ORDERED_3X3_2
public static final int PROCESS_DITHER_ORDERED_4X4
public static final int PROCESS_HORIZONTAL_MIRROR
public static final int PROCESS_VERTICAL_FLIP
public static final int PROCESS_DITHER_SHIAU_1
public static final int PROCESS_DITHER_SHIAU_2
public static final int SCALE_AUTOFIT_BY_X
public static final int SCALE_AUTOFIT_BY_Y
public static final int SCALE_BY_X_Y
public static final int SCALE_BY_X
public static final int SCALE_BY_Y
Constructor Detail |
public WBMPMaster()
Method Detail |
public static final int[] processPixels(int type, int[] ai, int i, int j, int k, java.awt.Color color, boolean flag)
type
- the dithering method to use. This defines the diffusion matrix.ai
- the pixels of the original image in one dimensional array of RGB valuesi
- the width of the imagej
- the height of the imagek
- the threshold value (0-255) RGBcolor
- the background color of the resulting imageflag
- if this is true, result is invertedpublic static final int[] mirrorPixels(int[] buffer, int width, int height)
buffer
- the original image to be mirroredwidth
- image widthheight
- image heightpublic static final int[] flipPixels(int[] buffer, int width, int height)
buffer
- the original image to be flippedwidth
- image widthheight
- image heightpublic static int[] ditherOrdered(int[] ai, int i, int j, int[] dithermap, java.awt.Color bg, boolean invert)
ai
- the pixels of the original image in one dimensional array of RGB valuesi
- the width of the imagej
- the height of the imagedithermap
- contains the matrix used for ditheringpublic static int[] ditherJarvis(int[] ai, int i, int j, int k, java.awt.Color color, boolean flag)
- - X 7 5 3 5 7 5 3 1 3 5 3 1
ai
- the pixels of the original image in one dimensional array of RGB valuesi
- the width of the imagej
- the height of the imagek
- the threshold value (0-255) RGBcolor
- the background color of the resulting imageflag
- if this is true, result is invertedpublic static int[] ditherStucki(int[] ai, int i, int j, int k, java.awt.Color color, boolean flag)
- - X 8 4 2 4 8 4 2 1 2 4 2 1
ai
- the pixels of the original image in one dimensional array of RGB valuesi
- the width of the imagej
- the height of the imagek
- the threshold value (0-255) RGBcolor
- the background color of the resulting imageflag
- if this is true, result is invertedditherBurke(int[], int, int, int, java.awt.Color, boolean)
public static int[] ditherBurke(int[] ai, int i, int j, int k, java.awt.Color color, boolean flag)
- - X 8 4 2 4 8 4 2
ai
- the pixels of the original image in one dimensional array of RGB valuesi
- the width of the imagej
- the height of the imagek
- the threshold value (0-255) RGBcolor
- the background color of the resulting imageflag
- if this is true, result is invertedditherStucki(int[], int, int, int, java.awt.Color, boolean)
public static final int[] ditherSimple(int[] ai, int i, int j, int k, java.awt.Color color, boolean flag)
ai
- the pixels of the original image in one dimensional array of RGB valuesi
- the width of the imagej
- the height of the imagek
- the threshold value (0-255) RGBcolor
- the background color of the resulting imageflag
- if this is true, result is invertedpublic static int[] ditherFloydSteinberg(int[] ai, int i, int j, int k, java.awt.Color color, boolean flag)
- X 7 3 5 1
ai
- the pixels of the original image in one dimensional array of RGB valuesi
- the width of the imagej
- the height of the imagek
- the threshold value (0-255) RGBcolor
- the background color of the resulting imageflag
- if this is true, result is invertedpublic static int[] ditherShiau1(int[] ai, int i, int j, int k, java.awt.Color color, boolean flag)
- - - X 8 1 1 2 4 0
ai
- the pixels of the original image in one dimensional array of RGB valuesi
- the width of the imagej
- the height of the imagek
- the threshold value (0-255) RGBcolor
- the background color of the resulting imageflag
- if this is true, result is invertedpublic static int[] ditherShiau2(int[] ai, int i, int j, int k, java.awt.Color color, boolean flag)
- - - X 8 2 0 2 4 0
ai
- the pixels of the original image in one dimensional array of RGB valuesi
- the width of the imagej
- the height of the imagek
- the threshold value (0-255) RGBcolor
- the background color of the resulting imageflag
- if this is true, result is invertedpublic static int[] threshold(int[] ai, int i, int j, int k, java.awt.Color color, boolean flag)
ai
- the pixels of the original image in one dimensional array of RGB valuesi
- the width of the imagej
- the height of the imagek
- the threshold value (0-255) RGBcolor
- the background color of the resulting imageflag
- if this is true, result is invertedpublic static java.awt.Image createImage(int[] ai, int i, int j)
ai
- the image pixel arrayi
- the width of the imagej
- the height of the imagepublic static final void encodeBytes(java.io.OutputStream o, int i) throws java.io.IOException
o
- the stream the result should be written to. This should be buffered.i
- this is the width or height of the imageencodePixels(java.io.OutputStream, java.awt.Image)
public static int decodeBytes(java.io.InputStream is) throws java.io.IOException
is
- the InputStream to read the value fromdecodePixels(java.io.InputStream)
public static int[] decodePixels(java.io.InputStream is) throws java.io.IOException
is
- the InputStream containing the WBMP encodingdecodeBytes(java.io.InputStream)
public final void encodePixels(java.io.OutputStream o, java.awt.Image image) throws java.io.IOException, java.lang.InterruptedException
o
- the stream the result should be written to. This should be buffered.image
- reference to the original image to be convertedencodeBytes(java.io.OutputStream, int)
public static final void encodePixels(java.io.OutputStream o, int[] image, int width, int height) throws java.io.IOException
o
- the stream the result should be written to. This should be buffered.image
- RGB pixel values of the imagewidth
- image widthheight
- image heightencodeBytes(java.io.OutputStream, int)
public final java.awt.Image getScaledInstance(java.awt.Image img, int w, int h, int mode)
img
- the image to be scaledw
- widthh
- heightmode
- operation mode, see all SCALE_-fields in this objectpublic final int[] grabPixels(java.awt.Image img) throws java.lang.InterruptedException
public final java.awt.Image getImage(java.net.URL url) throws java.lang.InterruptedException, java.net.MalformedURLException, java.io.IOException
public static final byte[] readURL(java.net.URL addr) throws java.net.MalformedURLException, java.io.IOException
addr
- the URL to be readpublic final void processImage(java.io.OutputStream o, java.util.Properties prop) throws java.io.IOException, java.net.MalformedURLException, java.lang.InterruptedException
o
- stream to write the result to. This MUST be buffered in order to get good performance.prop
- Properties bag containing all variables necessary to do the processing. Equal to command line params.public static void main(java.lang.String[] arg)
arg
- an array containing parameters received from the command line arguments.
|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |