線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:1230
推到 Plurk!
推到 Facebook!

編譯出現問題

尚未結案
dullvictory
一般會員


發表:5
回覆:2
積分:1
註冊:2005-08-16

發送簡訊給我
#1 引用回覆 回覆 發表時間:2005-08-23 23:46:05 IP:59.113.xxx.xxx 未訂閱
    #include 
#include 
#include 
#include 
#include "jpeglib.h"
#include "bmplib.h"
#define MAX_PATH 270        GLOBAL(int)
void jpg_save_dib_file ( FILE *fp, uchar *dib, int quality, int progression )
{
    int   i, j;
    int   bmp_row_bytes;
    uchar * bmp_image;
    uchar * src, * dest;
    DIB   new_dib;        struct jpeg_compress_struct cinfo;
    struct jpeg_error_mgr jerr;        JSAMPLE * image_buffer;
    JSAMPROW row_pointer[1];      /* pointer to JSAMPLE row[s] */
    int row_stride;               /* physical row width in image buffer */
    int image_height;
    int image_width;        // DIB??
    image_width = *(long  *)(dib 4);
    image_height = *(long  *)(dib 8) ;        // 24 bit 尬?????
    new_dib = bmp_convert_dib_24color( dib ) ;
    if( new_dib == NULL ) return FALSE;
    dib = new_dib;        /* JPEG?????????????????? */
    cinfo.err = jpeg_std_error(&jerr);
    jpeg_create_compress(&cinfo);        jpeg_stdio_dest(&cinfo, fp);        /* ???????????? */
    cinfo.image_width  = image_width;     /* ???????抵????? */
    cinfo.image_height = image_height;
    cinfo.input_components = 3;           /* ??抵?????? */
    cinfo.in_color_space = JCS_RGB;       /* 尬?????? */        /* ????????????????? */
    jpeg_set_defaults(&cinfo);        /* ?????????????? */
    jpeg_set_quality(&cinfo, quality, TRUE );        /* Progression ????????  */
    if( progression )  jpeg_simple_progression (&cinfo);        /* ???? */
    jpeg_start_compress(&cinfo, TRUE);        row_stride = image_width * 3; /* JSAMPLEs per row in image_buffer */
    image_buffer = malloc( row_stride );
    bmp_row_bytes = (image_width * 3   3) / 4 * 4;  // DWORD ??
    bmp_image = dib   40; // = sizeof(BITMAPINFOHEADER)        i = image_height - 1;
    while (cinfo.next_scanline < cinfo.image_height) {
        // BMP ?????置??怀?
        dest = image_buffer;
        src = &bmp_image[ i * bmp_row_bytes ];
        for( j = 0; j < image_width; j   ) {
            *dest   = src[ 2 ];
            *dest   = src[ 1 ];
            *dest   = src[ 0 ];
            src  = 3;
        }
        i--;            row_pointer[0] = image_buffer;
        jpeg_write_scanlines(&cinfo, row_pointer, 1);
    }        /* ???? */
    jpeg_finish_compress(&cinfo);        /* JPEG ??????????? */
    jpeg_destroy_compress(&cinfo);        free( image_buffer );
    image_buffer = 0;
    free( new_dib );
    return( TRUE );    }    int main( int argc, char *argv[] ) {
    int  arg_cou = 0, i;
    int  quality = 90;
    int  progression = 0;
    char *w_ptr;
    char inpfile[ MAX_PATH ];
    char outfile[ MAX_PATH ];
    FILE  *fp;
    DIB  dib;        for( i = 1; i < argc; i   ) {
        w_ptr = argv[ i ];
        if( *w_ptr == '/' || *w_ptr == '-' ) {
            int  c;
            w_ptr  ;
            c = toupper( *w_ptr   );
            if( *w_ptr == '=' ) w_ptr  ;
            switch( c ) {
              case 'Q':
                quality = atoi( w_ptr );
                break;
              case 'P':
                progression = TRUE;
                break;
              default:
                printf( "option (%c) is nothing!\n", c );
                break;
            }
            continue;
        }
        arg_cou  ;
        if( arg_cou == 1 ) {
            strcpy( inpfile, w_ptr );
            continue;
        }
        if( arg_cou == 2 ) {
            strcpy( outfile, w_ptr );
            continue;
        }
    }        if( arg_cou < 1 ) {
        printf( "\n\t>bmp2jpg input_file[.bmp] [output_file[.jpg]] [-Qnnn)][-P]\n\n");
        printf( "\t\t-P ... Progression\n");
        printf( "\t\t-Q ... Quality nnn:0?100(default=90)\n\n");
        exit(0);
    }        if( ( w_ptr = strchr( inpfile, '.' ) ) == 0 ) {
        strcat( inpfile, ".bmp" );
    }        if( arg_cou < 2 ) {
       strcpy( outfile, inpfile );
       if( w_ptr = strchr( outfile, '.' ) ) *w_ptr = 0;
    }
    if( ( w_ptr = strchr( outfile, '.' ) ) == 0 ) {
       strcat( outfile, ".jpg" );
    }        if( ( fp = fopen( inpfile, "rb" ) ) == 0 ) {
        printf( "input file (%s) not open!\n", inpfile );
        exit(1);
    }        // BMP ?????簿????DIB ???
    if( ( dib = bmp_read_dib_file( fp ) ) == NULL ) {
        fclose( fp );
        printf( "BMP file read error!\n" );
        exit(1);
    }
    fclose( fp );        // biBitCount 置 24 bit 尬????????
    if( *(DWORD *)(dib 14) != 24 && *(DWORD *)(dib 14) == 0 ) {
        DIB new_dib;
        if( ( new_dib = bmp_convert_dib_24color( dib ) ) == NULL ) {
            printf( "BMP format not support!\n" );
            exit(1);
        }
        free( dib );
        dib = new_dib;
    }        // JPEG ???????直????
    //   ???直????置啟??????????????
    if( ( fp = fopen( outfile, "wb" ) ) == 0 ) {
        printf( "output file (%s) not open!\n", outfile );
        exit(1);
    }        if( jpg_save_dib_file( fp, dib, quality, progression ) == FALSE ) {
        printf( "output JPEG file error!\n" );
    }
    fclose( fp );
    free( dib );
}     
不好意思..小弟有個問題想請問大家 GLOBAL(int)--->代表什麼意思呢?以及使用的時機呢? 在編譯過程中 void jpg_save_dib_file ( FILE *fp, uchar *dib, int quality, int progression )--->會出現Declaration syntax error是那裡出現錯誤了呢? 請高手解惑..感恩..
bass15
高階會員


發表:24
回覆:171
積分:119
註冊:2003-10-27

發送簡訊給我
#2 引用回覆 回覆 發表時間:2005-08-26 00:47:15 IP:61.59.xxx.xxx 未訂閱
因為你沒定義uchar吧... 程式前面加上這一行試試  
 
typedef  unsigned char uchar;
bass15
高階會員


發表:24
回覆:171
積分:119
註冊:2003-10-27

發送簡訊給我
#3 引用回覆 回覆 發表時間:2005-08-26 00:50:24 IP:61.59.xxx.xxx 未訂閱
GLOBAL(int);
dullvictory
一般會員


發表:5
回覆:2
積分:1
註冊:2005-08-16

發送簡訊給我
#4 引用回覆 回覆 發表時間:2005-08-26 19:21:14 IP:59.113.xxx.xxx 未訂閱
謝謝..高手的..回應... 只是..我加上 typedef unsigned char uchar;也是沒有用.. 再 GLOBAL(int)加上..分號也沒有.用...請高手再幫我看看.. 我現在再附上..點H檔..這樣對高手比較好判認..有兩個點H檔..幫幫忙. //bmplib.h #ifndef BITMAPINFOHEADER /* ????windows.h ?? */ #define TRUE 1 #define FALSE 0 typedef unsigned char BYTE; typedef unsigned short WORD; typedef unsigned long DWORD; typedef long LONG; typedef struct tagRGBQUAD { BYTE rgbBlue; BYTE rgbGreen; BYTE rgbRed; BYTE rgbReserved; } RGBQUAD; // DLL ??????? #ifndef EXPORT_OPTION #ifdef MAKEVBDLL #define EXPORT_OPTION __declspec(dllexport) __stdcall #define MAKEDLL #else #ifdef MAKEDLL #define EXPORT_OPTION __declspec(dllexport) #else #define EXPORT_OPTION #endif #endif #endif /* constants for the biCompression field */ #define BI_RGB 0L #define BI_RLE8 1L #define BI_RLE4 2L #define BI_BITFIELDS 3L typedef struct tagBITMAPFILEHEADER { WORD bfType; DWORD bfSize; WORD bfReserved1; WORD bfReserved2; DWORD bfOffBits; } BITMAPFILEHEADER; typedef struct tagBITMAPINFOHEADER{ DWORD biSize; LONG biWidth; LONG biHeight; WORD biPlanes; WORD biBitCount; DWORD biCompression; DWORD biSizeImage; LONG biXPelsPerMeter; LONG biYPelsPerMeter; DWORD biClrUsed; DWORD biClrImportant; } BITMAPINFOHEADER; #endif /* ???????? */ typedef unsigned char uchar; typedef unsigned int uint; typedef char * DIB; DIB bmp_read_dib_file( FILE *fp ) ; DIB bmp_read_dib_filename( char *filename ) ; int bmp_save_dib_file( FILE *fp, DIB dib ) ; int bmp_save_dib_filename( char *filename, DIB dib ) ; DIB bmp_expand_dib_rle( DIB dib ) ; DIB bmp_compress_dib_rle( DIB dib ); DIB bmp_convert_dib_24color( DIB dib ); //jpeglib.h /* jconfig.vc --- jconfig.h for Microsoft Visual C on Windows 95 or NT. */ /* see jconfig.doc for explanations */ #define HAVE_PROTOTYPES #define HAVE_UNSIGNED_CHAR #define HAVE_UNSIGNED_SHORT /* #define void char */ /* #define const */ #undef CHAR_IS_UNSIGNED #define HAVE_STDDEF_H #define HAVE_STDLIB_H #undef NEED_BSD_STRINGS #undef NEED_SYS_TYPES_H #undef NEED_FAR_POINTERS /* we presume a 32-bit flat memory model */ #undef NEED_SHORT_EXTERNAL_NAMES #undef INCOMPLETE_TYPES_BROKEN /* Define "boolean" as unsigned char, not int, per Windows custom */ #ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */ typedef unsigned char boolean; #endif #define HAVE_BOOLEAN /* prevent jmorecfg.h from redefining it */ #ifdef JPEG_INTERNALS #undef RIGHT_SHIFT_IS_UNSIGNED #endif /* JPEG_INTERNALS */ #ifdef JPEG_CJPEG_DJPEG #define BMP_SUPPORTED /* BMP image file format */ #define GIF_SUPPORTED /* GIF image file format */ #define PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */ #undef RLE_SUPPORTED /* Utah RLE image file format */ #define TARGA_SUPPORTED /* Targa image file format */ #define TWO_FILE_COMMANDLINE /* optional */ #define USE_SETMODE /* Microsoft has setmode() */ #undef NEED_SIGNAL_CATCHER #undef DONT_USE_B_MODE #undef PROGRESS_REPORT /* optional */ #endif /* JPEG_CJPEG_DJPEG */
bass15
高階會員


發表:24
回覆:171
積分:119
註冊:2003-10-27

發送簡訊給我
#5 引用回覆 回覆 發表時間:2005-08-27 01:27:18 IP:61.59.xxx.xxx 未訂閱
 
GLOBAL(int)
void jpg_save_dib_file ( FILE *fp, uchar *dib, int quality, int progression )
改成    bool jpg_save_dib_file ( FILE *fp, uchar *dib, int quality, int progression )
試試看
dullvictory
一般會員


發表:5
回覆:2
積分:1
註冊:2005-08-16

發送簡訊給我
#6 引用回覆 回覆 發表時間:2005-08-29 18:25:39 IP:59.113.xxx.xxx 未訂閱
謝謝上面大大的回覆。。。 我試了妳說的方法。。 但還是不行呀。。。。 好怪呀。。。><
系統時間:2024-05-02 7:48:03
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!