Monday, December 16, 2013

24비트 비트맵을 디더링된 16비트 비트맵으로 변환 (Convert 24bit bitmap to 16bit with dithering)

아래 그림은 원본임 (Original 25bit bmp)



24비트 이미지를 포토샵에서 16bit bmp 파이롤 저장하면 병신같은 결과가 나타난다.


아래그림은 포토샵에서 저장한것. (16bit bmp from photoshop)



포토샵은 16비트 이미지 저장을 시키면 그냥 모자란 컬러들을 버린다.

그래서 그라데이션 표현이 계단이된다.

디더링을 하면 해결되는데 문제는 디더링은 256 color 나 1bit 컬러로 Color space를 변환할때만 된다는것이고 16bit bmp  저장시에는 그런 옵션이 없다.

따라서 별도의 프로그램을 사용하면 되는데, 그것은 바로..



16bit bmp converted by "ReduceBitDepthCpp.exe"


사용 방법은 매우 간다.

명령창에서 ReduceBitDepthCPP -f bmp  source.bmp out.bmp  식으로 실행하면 된다.



Tuesday, November 26, 2013

STM32F103 내부 플래시 메모리 읽기 쓰기 ( Read, write internal flash memory )


// 헤더파일 추가
#include "stm32f10x_flash.h"

// 소스추가  stm32f10x_flash.c



    // 마지막 블럭에 넣는것으로 가정

    // low(LD),medium(MD) density는 블럭이 1KB, High(HD) density는 2KB 단위임.
 

    //HD 이면서 메모리가 512KB 인경우 마지막 블럭은 255번임
    // 어드레스는 0x08000000 + 255* 2048 => 0x0807F800
 
    #define StartAddr ((u32)0x0807F800)
    #define EndAddr ((u32)0x0807F8FF)
 

    //HD 이면서 메모리가 64KB 인경우 마지막 블럭은 255번임
    // 어드레스는 0x08000000 + 63* 2048 => 0x0801F800
 
    #define StartAddr ((u32)0x0801F800)
    #define EndAddr ((u32)0x0801F8FF)
 


    // MD 이면서 메모리가 64KB 인경우 마지막 블럭은 63번임
    // 어드레스는 0x08000000 + 63* 1024 => 0x0800FC00
 
    #define StartAddr ((u32) 0x0800FC00)
    #define EndAddr ((u32) 0x0800FCFF)
 




//구조체 읽기 쓰기:

typedef struct
{
    unsigned char a;
    unsigned char b;
    unsigned char c;

} TEST_STRUCT;




void test_read()
{
 
    // 구조체 읽기:
    TEST_STRUCT t;

    memcpy( &t, (TEST_STRUCT* ) StartAddr, sizeof( t ));
 
    TEST_STRUCT x;
    memcpy( &x, &t, sizeof(t));
 
    // 이제 t.a, t.b, t.c 에 값이 들어있음.
}

void test_write()
{
 
   
    // 구조체 쓰기
    TEST_STRUCT w;
 
    w.a = 1;
    w.b = 2;
    w.c = 3;
   
 
    unsigned int * p_w = (unsigned int *)&w;
    int byte_align  = 0;
    if( (sizeof(w) % 4) > 0)
        byte_align = 1; // 구조체가 32비트단위가 아닌경우 마지막 떨거지들에 대한처리.

    FLASH_Unlock();
    FLASH_ErasePage(StartAddr);

    for( int i=0; i< sizeof( w ) / 4 + byte_align ; i++)
    {
        FLASH_ProgramWord(StartAddr + (i*4) ,  p_w[i]  );
    }
    FLASH_Lock();
   
}


HAL 버전에서는

#include "stm32f1xx_hal_flash.h"

 
    #define StartAddr ((unsigned int)0x0807F800)
    #define EndAddr ((unsigned int)0x0807F8FF)
    HAL_FLASH_Unlock();

    FLASH_PageErase( StartAddr );
    HAL_FLASH_Program( FLASH_TYPEPROGRAM_WORD, StartAddr, 1234);
    HAL_FLASH_Lock();




Sunday, June 2, 2013

XLSX 파일 읽기

ADO로 xls 파일은 쉽게 열어서 읽을 수 있지만 xlsx 파일을 ADO로 여는것은 사실상 불가능하다.

특히 배포용 프로그램을 만든다면 이건 방법이 없다.

따라서 다른 방법을 찾아야 하는데 다음과 같은 이유로 해결이 가능하다.

1. xlsx 파일은 zip 압축 파일이고 풀면 xml 들이 나온다.

2. 각 xml  들 중에서 내용만 추출한다면 SharedString xml 과 worksheet xml 만 분석하면된다.

이 방법으로 codeproject.com 에서 xlsx 로 검색하면 소스들이 나온다.

나는 일반적인 xml parser를 이용하여 이를 대신하여 프로그램을 작성하려 하고 있고

곧 소스를 올릴 예정이다.


Wednesday, May 15, 2013

ASUS N56V 노트북에 SSD 장착, Windows 7 설치

기본적으로 N56V 에는 등신같은 Windows 8 이 설치되어있다.

물건을 사자마자 SSD 도 장착했고 Windows 7 을 설치하려 했더니 Starting Windows 라고 나오더니 뻣어버린다.

Bios setup에서 CSM 을 Enable 시키고 pxe 뭐시기도 Enable 시키고 설치하면 설치가 된다.

끝~


Tuesday, May 7, 2013

dialogic api 로 녹음중 통화 끊김 감지. dialogic api detect disconnected using dual tone


dialogic global call api를 이용한 녹음.

녹음 중 전화를 끊어버린 상황을 감지하는 소스플그램임.


This source program presents how to detect disonnected while recording.

dual tone (480, 30, 620, 40) is korean standard. find your self what tone using in your country.




//CH_DEV는 LINE 번호임. 1채널인경우 1임.

#define CH_DEV 1


CString CDialogicLib::Record(CString savefilename, int timeout_sec )
{
 CString result="";
 DV_TPT tpt[10];            /* termination parameter table */
 DX_XPB xpb;

 xpb.nSamplesPerSec = DRT_11KHZ;
 xpb.wFileFormat = FILE_FORMAT_WAVE;
 xpb.wDataFormat = DATA_FORMAT_ALAW;
 xpb.wBitsPerSample = 8;

 #define TID_1    101

 dx_clrtpt(tpt,4);

 tpt[0].tp_type   = IO_CONT;
 tpt[0].tp_termno = DX_MAXDTMF;
 tpt[0].tp_length = 1;
 tpt[0].tp_flags  = TF_MAXDTMF;

 // Terminate on Loop Current Drop (call disconnect)
 tpt[1].tp_type = IO_CONT;
 tpt[1].tp_termno = DX_LCOFF;    
 tpt[1].tp_length = 1;          //  I have also tried 3
 tpt[1].tp_flags = TF_LCOFF;

 tpt[2].tp_type = IO_CONT;
 tpt[2].tp_termno = DX_MAXTIME;        /* Function Time */
 tpt[2].tp_length = (timeout_sec * 10);    /* 10 seconds (100 msec resolution timer) */
 tpt[2].tp_flags = TF_MAXTIME;        /* Edge-triggered */

 tpt[3].tp_type = IO_EOT;
 tpt[3].tp_termno = DX_TONE;
 tpt[3].tp_length = TID_1;
 tpt[3].tp_flags = TF_TONE;
 tpt[3].tp_data = DX_TONEON;


 dx_deltones(CH_DEV);
 dx_blddt(TID_1, 480, 30, 620, 40,TN_LEADING );
 dx_addtone(CH_DEV,NULL,0);
 dx_enbtone( CH_DEV, TID_1, DM_TONEON | DM_TONEOFF );

 dx_clrdigbuf(CH_DEV);

 dx_setevtmsk(CH_DEV, GCEV_DISCONNECTED);

 /* Start 11KHz A-law recording */
 if (dx_recwav(CH_DEV, savefilename, tpt,   &xpb,PM_TONE|EV_SYNC) == -1)
 {
  return "ERROR";
 }
 else
 {
  dx_clrdigbuf(CH_DEV);


  switch(ATDX_TERMMSK(CH_DEV))
  {
  case TM_MAXDTMF:
   return "SUCCESS";
  case TM_LCOFF :
   result = "LCOFF";
   break;
  case TM_TONE:
   result ="TONE";
   break;
  case TM_MAXTIME:
   result = "MAXTIME";
   break;
  }
  return "UNKNOWN";
 }

}

Thursday, May 2, 2013

dx_gtcallid 가 전화번호를 못알아내는 경우. (dx_gtcallid not working)

Ring 이 3번 정도 울린 후에 dx_gtcallid 를 호출하면 상대방의 전화번호를 알 수 있다. Call dx_gtcallid after ring more then 3 times. example) if (dx_wtring(CH_DEV, 3, DX_OFFHOOK, 10000) != -1) { dx_gtcallid( ..... ); return true; } else return false; //timeout

Tuesday, April 23, 2013

V-Ray for Sketchup 에서 displacement 가 안될때 ( v-ray for sketchup displacement not working )

해결1. Displacement 는 물체가 Group이 되어있어야 된다. solution 1. convert to group for object, try render. 해결1. 1번 후에도 마찬가지라면 Surface 를 Reverse 시켜보자. solution 2. after solution 1, In sketchup. Reverse surface and try again. 그래도 안된다면 Sketchup 의 번전을 살펴보자. 8.0.3117 버전에는 displacement mapping 이 안되는 버그가 있는듯하다. Check your sketchup version. If you have 8.0.3117 then uninstall fucking that version. and install 8.0.4811 version or higher.