MFC로 간단하게 이미지 뷰어

Posted at 2008/08/23 14:42 // in Programming // by Daniel

http://drcarter.tistory.com/entry/%ea%b ··· 596%25b4 에서 퍼왔습니다.

1. MFC Application 생성

    Application Type
        Single document, Document/View architecture support
 uncheck
    User Interface Features
        Thick frame, Initial status bar, System menu(
저는 귀찮아서 이것도 삭제) uncheck
   
2. Stdafx.h
파일을 열고 마지막 줄에 다음 추가

    #include "atlimage.h"

3. ChildView.h
파일을 열고 CChildView class 속성에 다음 추가

    CImage image;
    CString sFilename;
   
4. ChildView.cpp
파일을 열고 생성자에 다음 추가

    sFilename = L"";
   
5. Resource view
창에서 Menu 항목의 IDR_MAINFRAME  더블 클릭하고 File 메뉴 아래 Open... 메뉴 추가

6. Open...
메뉴 오른 클릭해서 Event handler 추가 선택, CChildView 추가한다.

7. CChildView::OnFileOpen() (
방금 추가한 Event handler)  다음 추가

    // Get image file name
   
LPCTSTR szFilter = _T("Image Files(*.BMP, *.GIF, *.JPG, *.PNG) | *.BMP;*.GIF;*.JPG;*.PNG | All Files(*.*)|*.*||");
    if(IDOK != dlg.DoModal()) return;
    CString sFilename = dlg.GetPathName();

    // Detaches the bitmap from the CImage object and destroys the bitmap if image already loaded
    if ( !image.IsNull() )
        image.Destroy();
    image.Load(sFilename);
    Invalidate();
    UpdateWindow();
   
8. CChildView::OnPaint()
 //TODO 아래에  다음 추가

    // Draw image if a source bitmap is currently loaded
    if ( !image.IsNull() ) {
        image.Draw(dc.m_hDC, 0, 0);
    }

9.
실행

크리에이티브 커먼즈 라이센스
Creative Commons License

코드에서 glibc 버전 알아내기

Posted at 2008/08/21 21:19 // in Programming // by Daniel

http://www.technovelty.org/linux/tips/glibc-version.html

실행중에 libc 버전을 봐야 할 경우, contstr을 쓰면 된다고 합니다

#include <stdio.h>

#include <unistd.h>

#include <alloca.h>

#include <string.h>


int main (void)

{

    size_t n = confstr (_CS_GNU_LIBC_VERSION, NULL, 0);

    if (n > 0)

    {

        char *buf = alloca (n);

        confstr (_CS_GNU_LIBC_VERSION, buf, n);

        printf("%s\n", buf);

    }

    return 0;

}

 

실행해 보면
 $ ./a.out
glibc 2.7

이렇게 나옵니다.
또는 돌리는 코드상에서가 아니고 콘솔에서 보고 싶다면 /lib/libc.so.6 파일을 실행해봐도 됩니다.
$ /lib/libc.so.6
GNU C Library stable release version 2.7, by Roland McGrath et al.
Copyright (C) 2007 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
Compiled by GNU CC version 4.2.3 (Ubuntu 4.2.3-2ubuntu7).
Compiled on a Linux >>2.6.24-14-server<< system on 2008-04-04.
Available extensions:
    crypt add-on version 2.1 by Michael Glad and others
    GNU Libidn by Simon Josefsson
    Native POSIX Threads Library by Ulrich Drepper et al
    BIND-8.2.3-T5B
For bug reporting instructions, please see:
<http://www.gnu.org/software/libc/bugs.html>.

그리고 LD_DEBUG를 이용하면 많은 정보를 볼 수 있습니다.

$ LD_DEBUG=help ls
Valid options for the LD_DEBUG environment variable are:

  libs        display library search paths
  reloc       display relocation processing
  files       display progress for input file
  symbols     display symbol table processing
  bindings    display information about symbol binding
  versions    display version dependencies
  all         all previous options combined
  statistics  display relocation statistics
  unused      determined unused DSOs
  help        display this help message and exit

To direct the debugging output into a file instead of standard output
a filename can be specified using the LD_DEBUG_OUTPUT environment variable.


예를 들어 아까의 a.out을 실행하면

$ LD_DEBUG=versions ./a.out
      1565:     checking for version `GLIBC_2.4' in file /lib/tls/i686/cmov/libc.so.6 [0] required by file ./a.out [0]
      1565:     checking for version `GLIBC_2.0' in file /lib/tls/i686/cmov/libc.so.6 [0] required by file ./a.out [0]
      1565:     checking for version `GLIBC_PRIVATE' in file /lib/ld-linux.so.2 [0] required by file /lib/tls/i686/cmov/libc.so.6 [0]
      1565:     checking for version `GLIBC_2.3' in file /lib/ld-linux.so.2 [0] required by file /lib/tls/i686/cmov/libc.so.6 [0]
      1565:     checking for version `GLIBC_2.1' in file /lib/ld-linux.so.2 [0] required by file /lib/tls/i686/cmov/libc.so.6 [0]
      1565:
      1565:     calling init: /lib/tls/i686/cmov/libc.so.6
      1565:
      1565:
      1565:     initialize program: ./a.out
      1565:
      1565:
      1565:     transferring control: ./a.out
      1565:
glibc 2.7
      1565:
      1565:     calling fini: ./a.out [0]
      1565:
      1565:
      1565:     calling fini: /lib/tls/i686/cmov/libc.so.6 [0]
      1565:

이런 식으로 나옵니다.
크리에이티브 커먼즈 라이센스
Creative Commons License

configure에서 --host와 --build의 차이

Posted at 2008/08/20 18:41 // in Programming // by Daniel

configure 스크립트에서 받는 옵션으로 --host, --build, --target이 있습니다.

만약에 빌드를 x86 리눅스 머신에서 하고 실제 실행은 리눅스이면서 eabi를 쓰고 ARM 플랫폼에서 실행하고 싶다면

./configure --target=arm-none-linux-gnueabi --host=arm-none-linux-gnueabi --build=linux

./configure --target=arm-none-linux-gnueabi --host=arm-none-linux-gnueabi --build=i486-pc-linux-gnu

이런식으로 할 겁니다.

--build : 내가 지금 작업하고 있는 컴파일 시스템 - 그러니까 코딩 작업하고 있는 호스트

--host : 빌드하고 나서 실행파일이 실행될 시스템을 명시합니다. 컴파일 결과물이 돌아갈 환경. 실제 타겟 이름. 예를 들어 arm-none-linux-

--target : (대부분 host와 같은 거이 일반적이고) 크로스 컴파일러를 빌드할 때 등에 쓰는 것으로 빌드된 파일이 실행됐을 때 내놓을 바이너리 포맷입니다.

target을 쓰는 경우는 예를 들어 x86 리눅스에서 ARM 컴파일러를 PowerPC에서 실행시킬 바이너리를 만든다면

./configure --target=arm-linux-gnu --host=powerpc-linux-gnu --build=i686-pc-linux-gnu

정도로 쓰면 됩니다.

영문으로 자세히 설명된 canadian cross http://www.airs.com/ian/configure/configure_6.html

http://kelp.or.kr/korweblog/stories.php?story=04/09/22/9919655

-------------

KLDP에서 퍼온 것

http://www.belgeler.org/autobook/autobook-Building-with-a-Cross-Compiler...

즉 Linux에서 빌드를 하는데 만드는 컴파일러가 dos에서 실행되는 컴파일러이고, 이 컴파일러의 출력코드는 mips용이라면
--build : linux
--host : dos
--target : mips
가 됩니다. 이런 경우를 canadian cross라고 하죠. 캐나다에 세 민족이 살아서 그런데나... 물론 이런 canadian cross는 library 때문에 빌드가 상당히 복잡해집니다.

기본적으로는 host, target, build를 모두 적어주어야 합니다. 단, 적어주지 않는 경우 config.guess script에서 나머지를 default로 현재 platform으로 설정합니다.

그래서
canadian cross 인 경우에는 --host, --target을 정확히 적어주어야 하고,
cross인 경우에는 --target 만을 정확히 적어주면 되고,
일반적인 경우에는 아무것도 적어주지 않아도 됩니다.

크리에이티브 커먼즈 라이센스
Creative Commons License

프로그램에 빌드 타임 기록하기

Posted at 2008/08/08 16:25 // in Programming // by Daniel


리눅스 계열의 경우 동작합니다.
make할 때마다 빌드시각을 version.c 파일을 생성해서 저장하고 그 파일에 있는 함수를 참조하게 해서 씁니다.

.PHONY:version clean

LD=gcc

test: test.o version.o
 ${LD} version.o test.o -o test


version.o:version.c version

version:
 @echo Making version information
 @echo -n 'const char* myversion(void) { const char* Build_Info  = "' > version.c
 @echo -n `date` >> version.c
 @echo '"; return Build_Info; }' >> version.c

clean:
 rm -f test test.o version.o

Makefile은 위와 같습니다.
version을 phony 타겟으로 지정해서 타겟에 상관없이 매번 생성케 했고
version.o가 version 타겟을 받으므로
test <- test.o, version.o <- version
의 빌드 의존성이 생겨서 최종바이너리인 test를 만들기 위해선 매번 version을 갱신하게 됩니다.
make version 하면
version.c 에 다음과 같이 써지게 됩니다.

const char* myversion(void) { const char* Build_Info  = "Fri Aug 8 16:19:58 KST 2008"; return Build_Info; }

test.c에 const char* myversion(void);로 선언해놓고 쓰면 됩니다.
예를 들어 다음과 같이

/* test.c */
#include <stdio.h>

const char* myversion(void);

int main()
{
    printf("version: %s\n", myversion());
    return 0;
}

테스트해보면 다음과 같이 됩니다.

[danielsong@raffaello test]$ make
cc    -c -o test.o test.c
Making version information
cc    -c -o version.o version.c
gcc version.o test.o -o test
[danielsong@raffaello test]$ ./test
version: Fri Aug 8 16:24:33 KST 2008

빌드한 시간이 찍히는 걸 볼 수 있습니다.


 




 

크리에이티브 커먼즈 라이센스
Creative Commons License

coredump를 이용한 gdb 디버깅 하기

Posted at 2008/07/11 17:45 // in Programming // by Daniel
http://ggamsso.springnote.com/pages/738667

coredump 설정하기
...

gdb에서 core불러오기

gdb --core=(생성된코어의경로) --se=(바이너리의파일경로)

크리에이티브 커먼즈 라이센스
Creative Commons License

Interactive linux kernel map

Posted at 2008/06/09 16:07 // in Programming // by Daniel

image

http://www.makelinux.net/kernel_map

크리에이티브 커먼즈 라이센스
Creative Commons License

PNPOLY - Point Inclusion in Polygon Test

Posted at 2008/06/09 09:24 // in Programming // by Daniel

http://www.ecse.rpi.edu/homepages/wrf/r ··· oly.html

n vertex로 이루어진 다각형 안에 포인트가 있는지 알아보는 코드입니다.

int pnpoly(int nvert, float *vertx, float *verty, float testx, float testy)
{ int i, j, c = 0; for (i = 0, j = nvert-1; i < nvert; j = i++) { if ( ((verty[i]>testy) != (verty[j]>testy)) && (testx < (vertx[j]-vertx[i]) * (testy-verty[i]) / (verty[j]-verty[i]) + vertx[i]) ) c = !c; } return c;
}

Argument Meaning
nvert Number of vertices in the polygon. Whether to repeat the first vertex at the end is discussed below.
vertx, verty Arrays containing the x- and y-coordinates of the polygon’s vertices.
testx, testy X- and y-coordinate of the test point.

크리에이티브 커먼즈 라이센스
Creative Commons License

간단한 php 사진 갤러리 소스

Posted at 2008/05/14 14:36 // in Programming // by Daniel

정말 간단한 php 웹 앨범 소스입니다.
php의 glob이라는 함수를 사용해서 파일 리스트 얻어와서 5장씩 보여줍니다.
페이지 레이아웃 같은 것 하나도 없는 아주 간단한 소스입니다.
보안 문제 있을수도 있으므로 주의.
소스에 한글 주석 달아놨습니다. 5년 전에 필요해서 만들었던 것.

사용법은 폴더를 만들고 사진 파일을 업로드하고 그 폴더에 제가 올린 php 파일 두개를 올려둡니다.
그리고 웹브라우저로 디렉토리를 보면 페이지별 5장씩 나옵니다.


사용예

image

크리에이티브 커먼즈 라이센스
Creative Commons License

TSP

Posted at 2008/04/17 18:23 // in Programming // by Daniel

image

개인적으로 정리하려고 올리는 글들

TSP 100개 도시 최적은 아니고 최적과 근접한 경로 찾음.

크리에이티브 커먼즈 라이센스
Creative Commons License

TSP 경과

Posted at 2008/04/16 02:43 // in Programming // by Daniel

image

30개 도시의 경우 최적경로를 찾았다 :-)

population은 1000

IPOP_CONTROL intermediate population은 30에서 시작해서 다양성이 줄어들 때마다 4개씩 증가.

MUTATION_RATE   0.015

SELECTION_UNIFORM_RANDOM 부모 선택 방법은 그냥 랜덤

VICTIM_PARENT 교체되는 타겟은 부모중에서 고르고, 추가로 혹시 best값이 부모였으면 베스트 빼고 랜덤선택하게 했다.

MUTATION_RATE_CONTROL 다양성이 줄어들면 Mutation rate을 증가시켰다.

ALIEN_INJECTION Mutation rate확률로 매 세대에 하나를 추가로 Alien injection을 했다. 다양성을 추가하기 위해

MUTATION_SWAP_CYCLE Mutation방식은 두개 포인트를 찍어서 그 두 포인트를 가지고 경로를 쭈욱 뒤집도록 했다.

 

전에 해봤던 친구들 말로는 다양성을 유지하기 위해 mutation rate도 관리하고 추가로 결혼시킬(selection) 타겟을 정할 때 다양성을 위해 좋은 녀석과 나쁜 녀석을 일부러 골라 결혼시켜야 한다고 한다.

fitness쪽은 계산에 버그가 있는지 일단 disable했다. 현재는 그냥 uniform 랜덤.

크리에이티브 커먼즈 라이센스
Creative Commons License