polygon<T> reproject_internal(polygon<T> const& poly, proj_transform const& proj_trans, unsigned int & n_err)
{
    polygon<T> new_poly;
    linear_ring<T> new_ext(poly.exterior_ring);
    unsigned int err = proj_trans.forward(new_ext);
    // If the exterior ring doesn't transform don't bother with the holes.
    if (err > 0 || new_ext.empty())
    {
        n_err += err;
    }
    else
    {
        new_poly.set_exterior_ring(std::move(new_ext));
        new_poly.interior_rings.reserve(poly.interior_rings.size());

        for (auto const& lr : poly.interior_rings)
        {
            linear_ring<T> new_lr(lr);
            err = proj_trans.forward(new_lr);
            if (err > 0 || new_lr.empty())
            {
                n_err += err;
                // If there is an error in interior ring drop
                // it from polygon.
                continue;
            }
            new_poly.add_hole(std::move(new_lr));
        }
    }
    return new_poly;
}
示例#2
0
static std::string rel_path(std::string const &path)
{
    std::string file;
    if (path.substr(0, 4) == "art/")
    {
        file = path.substr(4);
    }
    else
    {
        //  there must be an "art" folder in the path
        size_t pos = path.find_first_of("/art/");
        if (pos == std::string::npos)
        {
            throw std::runtime_error(std::string("Cannot make a reference to an asset not in an /art/ directory.\n") +
                path);
        }
        file = path.substr(pos + 5);
    }
    std::string ext = fileext(file);
    std::string subExt = new_ext(ext);
    return file.substr(0, file.size() - ext.size()) + subExt;
}
示例#3
0
文件: Musicin.c 项目: IMSoP/CDex
static void ParseArgs
(
		int				argc,
	    char**			argv,
		PMP2ENC_CONFIG	pConfig,
		BOOL*			pbDownMixToMono,
		BOOL*			pbByteSwap,
		CHAR*			lpszInPath,
		CHAR*			lpszOutPath
	)
{
	int		i=0;
	BOOL	bErr=FALSE;
	CHAR*	lpszProgName=argv[0];

	FLOAT	srate;
	int		brate;
//	long samplerate;

	// clear everything
	memset(lpszInPath,0,MAX_NAME_SIZE);
	memset(lpszOutPath,0,MAX_NAME_SIZE);
	memset(pConfig,0,sizeof(MP2ENC_CONFIG));

	// set defaults
	pConfig->dwVersion	= MP2ENC_CUR_IF_VERSION;
	pConfig->dwSize		= sizeof(MP2ENC_CONFIG);

	pConfig->dwSampleRate		= DFLT_SFQ;
	pConfig->dwMode				= DFLT_MOD;
	pConfig->dwBitrate			= DFLT_BRT;
							
	pConfig->bPrivate			= FALSE;		
	pConfig->bCRC				= FALSE;	
	pConfig->bCopyright			= FALSE;
	pConfig->bOriginal			= FALSE;

	pConfig->bUseVbr			= FALSE;
	pConfig->dwVbrQuality		= 0;

	pConfig->dwPsyModel			= 2;
	pConfig->dwQuickMode		= 1;

	pConfig->bWriteAncil		= FALSE;
	pConfig->bNoPadding			= FALSE;

	*pbDownMixToMono=FALSE;
	*pbByteSwap=FALSE;


	// process args
	while( ( ++i < argc ) && (bErr == FALSE) )
	{
		char c, *token, *arg, *nextArg;
		int  argUsed=0;

		token = argv[i];

		if(*token++ == '-')
        {
			if(i+1 < argc) nextArg = argv[i+1];
			else           nextArg = "";

			if (!*token)
			{
				// The user wants to use stdin and/or stdout
				if(lpszInPath[0] == '\0')       strncpy(lpszInPath, argv[i],MAX_NAME_SIZE);
				else if(lpszOutPath[0] == '\0') strncpy(lpszOutPath, argv[i],MAX_NAME_SIZE);
			} 

			while( ( c = *token++ ) )
            {
				if(*token /* NumericQ(token) */) arg = token;
				else                             arg = nextArg;

				switch(c)
                {
					case 'm':
						argUsed = 1;
						switch (*arg)
						{
							case 's': pConfig->dwMode = MP2ENC_MD_STEREO;		break;
							case 'd': pConfig->dwMode = MP2ENC_MD_DUALCHANNEL;	break;
							case 'j': pConfig->dwMode = MP2ENC_MD_JSTEREO;		break;
							case 'm': pConfig->dwMode = MP2ENC_MD_MONO;			break;
							default:
								MP2LibError("%s: -m mode must be s/d/j/m not %s\n",lpszProgName, arg);
								bErr= TRUE;
						}
					break;

					case 'p':
						pConfig->dwPsyModel = atoi(arg);
						argUsed = 1;
						if(pConfig->dwPsyModel<0 || pConfig->dwPsyModel>2)
						{
							MP2LibError("%s: -p model must be 1 or 2, not %s\n",lpszProgName, arg);
							bErr=TRUE;;
						}
					break;

					case 's':
						argUsed = 1;
						srate = (float)atof( arg );

						/* samplerate = rint( 1000.0 * srate ); $A  */
						pConfig->dwSampleRate = (long) (( 1000.0 * srate ) + 0.5);

						if (	(pConfig->dwSampleRate != 48000 ) ||
								(pConfig->dwSampleRate != 44100 ) ||
								(pConfig->dwSampleRate != 32000 ) ||
								(pConfig->dwSampleRate != 24000 ) ||
								(pConfig->dwSampleRate != 22050 ) ||
								(pConfig->dwSampleRate != 16000 ) )
						{
							MP2LibError("%s: -s invalid sampling frequency %d\n",lpszProgName, pConfig->dwSampleRate);
							bErr=TRUE;
						}
					break;

					case 'b': 
						argUsed = 1;
						pConfig->dwBitrate = atoi(arg);
					break;
					case 'c': pConfig->bCopyright = TRUE; break;
					case 'o': pConfig->bOriginal  = TRUE; break;
					case 'e': pConfig->bCRC		  = TRUE; break;
					case 'f': pConfig->dwPsyModel = 0   ; break;
					case 'r': pConfig->bNoPadding = TRUE; break;
					case 'q':
						argUsed = 1;
						pConfig->dwQuickMode = atoi (arg);
					case 'a':
						*pbDownMixToMono = TRUE;
						pConfig->dwMode  = MP2ENC_MD_MONO;
					break;
					case 'x': *pbByteSwap= TRUE;	break;
					case 'v':
						argUsed = 1;
						pConfig->bUseVbr = TRUE;
						pConfig->dwVbrQuality = atoi(arg);
					break;
					case 'h':
						usage();
					break;
					default:
						MP2LibError("%s: unrec option %c\n",lpszProgName, c);
						bErr = TRUE;
					break;
                }

				if(argUsed)
                {
                  if(arg == token)    token = "";   /* no more from token */
                  else                ++i;          /* skip arg we used */
                  arg = "";
                  argUsed = 0;
                }
            }
        }
		else
		{
			if(lpszInPath[0] == '\0')       strcpy(lpszInPath, argv[i]);
			else if(lpszOutPath[0] == '\0') strcpy(lpszOutPath, argv[i]);
			else
			{
				MP2LibError("%s: excess arg %s\n", lpszProgName, argv[i]);
				bErr=TRUE;
			}
		}
    }

  /* check for a valid bitrate */
//  if ( brate == 0 )
//    brate = bitrate[info->version][10];

//  if( (info->bitrate_index = BitrateIndex(brate, info->version)) < 0) err=1;

	if( bErr || lpszInPath[0] == '\0')
		usage();  /* If no infile defined, or err has occured, then call usage() */

	if( lpszOutPath[0] == '\0')
	{
		/* replace old extension with new one, 1992-08-19, 1995-06-12 shn */
		new_ext(lpszInPath, DFLT_EXT, lpszOutPath);
	}
}
示例#4
0
void parse_args (int argc, char **argv, frame_info * frame, int *psy,
        unsigned long *num_samples, char inPath[MAX_NAME_SIZE],
        char outPath[MAX_NAME_SIZE], char **mot_file, char **icy_file)
{
    FLOAT srate;
    int brate;
    frame_header *header = frame->header;
    int err = 0, i = 0;
    long samplerate = 0;

    /* preset defaults */
    inPath[0] = '\0';
    outPath[0] = '\0';
    header->lay = DFLT_LAY;
    switch (DFLT_MOD) {
        case 's':
            header->mode = MPG_MD_STEREO;
            header->mode_ext = 0;
            break;
        case 'd':
            header->mode = MPG_MD_DUAL_CHANNEL;
            header->mode_ext = 0;
            break;
            /* in j-stereo mode, no default header->mode_ext was defined, gave error..
               now  default = 2   added by MFC 14 Dec 1999.  */
        case 'j':
            header->mode = MPG_MD_JOINT_STEREO;
            header->mode_ext = 2;
            break;
        case 'm':
            header->mode = MPG_MD_MONO;
            header->mode_ext = 0;
            break;
        default:
            fprintf (stderr, "%s: Bad mode dflt %c\n", programName, DFLT_MOD);
            abort ();
    }
    *psy = DFLT_PSY;
    if ((header->sampling_frequency =
                SmpFrqIndex ((long) (1000 * DFLT_SFQ), &header->version)) < 0) {
        fprintf (stderr, "%s: bad sfrq default %.2f\n", programName, DFLT_SFQ);
        abort ();
    }
    header->bitrate_index = 14;
    brate = 0;
    switch (DFLT_EMP) {
        case 'n':
            header->emphasis = 0;
            break;
        case '5':
            header->emphasis = 1;
            break;
        case 'c':
            header->emphasis = 3;
            break;
        default:
            fprintf (stderr, "%s: Bad emph dflt %c\n", programName, DFLT_EMP);
            abort ();
    }
    header->copyright = 0;
    header->original = 0;
    header->error_protection = FALSE;
    header->dab_extension = 0;

    glopts.input_select = INPUT_SELECT_WAV;

    /* process args */
    while (++i < argc && err == 0) {
        char c, *token, *arg, *nextArg;
        int argUsed;

        token = argv[i];
        if (*token++ == '-') {
            if (i + 1 < argc)
                nextArg = argv[i + 1];
            else
                nextArg = "";
            argUsed = 0;
            if (!*token) {
                /* The user wants to use stdin and/or stdout. */
                if (inPath[0] == '\0')
                    strncpy (inPath, argv[i], MAX_NAME_SIZE);
                else if (outPath[0] == '\0')
                    strncpy (outPath, argv[i], MAX_NAME_SIZE);
            }
            while ((c = *token++)) {
                if (*token /* NumericQ(token) */ )
                    arg = token;
                else
                    arg = nextArg;
                switch (c) {
                    case 'm':
                        argUsed = 1;
                        if (*arg == 's') {
                            header->mode = MPG_MD_STEREO;
                            header->mode_ext = 0;
                        } else if (*arg == 'd') {
                            header->mode = MPG_MD_DUAL_CHANNEL;
                            header->mode_ext = 0;
                        } else if (*arg == 'j') {
                            header->mode = MPG_MD_JOINT_STEREO;
                        } else if (*arg == 'm') {
                            header->mode = MPG_MD_MONO;
                            header->mode_ext = 0;
                        } else {
                            fprintf (stderr, "%s: -m mode must be s/d/j/m not %s\n",
                                    programName, arg);
                            err = 1;
                        }
                        break;
                    case 'y':
                        *psy = atoi (arg);
                        argUsed = 1;
                        break;

                    case 'L':
                        glopts.show_level = 1;
                        break;

                    case 's':
                        argUsed = 1;
                        srate = atof (arg);
                        /* samplerate = rint( 1000.0 * srate ); $A  */
                        samplerate = (long) ((1000.0 * srate) + 0.5);
                        if ((header->sampling_frequency =
                                    SmpFrqIndex ((long) samplerate, &header->version)) < 0)
                            err = 1;
                        break;

                    case 'j':
                        glopts.input_select = INPUT_SELECT_JACK;
                        break;

                    case 'b':
                        argUsed = 1;
                        brate = atoi (arg);
                        break;
                    case 'd':
                        argUsed = 1;
                        if (*arg == 'n')
                            header->emphasis = 0;
                        else if (*arg == '5')
                            header->emphasis = 1;
                        else if (*arg == 'c')
                            header->emphasis = 3;
                        else {
                            fprintf (stderr, "%s: -d emp must be n/5/c not %s\n", programName,
                                    arg);
                            err = 1;
                        }
                        break;
                    case 'P':
                        argUsed = 1;
                        *mot_file = arg;
                        break;
                    case 'p':
                        argUsed = 1;
                        header->dab_length = atoi(arg);
                        break;
                    case 'c':
                        header->copyright = 1;
                        break;
                    case 'o':
                        header->original = 1;
                        break;
                    case 'e':
                        header->error_protection = TRUE;
                        break;
                    case 'r':
                        glopts.usepadbit = FALSE;
                        header->padding = 0;
                        break;
                    case 'q':
                        argUsed = 1;
                        glopts.quickmode = TRUE;
                        glopts.usepsy = TRUE;
                        glopts.quickcount = atoi (arg);
                        if (glopts.quickcount == 0) {
                            /* just don't use psy model */
                            glopts.usepsy = FALSE;
                            glopts.quickcount = FALSE;
                        }
                        break;
                    case 'a':
                        glopts.downmix = TRUE;
                        header->mode = MPG_MD_MONO;
                        header->mode_ext = 0;
                        break;
                    case 'x':
                        glopts.byteswap = TRUE;
                        break;
                    case 'v':
                        argUsed = 1;
                        glopts.vbr = TRUE;
                        glopts.vbrlevel = atof (arg);
                        glopts.usepadbit = FALSE;	/* don't use padding for VBR */
                        header->padding = 0;
                        /* MFC Feb 2003: in VBR mode, joint stereo doesn't make
                           any sense at the moment, as there are no noisy subbands 
                           according to bits_for_nonoise in vbr mode */
                        header->mode = MPG_MD_STEREO; /* force stereo mode */
                        header->mode_ext = 0;
                        break;
                    case 'V':
                        glopts.input_select = INPUT_SELECT_VLC;
                        break;
                    case 'W':
                        argUsed = 1;
                        *icy_file = arg;
                        break;
                    case 'l':
                        argUsed = 1;
                        glopts.athlevel = atof(arg);
                        break;
                    case 'h':
                        usage ();
                        break;
                    case 'g':
                        glopts.channelswap = TRUE;
                        break;
                    case 't':
                        argUsed = 1;
                        glopts.verbosity = atoi (arg);
                        break;
                    default:
                        fprintf (stderr, "%s: unrec option %c\n", programName, c);
                        err = 1;
                        break;
                }
                if (argUsed) {
                    if (arg == token)
                        token = "";		/* no more from token */
                    else
                        ++i;		/* skip arg we used */
                    arg = "";
                    argUsed = 0;
                }
            }
        } else {
            if (inPath[0] == '\0')
                strcpy (inPath, argv[i]);
            else if (outPath[0] == '\0')
                strcpy (outPath, argv[i]);
            else {
                fprintf (stderr, "%s: excess arg %s\n", programName, argv[i]);
                err = 1;
            }
        }
    }

    /* Always enable DAB mode */
    header->error_protection = TRUE;
    header->dab_extension = 2;
    header->padding = 0;
    glopts.dab = TRUE;

    if (header->dab_extension) {
        /* in 48 kHz */
        /* if the bit rate per channel is less then 56 kbit/s, we have 2 scf-crc */
        /* else we have 4 scf-crc */
        /* in 24 kHz, we have 4 scf-crc, see main loop */
        if (brate / (header->mode == MPG_MD_MONO ? 1 : 2) >= 56)
            header->dab_extension = 4;
    }


    if (err)
        usage ();			/* If err has occured, then call usage() */

    if (glopts.input_select != INPUT_SELECT_JACK && inPath[0] == '\0')
        usage ();			/* If not in jack-mode and no file specified, then call usage() */

    if (outPath[0] == '\0') {
        /* replace old extension with new one, 1992-08-19, 1995-06-12 shn */
        new_ext (inPath, DFLT_EXT, outPath);
    }

    if (glopts.input_select == INPUT_SELECT_JACK) {
        musicin.jack_name = inPath;
        *num_samples = MAX_U_32_NUM;

#if defined(JACK_INPUT)
        setup_jack(header, musicin.jack_name);
#else
        fprintf(stderr, "JACK input not compiled in\n");
        exit(1);
#endif
    }
    else if (glopts.input_select == INPUT_SELECT_WAV) {
        if (!strcmp (inPath, "-")) {
            musicin.wav_input = stdin;		/* read from stdin */
            *num_samples = MAX_U_32_NUM;
        } else {
            if ((musicin.wav_input = fopen (inPath, "rb")) == NULL) {
                fprintf (stderr, "Could not find \"%s\".\n", inPath);
                exit (1);
            }
            parse_input_file (musicin.wav_input, inPath, header, num_samples);
        }
    }
    else if (glopts.input_select == INPUT_SELECT_VLC) {
        if (samplerate == 0) {
            fprintf (stderr, "Samplerate not specified\n");
            exit (1);
        }
        *num_samples = MAX_U_32_NUM;
        int channels = (header->mode == MPG_MD_MONO) ? 1 : 2;
#if defined(VLC_INPUT)
        if (vlc_in_prepare(glopts.verbosity, samplerate, inPath, channels, *icy_file) != 0) {
            fprintf(stderr, "VLC initialisation failed\n");
            exit(1);
        }
#else
        fprintf(stderr, "VLC input not compiled in\n");
        exit(1);
#endif
    }
    else {
        fprintf(stderr, "INVALID INPUT\n");
        exit(1);
    }


    /* check for a valid bitrate */
    if (brate == 0)
        brate = bitrate[header->version][10];

    /* Check to see we have a sane value for the bitrate for this version */
    if ((header->bitrate_index = BitrateIndex (brate, header->version)) < 0)
        err = 1;

    bs.zmq_framesize = 3 * brate;

    /* All options are hunky dory, open the input audio file and
       return to the main drag */
    open_bit_stream_w (&bs, outPath, BUFFER_SIZE);
}