/Users/lyon/j4p/src/math/transforms/fft/ImageUtils.java

1    //Title:        WDYLBJIP1 
2    //Version: 
3    //Copyright:    Copyright (c) 1998 
4    //Author:       Dongyan Wang & Bo Lin 
5    //Company:      UWM 
6    //Description:  Java Image Processing 
7     
8    package math.transforms.fft; 
9     
10   //package WDYLBJIP1; 
11    
12    
13   public class ImageUtils { 
14    
15     public ImageUtils() { 
16     } 
17    
18     public int argbToInt(short alpha, short red, short green, short blue) { 
19       return alpha << 24 | red << 16 | green << 8 | blue; 
20     } 
21    
22     static public int[] argbToInt(short[] alpha, short[] red, 
23                                   short[] green, short[] blue) { 
24    
25       int length = alpha.length; 
26       int[] imageInt = new int[length]; 
27    
28       for (int i = 0; i < length; i++) { 
29         imageInt[i] = alpha[i] << 24 | red[i] << 16 | green[i] << 8 | blue[i]; 
30       } 
31       return imageInt; 
32     } 
33    
34     static public int[] argbToInt(short[] alpha, float[] red, 
35                                   float[] green, float[] blue) { 
36    
37       int length = alpha.length; 
38       int[] imageInt = new int[length]; 
39    
40       for (int i = 0; i < length; i++) { 
41         imageInt[i] = alpha[i] << 24 | ((int) red[i]) << 16 | 
42             ((int) green[i]) << 8 | ((int) blue[i]); 
43       } 
44       return imageInt; 
45     } 
46    
47     static public int[] argbToInt(short[] alpha, double[] red, 
48                                   double[] green, double[] blue) { 
49    
50       int length = alpha.length; 
51       int[] imageInt = new int[length]; 
52    
53       for (int i = 0; i < length; i++) { 
54         imageInt[i] = alpha[i] << 24 | ((int) red[i]) << 16 | 
55             ((int) green[i]) << 8 | ((int) blue[i]); 
56       } 
57       return imageInt; 
58     } 
59    
60     static public short getAlpha(int argb) { 
61       return (short) ((argb >> 24) & 0xFF); 
62     } 
63    
64     static public short getRed(int argb) { 
65       return (short) ((argb >> 16) & 0xFF); 
66     } 
67    
68     static public short getGreen(int argb) { 
69       return (short) ((argb >> 8) & 0xFF); 
70     } 
71    
72     static public short getBlue(int argb) { 
73       return ((short) (argb & 0xFF)); 
74     } 
75    
76    
77     static public short[] getRed(int[] argb) { 
78       int length = argb.length; 
79       short red[] = new short[length]; 
80    
81       for (int i = 0; i < length; i++) 
82         red[i] = (short) ((argb[i] & 0x00FF0000) >> 16); 
83       return red; 
84     } 
85    
86     static public short[] getGreen(int[] argb) { 
87       int length = argb.length; 
88       short green[] = new short[length]; 
89    
90       for (int i = 0; i < length; i++) 
91         green[i] = (short) ((argb[i] & 0x0000FF00) >> 8); 
92       return green; 
93     } 
94    
95     static public short[] getBlue(int[] argb) { 
96       int length = argb.length; 
97       short blue[] = new short[length]; 
98    
99       for (int i = 0; i < length; i++) 
100        blue[i] = (short) (argb[i] & 0x000000FF); 
101      return blue; 
102    } 
103   
104    static public short[] getAlpha(int[] argb) { 
105      int length = argb.length; 
106      short alpha[] = new short[length]; 
107   
108      for (int i = 0; i < length; i++) 
109        alpha[i] = (short) ((argb[i] & 0xFF000000) >> 24); 
110      return alpha; 
111    } 
112   
113  }