⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ras2vec.c

📁 就是将BMP文件转换为DXF格式的文件
💻 C
📖 第 1 页 / 共 2 页
字号:
/*
 *  Ras2Vec by Davide Libenzi ( Raster to vector conversion program )
 *  Copyright (C) 1999  Davide Libenzi
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 *  Davide Libenzi <davidel@maticad.it>
 *
 */

#include<windows.h>
#include<windowsx.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<ctype.h>
#include<malloc.h>
#include<math.h>
#include<float.h>
#include<time.h>
#include<sys/types.h>
#include<sys/stat.h>
#include"ras2vec.h"
#include"dbll_list.h"
#include"bmputil.h"
#include"filescan.h"
#include"himage.h"
#include"vectorize.h"
#include"thinner.h"
#include"log.h"
#include"util.h"
#include"tiffio.h"
#include"tiffext.h"



/* #define DEMO_VERSION */



#define VERSION_HI                  1
#define VERSION_LO                  1
#define MAX_DEMO_SIZE               202
#define CENTER_LINE                 1
#define DOUBLE_LINE                 2
#define DXF_OUTPUT                  1
#define HPGL_OUTPUT                 2
#define POLYLINE_OUTPUT             3
#define EMF_OUTPUT                  4
#define MAX_TOLLERANCE              10.0

#define bound_value(v,mn,mx)        (min((mx),max((mn),(v))))




static int CALLBACK log_proc(char *str_format, va_list args);
static int CALLBACK err_proc(char *str_format, va_list args);
static void     tiff_warning_handler(const char *module, const char *fmt, va_list ap);
static void     tiff_error_handler(const char *module, const char *fmt, va_list ap);
static int      check_file_size(char *file_name, long int max_size_in_kb);




/* OK */
static int CALLBACK log_proc(char *str_format, va_list args)
{

    return (vfprintf(stdout, str_format, args));

}

/* OK */
static int CALLBACK err_proc(char *str_format, va_list args)
{

    return (vfprintf(stderr, str_format, args));

}

/* OK */
static void     tiff_warning_handler(const char *module, const char *fmt, va_list ap)
{

    char           *buffer;
    char            header_str[256];

    module = (module == NULL) ? "tifflib" : module;
    sprintf(header_str, "- %s warning :", module);
    if ((buffer = (char *) malloc(strlen(header_str) + strlen(fmt) + 2)) == NULL)
        return;
    sprintf(buffer, "%s %s\n", header_str, fmt);
    log_vprintf(buffer, ap);
    free(buffer);

}


/* OK */
static void     tiff_error_handler(const char *module, const char *fmt, va_list ap)
{

    char           *buffer;
    char            header_str[256];

    module = (module == NULL) ? "tifflib" : module;
    sprintf(header_str, "- %s error :", module);
    if ((buffer = (char *) malloc(strlen(header_str) + strlen(fmt) + 2)) == NULL)
        return;
    sprintf(buffer, "%s %s\n", header_str, fmt);
    log_vprintf(buffer, ap);
    free(buffer);

}


/* OK */
static int      check_file_size(char *file_name, long int max_size_in_kb)
{

    struct _stat    file_stat;

    _stat(file_name, &file_stat);
    return ((file_stat.st_size > (max_size_in_kb * 1024)) ? FALSE : TRUE);

}


/* OK */
static int      make_conversion_cntline(char *img_file_name, double pnt_error_tollerance,
                        double poly_lenght_factor, char *out_poly_file_name)
{

    int             use_a_copy = TRUE;
    time_t          start_time,
                    end_time;
    char            start_time_str[128],
                    end_time_str[128],
                    file_name_ext[MAX_PATH],
                    temp_img_file_name[MAX_PATH] = "";

    _splitpath(img_file_name, NULL, NULL, NULL, file_name_ext);
    if (stricmp(file_name_ext, ".tif") == 0)
    {
        GetTempFileName(".", "img", 0, temp_img_file_name);
        scr_printf("- reading tiff file %s to bmp file %s\n", img_file_name,
                temp_img_file_name);
        if (!tiff_file_to_bmp_file(img_file_name, temp_img_file_name))
        {
            remove(temp_img_file_name);
            log_printf("- error reading tiff file %s to bmp file %s\n", img_file_name,
                    temp_img_file_name);
            return (FALSE);
        }
        img_file_name = temp_img_file_name;
        use_a_copy = FALSE;
    }
#ifdef DEMO_VERSION
    if (!check_file_size(img_file_name, MAX_DEMO_SIZE))
    {
        if (strlen(temp_img_file_name) > 0)
            remove(temp_img_file_name);
        log_printf("- file %s too long for demo version\n", img_file_name);
        return (FALSE);
    }
#endif          // #ifdef DEMO_VERSION
    time(&start_time);
    scr_printf("- extracting vectors from file %s\n", img_file_name);
    if (!cntline_convert_file(img_file_name, use_a_copy, out_poly_file_name,
                    pnt_error_tollerance, poly_lenght_factor))
    {
        if (strlen(temp_img_file_name) > 0)
            remove(temp_img_file_name);
        log_printf("- error extracting vectors from file %s\n", img_file_name);
        return (FALSE);
    }
    time(&end_time);
    strcpy(start_time_str, ctime(&start_time));
    strcpy(end_time_str, ctime(&end_time));
    scr_printf("- file successfully converted\n"
            "- start conversion time ...: %s"
            "- end conversion time .....: %s"
            "- computation time ........: %lf sec\n", start_time_str,
            end_time_str, difftime(end_time, start_time));
    if (strlen(temp_img_file_name) > 0)
        remove(temp_img_file_name);
    return (TRUE);

}


/* OK */
static int      make_conversion_dblline(char *img_file_name, double pnt_error_tollerance,
                        double poly_lenght_factor, char *out_poly_file_name)
{

    time_t          start_time,
                    end_time;
    char            start_time_str[128],
                    end_time_str[128],
                    file_name_ext[MAX_PATH],
                    temp_img_file_name[MAX_PATH] = "";

    _splitpath(img_file_name, NULL, NULL, NULL, file_name_ext);
    if (stricmp(file_name_ext, ".tif") == 0)
    {
        GetTempFileName(".", "img", 0, temp_img_file_name);
        scr_printf("- reading tiff file %s to bmp file %s\n", img_file_name,
                temp_img_file_name);
        if (!tiff_file_to_bmp_file(img_file_name, temp_img_file_name))
        {
            remove(temp_img_file_name);
            log_printf("- error reading tiff file %s to bmp file %s\n", img_file_name,
                    temp_img_file_name);
            return (FALSE);
        }
        img_file_name = temp_img_file_name;
    }
#ifdef DEMO_VERSION
    if (!check_file_size(img_file_name, MAX_DEMO_SIZE))
    {
        if (strlen(temp_img_file_name) > 0)
            remove(temp_img_file_name);
        log_printf("- file %s too long for demo version\n", img_file_name);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -