티스토리 툴바


Picture2011/06/08 14:11

석양 사진이 핸드폰 카메라 치곤 잘 나온 듯

이스탄블
Posted by Lonnie_Noel
Computer2008/06/24 20:16

이것만 이해할수 있다면 다 그릴수 있습니다.
전체 소스를 보여드리고 싶지만 방대한 이유로 핵심만 공개합니다.

이것은 실제로 베지어 곡선을 그리는 재귀적 방식인데
이것을 4분할로 그리면 원이 되고 중심점이 양쪽 끝점의 중앙에 위치하면
직선이 되며 3개의 점이 한곳에 모이면 점이 되고
중심점이 양쪽 끝점의 중앙이 아닌 곳에 있으면 그에 가까워지는 베지어 곡선이
됩니다.
재귀적 단계는 16단계까지만 했으며 더 이상은 최적화에 문제가 있습니다.
그리고 설마 해상도를 2000x2000이상 사용하시는 분은 없을테니까....

점 찍는것은 어떻게 하는지 아실거라 생각되며.....

#define DEF_Bezier_Constant0 (2.0)
void MZ_DFB_Bezier_(t_DFB *s_Handle, int s_Color, float *s_x, float *s_y)
{
 float s_fx[3], s_fy[3], s_ix[3], s_iy[3];
 s_fx[0] = ((s_x[1]  + s_x[0] ) / DEF_Bezier_Constant0)  , s_fy[0] = ((s_y[1]  + s_y[0] ) / DEF_Bezier_Constant0);
 s_fx[2] = ((s_x[2]  + s_x[1] ) / DEF_Bezier_Constant0)  , s_fy[2] = ((s_y[2]  + s_y[1] ) / DEF_Bezier_Constant0);
 s_fx[1] = ((s_fx[2] + s_fx[0]) / DEF_Bezier_Constant0)  , s_fy[1] = ((s_fy[2] + s_fy[0]) / DEF_Bezier_Constant0);
 if(((int)s_fx[0] == (int)s_fx[2] && (int)s_fy[0] == (int)s_fy[2]))MZ_DFB_DrawPixel(s_Handle, s_Color, (int)s_fx[1], (int)s_fy[1]);
 else
 {
  s_ix[0] = s_x[0] , s_iy[0] = s_y[0];
  s_ix[1] = s_fx[0], s_iy[1] = s_fy[0];
  s_ix[2] = s_fx[1], s_iy[2] = s_fy[1];
  MZ_DFB_Bezier_(s_Handle, s_Color, &s_ix[0], &s_iy[0]); 
  s_ix[0] = s_fx[1], s_iy[0] = s_fy[1];
  s_ix[1] = s_fx[2], s_iy[1] = s_fy[2];
  s_ix[2] = s_x[2] , s_iy[2] = s_y[2];
  MZ_DFB_Bezier_(s_Handle, s_Color, &s_ix[0], &s_iy[0]); 
 }
} 

void MZ_DFB_Bezier(t_DFB *s_Handle, int s_Color, int *s_x, int *s_y)
{
 float s_fx[3], s_fy[3];
 int s_Count;
 for(s_Count = 0;s_Count < 3;s_Count++)s_fx[s_Count] = (float)s_x[s_Count], s_fy[s_Count] = (float)s_y[s_Count];
 MZ_DFB_Bezier_(s_Handle, s_Color, &s_fx[0], &s_fy[0]);
}

이것은 위의 소스를 응용한 직선(사선) 그리기를 구현한겁니다.

static void __DrawLine__(int s_Color, float s_x1, float s_y1, float s_x2, float s_y2, int s_Level)
{ /* Call by call level 16 optimize draw line : JaeHyuk algorithm ^^ */
 float s_cx = (s_x1 + s_x2) / 2.0, s_cy = (s_y1 + s_y2) / 2.0;
 if(((int)s_x1 == (int)s_x2 && (int)s_y1 == (int)s_y2) || s_Level > 16)DrawPixel(s_Color, (int)s_cx, (int)s_cy);
 else
 {
  s_Level++;	
  __DrawLine__(s_Color, s_x1, s_y1, s_cx, s_cy, s_Level); __DrawLine__(s_Color, s_cx, s_cy, s_x2, s_y2, s_Level);
 }
}

static void DrawLine(int s_Color, int s_x1, int s_y1, int s_x2, int s_y2)
{
 __DrawLine__(s_Color, (float)s_x1, (float)s_y1, (float)s_x2, (float)s_y2, 0);
}

이것은 전통적인 원을 그리는 소스입니다.

static void DrawCircle(int s_Color, int s_x, int s_y, int s_r)
{
 double s_Pi, s_Grid = 1.0 / ((double)s_r), s_sinX, s_cosY; 
 for(s_Pi = 0.0;s_Pi < (DEF_2PI / 4.0);s_Pi += s_Grid)
 {
  s_sinX = sin(s_Pi) * (double)s_r; s_cosY = -cos(s_Pi) * (double)s_r;	 
  DrawPixel(s_Color, (int)(s_x + s_sinX), (int)(s_y + s_cosY));
  DrawPixel(s_Color, (int)(s_x - s_sinX), (int)(s_y + s_cosY));
  DrawPixel(s_Color, (int)(s_x + s_sinX), (int)(s_y - s_cosY));
  DrawPixel(s_Color, (int)(s_x - s_sinX), (int)(s_y - s_cosY));
 }
}










위 정보는 KLDP에서 발취 했으며 원본 링크는 다음과 같습니다.
http://kldp.org/node/21471#comment-46222



Posted by Lonnie_Noel
Computer2008/06/23 18:46

사용자 삽입 이미지


Posted by Lonnie_Noel
Computer2008/06/17 10:24
CC = gcc
CFLAGS = -Wall -O2
all : calctest
calctest : calctest.o addsub.o muldiv.o
 $(CC) $(CFLAGS) -o $@ $^
calctest.o : calctest.c addsub.h muldiv.h
 $(CC) $(CFLAGS) -c $<
addsub.o : addsub.c addsub.h
 $(CC) $(CFLAGS) -c $<
muldiv.o : muldiv.c muldiv.h
 $(CC) $(CFLAGS) -c $*.c
clean :
 rm -f *.o calctest

위와 같은 Makefile 을 아래와 같이 간략화 할 수 있다.
 

CC = gcc
CFLAGS = -Wall -O2

all : calctest

calctest : calctest.o addsub.o muldiv.o
#calctest.o : calctest.c addsub.h muldiv.h
#addsub.o : addsub.c addsub.h
#muldiv.o : muldiv.c muldiv.h

clean :
 rm -f *.o calctest


주석은 #


clean:   공백   <- dependency 없이 쓰기때문에 clean밑은 그냥 실행된다 (dependency없이)

GNUmakefile, makefile, Makefile 세가지중 한가지로 작성 가능하며 순서대로 우선순위로 실행

실행은  make   ->all: 이 실행되며   make clean으로 clean: 실행가능

[구조]
target : dependency
rule

make파일의 이점은 수정된 파일만 찾아서 재 컴파일 가능하다

touch 파일이름 - 최근 수정된 것 처럼 날짜 갱신

shell에서 printf와 같은 명령은 echo 내용

makefile에서 명령을 안보이고 결과만 출력하고 싶다면 @를 붙여주면 된다.
ex>  @echo  or  @gcc

make파일은 한 라인을 쉘 명령으로 인식하기 때문에 한 라인에 한 명령을 넣어야 한다.

한줄에 이어지는 명령을 이어서 써야함
ex>  cp calctest /tmp
       cd /tmp && ls -l
&&   <- 앞 명령이 성공시 다음명령 실행
;  , :   <- 실패해도 다음명령으로 넘어감
\(역슬레쉬)  <- 줄내림

Makefile은 명령이 성공해야 다음 명령으로 넘어가는 속성이 있음

각 라인에 - 을 붙여 명령 실패 무시 가능

다음과 같은 shell 명령어도 가능 (디렉토리 없을때 만들기)
if[ ! -d /tmp/software]
then
mkdir /tmp/software
fi

변수선언
CC = gcc  #컴파일러는 gcc
$(CC) -o calctest.c

반복사항 치환하기
calctest : calctest.o add.o sub.o muldiv.o
$(CC) -o $^       <- $^ 는 위에 나온 calctest.o add.o sub.o muldiv.o를 뜻함

특정 Makefile로 make하기
make -f <참조할 Make파일 이름>
Posted by Lonnie_Noel
Computer2008/06/03 09:31

<출력 화면>

사용자 삽입 이미지

결과 화면

<소스 >
int add_int(int x, int y) { return (x+y); }
int sub_int(int x, int y) { return (x-y); }
int mul_int(int x, int y) { return (x*y); }
int div_int(int x, int y) { return (x/y); }

float add_float(float x, float y) { return (x+y); }
float sub_float(float x, float y) { return (x-y); }
float mul_float(float x, float y) { return (x*y); }
float div_float(float x, float y) { return (x/y); }


void main(){
  int a = 100, b = 20, c;
  float fa = 50.2, fb = 20.4, fc = 0.0;

  c = fun(add, int, a, b ); out(add, int, c );
  c = fun(div, int, a, b ); out(div, int, c );
  c = fun(mul, int, a, b ); out(mul, int, c );

  fc = fun(add, float, fa, fb); out(add, float, fc );
  fc = fun(div, float, fa, fb); out(div, float, fc );
  fc = fun(mul, float, fa, fb); out(mul, float, fc );
}

more..


   

Posted by Lonnie_Noel
TAG C, 매크로