IT Nebula

블로그 이미지
별나라추장

Article Category

분류 전체보기 (2)
Java (1)
Server (0)

Recent Post

Recent Comment

Calendar

«   2025/12   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31

Archive

My Link

  • Total
  • Today
  • Yesterday

참고 URL : http://www.cyberciti.biz/faq/how-to-fix-x11-forwarding-request-failed-on-channel-0/


1. 현재상태.

a. Local (장비명 A)

- OS : Mac OS X Yosemite (10.10.4)

- IP : 172.31.xxx.xxx

b. Remote (장비명 B)

- OS : CentOS 5.10

- IP : 172.31.xxx.xxx


2. 원하는 결과

- B에서 X-window 프로그램을 구동하면 A의 모니터에 프로그램이 실행이된다.


3. Step

a. Linux 에서
(http://www.cyberciti.biz/faq/how-to-fix-x11-forwarding-request-failed-on-channel-0/ 참조)

- /etc/ssh/sshd_config 수정

$ sudo vi /etc/ssh/sshd_config 
--- modify two line ----
X11Forwarding yes
X11UseLocalhost no
----------------------
$ sudo /etc/init.d/sshd reload

- sudo yum install xauth

b. Mac OS에서

a. X Quartz  설치

- 방법 1 : Application -> Utility -> X11 실행 -> 2.7.7 설치 페이지로 이동 : 2.7.7에는 버그가 있다고 함.

- 방법 2 : http://xquartz.macosforge.org/trac/wiki/X112.7.8
  -> 2.7.8_rc1 설치

b. Logout + Login

c. Appliation -> Utility -> X11 실행

d. X11 Menu -> terminal

e. run this command on terminal

ssh -Y deploy@172.31.224.9 

f. X window application 실행.



and

0. 테스트 환경.

OS : OS X
CPU : 3.2G Intel Core i5
Mem : 16GB 1600MHz DDR3
Storage : HDD

source resolution : 1080 x 480
source format : PNG
target resolution : 720 x 320
target format : PNG


1. 이미지 개략 정보(width, height) 얻어오기.

비추천)

BufferedImage image = ImageIO.read(tempFile);
if(image.getWidth() != 140 || image.getHeight() != 140) {
   return simpleScriptResultView("프로필 사이즈는 140px x 140px 이어야 합니다.");
}

장점) 이미지 파일이 어떤 형식인지 구분하지 않고 바로 사용이 가능하다.

단점 ) 이미지 전체를 메모리로 불러온 후 이미지의 정보를 얻어오게 되므로 메모리 로딩에 시간이 많이 걸리게 된다.

추천)

Iterator<ImageReader> iter = ImageIO.getImageReadersBySuffix(suffix);
if (iter.hasNext()) {
    ImageReader reader = iter.next();
    try {
        ImageInputStream stream = new FileImageInputStream(orgFile);
        reader.setInput(stream);
        int width = reader.getWidth(reader.getMinIndex());
        int height = reader.getHeight(reader.getMinIndex());
    } catch (IOException e) {
     logger.warn("checkImageSize fail.", e);
    } finally {
        reader.dispose();
    }
} else {
    logger.debug("No reader found for given format: " + suffix);
}

장점 ) 이미지 전체를 메모리에 불러오지 않고도 헤더만 확인 후 바로 이미지의 기본 정보를 알 수 있다. 즉 훨씬 빠르다. (900kb 실사형 png에서 100배 가량의 속도향상)

단점) 이미지가 어떤 포맷인지 미리 확인해야 한다. (이미지 포맷은 아래에서 다시 설명.)


2. ContentType(포맷) 확인하기

비추천)

File orgFile = new File(path);
String contentType = orgFile.toURI().toURL().openConnection().getContentType();

추천)

String contentType = URLConnection.guessContentTypeFromStream(new BufferedInputStream(new FileInputStream(orgFile)));

결과) 두 경우 모두  contentType 에는  "image/png" 형식의 contentType을 얻을 수 있다.
파일크기 등에 따라 다르겠지만 후자가 훨씬 빠르다.(900kb 실사형 png에서 10배 가량의 속도향상)

앞 부분의 "image"를 떼고 뒷부분만 잘라서 사용하면 되겠다.


3ImageIO.read(File imageFile)

매우 무거운 작업임. file copy보다 수 십배는 오래 걸리는 작업이므로 사용하는 부분을 최소화 하는 것이 필요함. 개인적으로 테스트를 수행한 결과는 30배 가량 차이가 났음.


4. resize image

Image img = orgImg.getScaledInstance(width, height, Image.SCALE_SMOOTH);
BufferedImage resized = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
resized.getGraphics().drawImage(img, 0, 0 , null);
return resized;

1080->720의 비율로 줄이는 경우 위 코드가 ImageIO.read() 의 2배 걸렸음.


5. ImageWriter.write(IIOImage img)

4의 image resizing과 속도가 비슷함.


6. ImageWriter 생성

Iterator<ImageWriter> iter = ImageIO.getImageWritersByFormatName(saveFormat);
ImageWriter writer = iter.next();

충분히 빠르다고 판단됨.


7.  FileImageOutputStream 생성

FileImageOutputStream output = new FileImageOutputStream(resizedFile);
writer.setOutput(output);

충분히 빠르다고 판단됨.


8. File.createTempFile(String prefix, String suffix)

File.createTempFile("resized", "." + saveFormat);

의외로 많이 느림. file copy하는 정도로 느림. string 연산이 포함되었다 해도 예상을 넘음. 새로운 파일을 생성하는 것 자체가 많이 느리다고 생각이 됨.


- 2015.06.25


and