Пример #1
0
bool
AirspaceParser::Parse(TLineReader &reader, OperationEnvironment &operation)
{
  bool ignore = false;

  // Create and init ProgressDialog
  operation.SetProgressRange(1024);

  const long file_size = reader.GetSize();

  TempAirspaceType temp_area;
  AirspaceFileType filetype = AFT_UNKNOWN;

  TCHAR *line;

  // Iterate through the lines
  for (unsigned line_num = 1; (line = reader.ReadLine()) != NULL; line_num++) {
    // Skip empty line
    if (StringIsEmpty(line))
      continue;

    if (filetype == AFT_UNKNOWN) {
      filetype = DetectFileType(line);
      if (filetype == AFT_UNKNOWN)
        continue;
    }

    // Parse the line
    if (filetype == AFT_OPENAIR)
      if (!ParseLine(airspaces, line, temp_area) &&
          !ShowParseWarning(line_num, line, operation))
        return false;

    if (filetype == AFT_TNP)
      if (!ParseLineTNP(airspaces, line, temp_area, ignore) &&
          !ShowParseWarning(line_num, line, operation))
        return false;

    // Update the ProgressDialog
    if ((line_num & 0xff) == 0)
      operation.SetProgressPosition(reader.Tell() * 1024 / file_size);
  }

  if (filetype == AFT_UNKNOWN) {
    operation.SetErrorMessage(_("Unknown airspace filetype"));
    return false;
  }

  // Process final area (if any)
  if (!temp_area.points.empty())
    temp_area.AddPolygon(airspaces);

  return true;
}
Пример #2
0
  __declspec(dllexport) bool CreateThumbnailFromMemory(BYTE *buffer, unsigned int size, const char *ext, const char *thumb, int maxWidth, int maxHeight)
  {
    if (!buffer || !size || !ext || !thumb) return false;
    // load the image
    DWORD dwImageType = CXIMAGE_FORMAT_UNKNOWN;
    if (strlen(ext)) {
      dwImageType = GetImageType(ext);
      if (dwImageType == CXIMAGE_FORMAT_UNKNOWN)
        dwImageType = DetectFileType(buffer, size);
    }
    else
      dwImageType = DetectFileType(buffer, size);
    if (dwImageType == CXIMAGE_FORMAT_UNKNOWN)
    {
      printf("PICTURE::CreateThumbnailFromMemory: Unable to determine image type.");
      return false;
    }
    CxImage image(dwImageType);
    try
    {
      bool success = image.Decode(buffer, size, dwImageType);
      if (!success && dwImageType != CXIMAGE_FORMAT_UNKNOWN)
      { // try to decode with unknown imagetype
        success = image.Decode(buffer, size, CXIMAGE_FORMAT_UNKNOWN);
      }
      if (!success || !image.IsValid())
      {
        printf("PICTURE::CreateThumbnailFromMemory: Unable to decode image. Error:%s\n", image.GetLastError());
        return false;
      }
    }
    catch (...)
    {
      printf("PICTURE::CreateThumbnailFromMemory: Unable to decode image.");
      return false;
    }

    return SaveThumb(image, "", thumb, maxWidth, maxHeight);
  };
Пример #3
0
int RemuxFile( unsigned short nTask, char* pInputFile, TUNE* pTune, int nInputFormat, 
			   char* pOutFile, int nOutputFormat, int nOption )
{
	REMUXER *pRemuxer;
	int ret, max_track_num;

	//if not specify a input format, detect it
	if ( nInputFormat == 0 )
		nInputFormat = DetectFileType( pInputFile );
	if ( nInputFormat == 0 )
		return 0;

	if ( nInputFormat == MPEG_M2TS ) 
		 max_track_num = MAX_TRACK_NUM *2;
	else
		 max_track_num = MAX_TRACK_NUM;

	pRemuxer = CreateRemuxer( nInputFormat, max_track_num, ES_BUFFER_SIZE );
	pRemuxer->task = nTask;

	SetupMessageDumper( pRemuxer->demuxer, (DUMP)RemuxMessageDumper, pRemuxer );

	ret = OpenFileSource( pRemuxer->demuxer, pInputFile, nInputFormat,  pTune );
	if ( !ret )
	{
		ReleaseRemuxer( pRemuxer );
		return 0;
	}

	if ( nOption & 0x01 ) 
		DisabeTSPtsFix( pRemuxer ); 

	if ( nOption & 0x02 ) 
		SetupEPGDump( pRemuxer, (DUMP)EPGDumper, pRemuxer );

	if ( nOption & 0x04 )
		DisableSubtitle( pRemuxer );


	SetupEPGDumpLanguage( pRemuxer, LanguageCode((unsigned char*)"eng") );

	if ( pOutFile != NULL && pOutFile[0] != 0x0 )
		CreateFileOutput( pRemuxer, pOutFile, nOutputFormat, max_track_num );

	if ( IS_TS_TYPE(nOutputFormat) )
		SetupBlockDataDumper( pRemuxer->demuxer, BlockBufferTSDump, pRemuxer->ts_builder );
	else
	if ( IS_PS_TYPE(nOutputFormat) )
		SetupBlockDataDumper( pRemuxer->demuxer, BlockBufferPSDump, pRemuxer->ps_builder );

	pRemuxer->state = 1;

	//looping pump data from file into remuxer
	PumpFileData( pRemuxer->demuxer, 0, RemuxFileProgressCallback, pRemuxer ); 

	PostStatusMessage( pRemuxer, "STREAM END (slot:0)" );

	ReleaseFileOutput( pRemuxer );
	CloseFileSource( pRemuxer->demuxer );
	ReleaseRemuxer( pRemuxer );
	
	return 1;
}
Пример #4
0
bool
ReadAirspace(Airspaces &airspace_database, TLineReader &reader)
{
  int LineCount = 0;
  bool ignore = false;

  // Create and init ProgressDialog
  ProgressGlue::SetRange(1024);

  long file_size = reader.size();

  TempAirspaceType temp_area;
  asFileType filetype = ftUnknown;

  TCHAR *line;
  TCHAR *comment;
  // Iterate through the lines
  while ((line = reader.read()) != NULL) {
    // Increase line counter
    LineCount++;

    // Strip comments
    comment = _tcschr(line, _T('*'));
    if (comment != NULL)
      *comment = _T('\0');

    // Skip empty line
    if (string_is_empty(line))
      continue;

    if (filetype == ftUnknown) {
      filetype = DetectFileType(line);
      if (filetype == ftUnknown)
        continue;
    }

    // Parse the line
    if (filetype == ftOpenAir)
      if (!ParseLine(airspace_database, line, temp_area) &&
          !ShowParseWarning(LineCount, line))
        return false;

    if (filetype == ftTNP)
      if (!ParseLineTNP(airspace_database, line, temp_area, ignore) &&
          !ShowParseWarning(LineCount, line))
        return false;

    // Update the ProgressDialog
    if ((LineCount & 0xff) == 0)
      ProgressGlue::SetValue(reader.tell() * 1024 / file_size);
  }

  if (LineCount == 0)
    return false;

  if (filetype == ftUnknown) {
    MessageBoxX(_("Unknown Filetype."), _("Airspace"), MB_OK);
    return false;
  }

  // Process final area (if any)
  if (!temp_area.Waiting)
    temp_area.AddPolygon(airspace_database);

  return true;
}
Пример #5
0
  __declspec(dllexport) bool LoadImageFromMemory(const BYTE *buffer, unsigned int size, const char *mime, unsigned int maxwidth, unsigned int maxheight, ImageInfo *info)
  {
    if (!buffer || !size || !mime || !info) return false;

    // load the image
    DWORD dwImageType = CXIMAGE_FORMAT_UNKNOWN;
    if (strlen(mime))
      dwImageType = GetImageType(mime);
    if (dwImageType == CXIMAGE_FORMAT_UNKNOWN)
      dwImageType = DetectFileType(buffer, size);
    if (dwImageType == CXIMAGE_FORMAT_UNKNOWN)
    {
      printf("PICTURE::LoadImageFromMemory: Unable to determine image type.");
      return false;
    }

    CxImage *image = new CxImage(dwImageType);
    if (!image)
      return false;

    int actualwidth = maxwidth;
    int actualheight = maxheight;

    try
    {
      bool success = image->Decode((BYTE*)buffer, size, dwImageType, actualwidth, actualheight);
      if (!success && dwImageType != CXIMAGE_FORMAT_UNKNOWN)
      { // try to decode with unknown imagetype
        success = image->Decode((BYTE*)buffer, size, CXIMAGE_FORMAT_UNKNOWN);
      }
      if (!success || !image->IsValid())
      {
        printf("PICTURE::LoadImageFromMemory: Unable to decode image. Error:%s\n", image->GetLastError());
        delete image;
        return false;
      }
    }
    catch (...)
    {
      printf("PICTURE::LoadImageFromMemory: Unable to decode image.");
      delete image;
      return false;
    }

    // ok, now resample the image down if necessary
    if (ResampleKeepAspect(*image, maxwidth, maxheight) < 0)
    {
      printf("PICTURE::LoadImage: Unable to resample picture\n");
      delete image;
      return false;
    }

    // make sure our image is 24bit minimum
    image->IncreaseBpp(24);

    // fill in our struct
    info->width = image->GetWidth();
    info->height = image->GetHeight();
    info->originalwidth = actualwidth;
    info->originalheight = actualheight;
    memcpy(&info->exifInfo, image->GetExifInfo(), sizeof(EXIFINFO));

    // create our texture
    info->context = image;
    info->texture = image->GetBits();
    info->alpha = image->AlphaGetBits();
    return (info->texture != NULL);
  };