fork download
  1. import org.eclipse.swt.SWT;
  2. import org.eclipse.swt.events.PaintEvent;
  3. import org.eclipse.swt.events.PaintListener;
  4. import org.eclipse.swt.layout.FillLayout;
  5. import org.eclipse.swt.widgets.Canvas;
  6. import org.eclipse.swt.widgets.Display;
  7. import org.eclipse.swt.widgets.Shell;
  8.  
  9. import org.eclipse.swt.graphics.PaletteData;
  10. import org.eclipse.swt.graphics.Image;
  11. import org.eclipse.swt.graphics.ImageData;
  12.  
  13. import java.io.*;
  14.  
  15. public class CanvasRepaint {
  16.  
  17. /**
  18. * 본 프로그램의 License는 AGPL3 http://w...content-available-to-author-only...u.org/licenses/agpl-3.0.html
  19. * 개인적으로 쓰려고 만들다 만 코드입니다. 코드가 지저분하고 불완전하므로 알아서 고치시기 바랍니다.
  20. * @param args
  21. */
  22. public static void main(String[] args) {
  23. // TODO Auto-generated method stub
  24. final rtk2face face= new rtk2face("kaodata.dat", 40);
  25.  
  26. Display display = new Display();
  27. Shell shell = new Shell(display);
  28. shell.setText("삼국지");
  29. shell.setLayout(new FillLayout());
  30.  
  31. Canvas canvas = new Canvas(shell, SWT.NONE);
  32.  
  33. final int xx=20;
  34. final int yy=12;
  35.  
  36. PaletteData palette = new PaletteData(0xff0000, 0x00ff00, 0x0000ff);
  37. ImageData sourceData = new ImageData(64, face.getHeight(), 24, palette);
  38. ImageData sourceData2 = new ImageData(64*xx, face.getHeight()*yy, 24, palette);
  39. sourceData.setPixels(0, 0, 64*face.getHeight()-1, face.getFace(200), 0);
  40. sourceData2.setPixels(0, 0, 64*xx * face.getHeight()*yy -1, face.getFaces(0,xx*yy-1,xx,yy), 0);
  41. //face.getFaces(0, 5, 3, 2);
  42.  
  43. final Image source = new Image(display, sourceData);
  44. final Image source2 = new Image(display, sourceData2);
  45.  
  46. canvas.addPaintListener(new PaintListener() {
  47. public void paintControl(PaintEvent e) {
  48. e.gc.drawImage(source2, 0, 0, 64*xx, face.getHeight()*yy, 0, 0, 64*xx, face.getHeight()*yy*2);
  49. //e.gc.drawImage(source, 0, 0, 64, face.getHeight(), 100, 100, 64, face.getHeight()*2);
  50. }
  51. });
  52.  
  53. canvas.redraw();
  54.  
  55. shell.open();
  56. while (!shell.isDisposed()) {
  57. if (!display.readAndDispatch()) {
  58. display.sleep();
  59. }
  60. }
  61. display.dispose();
  62. }
  63. }
  64.  
  65. class rtk2face {
  66. private String filePath;
  67. private int height;
  68.  
  69. public rtk2face(String filePath, int height){
  70. this.filePath = filePath;
  71. this.height = height;
  72. }
  73.  
  74. public int[] getFace(int faceIndex){
  75. byte[] srcByte = new byte[24 * height]; // srcByte: 원본 바이트 배열
  76. int[] src = new int[24 * height]; // src: 원본 int 배열
  77. int[] out = new int[64 * height]; // out: 출력 int 배열
  78.  
  79. try{
  80. RandomAccessFile rf = new RandomAccessFile(filePath, "r");
  81. rf.seek(960*faceIndex); // 얼굴의 첫 위치로
  82. //rf.seek(0x780+960*216);
  83. //a = rf.readLine();
  84. rf.read(srcByte, 0, 24*height); // 얼굴 하나 읽음
  85. // srcByte를 src로 바꾼다
  86. for ( int i = 0; i < srcByte.length; i++){
  87. src[i] = srcByte[i] & 0xff;
  88. //System.out.printf("%x ", src[i] );
  89. }
  90. System.out.printf("\n");
  91.  
  92. /*한 바이트를 읽고 여덟픽셀로 파란색을 옮긴다
  93. * 목표의 포인터를 -8한다
  94. * 한 바이트를 읽고 여덟픽셀로 빨간색을 옮긴다
  95. * 목표의 포인터를 -8한다
  96. * 한 바이트를 읽고 여덟픽셀로 녹색을 옮긴다*/
  97. int x = 0;
  98. int k = 0;
  99. // 00000000, 11111111
  100. while( k < src.length){
  101. out[x++] = ((src[k] & 128) >> 7) * 0x0000ff;
  102. out[x++] = ((src[k] & 64) >> 6)* 0x0000ff;
  103. out[x++] = ((src[k] & 32) >> 5)* 0x0000ff;
  104. out[x++] = ((src[k] & 16) >> 4)* 0x0000ff;
  105. out[x++] = ((src[k] & 8) >> 3)* 0x0000ff;
  106. out[x++] = ((src[k] & 4) >> 2)* 0x0000ff;
  107. out[x++] = ((src[k] & 2) >> 1)* 0x0000ff;
  108. out[x++] = ((src[k++] & 1))* 0x0000ff;
  109. x -= 8;
  110. out[x++] |= ((src[k] & 128) >> 7) * 0xff0000;
  111. out[x++] |= ((src[k] & 64) >> 6)* 0xff0000;
  112. out[x++] |= ((src[k] & 32) >> 5)* 0xff0000;
  113. out[x++] |= ((src[k] & 16) >> 4)* 0xff0000;
  114. out[x++] |= ((src[k] & 8) >> 3)* 0xff0000;
  115. out[x++] |= ((src[k] & 4) >> 2)* 0xff0000;
  116. out[x++] |= ((src[k] & 2) >> 1)* 0xff0000;
  117. out[x++] |= ((src[k++] & 1))* 0xff0000;
  118. x -= 8;
  119. out[x++] |= ((src[k] & 128) >> 7) * 0x00ff00;
  120. out[x++] |= ((src[k] & 64) >> 6)* 0x00ff00;
  121. out[x++] |= ((src[k] & 32) >> 5)* 0x00ff00;
  122. out[x++] |= ((src[k] & 16) >> 4)* 0x00ff00;
  123. out[x++] |= ((src[k] & 8) >> 3)* 0x00ff00;
  124. out[x++] |= ((src[k] & 4) >> 2)* 0x00ff00;
  125. out[x++] |= ((src[k] & 2) >> 1)* 0x00ff00;
  126. out[x++] |= ((src[k++] & 1))* 0x00ff00;
  127. }
  128. for(int j=0; j<out.length; j++){
  129. if(out[j] == 0x000000)//검
  130. out[j] = 0x000000;
  131. if(out[j] == 0xff0000)//빨
  132. out[j] = 0xff5555;
  133. if(out[j] == 0xffff00)//노
  134. out[j] = 0xffff55;
  135. if(out[j] == 0x00ff00)//녹
  136. out[j] = 0x55ff55;
  137. if(out[j] == 0x00ffff)//하
  138. out[j] = 0x55ffff;
  139. if(out[j] == 0x0000ff)//파
  140. out[j] = 0x5555ff;
  141. if(out[j] == 0xff00ff)//분
  142. out[j] = 0xff55ff;
  143. if(out[j] == 0xffffff)//흰
  144. out[j] = 0xffffff;
  145. }
  146. for ( int i = 0; i < out.length; i++){
  147. //System.out.printf("%x ", out[i]);
  148. }
  149. for ( int i = 0; i < srcByte.length; i++){
  150. src[i] = srcByte[i] & 0xff;
  151. //System.out.printf("%x ", src[i] );
  152. }
  153. System.out.println("해당 디렉토리나 파일이 없습니다.");
  154. }catch(IOException e){
  155. System.out.println("파일을 읽을수 없습니다.");
  156. }catch(Exception e){
  157. System.out.println("알수 없는 예외입니다.");
  158. }
  159. return out;
  160. }
  161.  
  162. public int[] getFaceLine(int faceIndex, int lineIndex){
  163. int[] out = new int[64];
  164. int[] temp = new int[64*this.height];
  165. temp = getFace(faceIndex);
  166. for(int i=0; i<64; i++){
  167. out[i] = temp[lineIndex*64+i];
  168. }
  169. return out;
  170. }
  171.  
  172. public int[] getFaces(int faceIndexFrom, int faceIndexTo, int x, int y){
  173. int[] out = new int[x*64 * y*this.height];
  174. //System.out.println(x*64 * y*this.height);
  175. int k = 0;
  176. int firstX = 0;
  177. while (k<out.length){
  178. for(int j=0; j<this.height; j++){
  179. for(int i=firstX; i<firstX+x; i++){
  180. int[] temp = new int[64];
  181. temp = getFaceLine(faceIndexFrom+i, j);
  182. for(int t=0; t<temp.length; t++){
  183. out[k++] = temp[t];
  184. }
  185. //System.out.println((k-1)+"!"+faceIndexFrom+i+"!"+j);
  186. }
  187. }
  188. firstX += x;
  189. }
  190. return out;
  191. }
  192.  
  193. public int getHeight(){
  194. return height;
  195. }
  196. }
  197.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:15: error: class CanvasRepaint is public, should be declared in a file named CanvasRepaint.java
public class CanvasRepaint {
       ^
Main.java:1: error: package org.eclipse.swt does not exist
import org.eclipse.swt.SWT;
                      ^
Main.java:2: error: package org.eclipse.swt.events does not exist
import org.eclipse.swt.events.PaintEvent;
                             ^
Main.java:3: error: package org.eclipse.swt.events does not exist
import org.eclipse.swt.events.PaintListener;
                             ^
Main.java:4: error: package org.eclipse.swt.layout does not exist
import org.eclipse.swt.layout.FillLayout;
                             ^
Main.java:5: error: package org.eclipse.swt.widgets does not exist
import org.eclipse.swt.widgets.Canvas;
                              ^
Main.java:6: error: package org.eclipse.swt.widgets does not exist
import org.eclipse.swt.widgets.Display;
                              ^
Main.java:7: error: package org.eclipse.swt.widgets does not exist
import org.eclipse.swt.widgets.Shell;
                              ^
Main.java:9: error: package org.eclipse.swt.graphics does not exist
import org.eclipse.swt.graphics.PaletteData;
                               ^
Main.java:10: error: package org.eclipse.swt.graphics does not exist
import org.eclipse.swt.graphics.Image;
                               ^
Main.java:11: error: package org.eclipse.swt.graphics does not exist
import org.eclipse.swt.graphics.ImageData;
                               ^
Main.java:26: error: cannot find symbol
		Display display = new Display();
		^
  symbol:   class Display
  location: class CanvasRepaint
Main.java:26: error: cannot find symbol
		Display display = new Display();
		                      ^
  symbol:   class Display
  location: class CanvasRepaint
Main.java:27: error: cannot find symbol
	    Shell shell = new Shell(display);
	    ^
  symbol:   class Shell
  location: class CanvasRepaint
Main.java:27: error: cannot find symbol
	    Shell shell = new Shell(display);
	                      ^
  symbol:   class Shell
  location: class CanvasRepaint
Main.java:29: error: cannot find symbol
	    shell.setLayout(new FillLayout());
	                        ^
  symbol:   class FillLayout
  location: class CanvasRepaint
Main.java:31: error: cannot find symbol
	    Canvas canvas = new Canvas(shell, SWT.NONE);
	    ^
  symbol:   class Canvas
  location: class CanvasRepaint
Main.java:31: error: cannot find symbol
	    Canvas canvas = new Canvas(shell, SWT.NONE);
	                        ^
  symbol:   class Canvas
  location: class CanvasRepaint
Main.java:31: error: cannot find symbol
	    Canvas canvas = new Canvas(shell, SWT.NONE);
	                                      ^
  symbol:   variable SWT
  location: class CanvasRepaint
Main.java:36: error: cannot find symbol
	    PaletteData palette = new PaletteData(0xff0000, 0x00ff00, 0x0000ff);
	    ^
  symbol:   class PaletteData
  location: class CanvasRepaint
Main.java:36: error: cannot find symbol
	    PaletteData palette = new PaletteData(0xff0000, 0x00ff00, 0x0000ff);
	                              ^
  symbol:   class PaletteData
  location: class CanvasRepaint
Main.java:37: error: cannot find symbol
	    ImageData sourceData = new ImageData(64, face.getHeight(), 24, palette);
	    ^
  symbol:   class ImageData
  location: class CanvasRepaint
Main.java:37: error: cannot find symbol
	    ImageData sourceData = new ImageData(64, face.getHeight(), 24, palette);
	                               ^
  symbol:   class ImageData
  location: class CanvasRepaint
Main.java:38: error: cannot find symbol
	    ImageData sourceData2 = new ImageData(64*xx, face.getHeight()*yy, 24, palette);
	    ^
  symbol:   class ImageData
  location: class CanvasRepaint
Main.java:38: error: cannot find symbol
	    ImageData sourceData2 = new ImageData(64*xx, face.getHeight()*yy, 24, palette);
	                                ^
  symbol:   class ImageData
  location: class CanvasRepaint
Main.java:43: error: cannot find symbol
	    final Image source = new Image(display, sourceData);
	          ^
  symbol:   class Image
  location: class CanvasRepaint
Main.java:43: error: cannot find symbol
	    final Image source = new Image(display, sourceData);
	                             ^
  symbol:   class Image
  location: class CanvasRepaint
Main.java:44: error: cannot find symbol
	    final Image source2 = new Image(display, sourceData2);
	          ^
  symbol:   class Image
  location: class CanvasRepaint
Main.java:44: error: cannot find symbol
	    final Image source2 = new Image(display, sourceData2);
	                              ^
  symbol:   class Image
  location: class CanvasRepaint
Main.java:46: error: cannot find symbol
	    canvas.addPaintListener(new PaintListener() {
	                                ^
  symbol:   class PaintListener
  location: class CanvasRepaint
30 errors
stdout
Standard output is empty