示例#1
0
outputFormatObj *msSelectOutputFormat( mapObj *map, 
                                       const char *imagetype )

{
    int index;
    outputFormatObj *format = NULL;

    if( map == NULL || imagetype == NULL || strlen(imagetype) == 0 )
        return NULL;
    
/* -------------------------------------------------------------------- */
/*      Try to find the format in the maps list of formats, first by    */
/*      mime type, and then by output format name.                      */
/* -------------------------------------------------------------------- */
    index = msGetOutputFormatIndex(map, imagetype);
    if (index >= 0) {
        format = map->outputformatlist[index];
    } else {
       struct defaultOutputFormatEntry *formatEntry = defaultoutputformats;
       while(formatEntry->name) {
          if(!strcasecmp(imagetype,formatEntry->name) || !strcasecmp(imagetype,formatEntry->mimetype)) {
             format = msCreateDefaultOutputFormat( map, formatEntry->driver, formatEntry->name );
             break;
          }
          formatEntry++;
       }

    }

    if (format)
    {
        if (map->imagetype)
            free(map->imagetype);
        map->imagetype = msStrdup(format->name);
    }

    if( format != NULL )
        msOutputFormatValidate( format, MS_FALSE );

    return format;
}
示例#2
0
void msApplyOutputFormat( outputFormatObj **target,
                          outputFormatObj *format,
                          int transparent,
                          int interlaced,
                          int imagequality )

{
  int       change_needed = MS_FALSE;
  int       old_imagequality, old_interlaced;
  outputFormatObj *formatToFree = NULL;

  assert( target != NULL );

  if( *target != NULL && MS_REFCNT_DECR_IS_ZERO( (*target) ) ) {
    formatToFree = *target;
    *target = NULL;
  }

  if( format == NULL ) {
    if( formatToFree )
      msFreeOutputFormat( formatToFree );
    *target = NULL;
    return;
  }

  msOutputFormatValidate( format, MS_FALSE );

  /* -------------------------------------------------------------------- */
  /*      Do we need to change any values?  If not, then just apply       */
  /*      and return.                                                     */
  /* -------------------------------------------------------------------- */
  if( transparent != MS_NOOVERRIDE && !format->transparent != !transparent )
    change_needed = MS_TRUE;

  old_imagequality = atoi(msGetOutputFormatOption( format, "QUALITY", "75"));
  if( imagequality != MS_NOOVERRIDE && old_imagequality != imagequality )
    change_needed = MS_TRUE;

  old_interlaced =
    strcasecmp(msGetOutputFormatOption( format, "INTERLACE", "ON"),
               "OFF") != 0;
  if( interlaced != MS_NOOVERRIDE && !interlaced != !old_interlaced )
    change_needed = MS_TRUE;

  if( change_needed ) {
    char new_value[128];

    if( format->refcount > 0 )
      format = msCloneOutputFormat( format );

    if( transparent != MS_NOOVERRIDE ) {
      format->transparent = transparent;
      if( format->imagemode == MS_IMAGEMODE_RGB )
        format->imagemode = MS_IMAGEMODE_RGBA;
    }

    if( imagequality != MS_NOOVERRIDE && imagequality != old_imagequality ) {
      snprintf( new_value, sizeof(new_value), "%d", imagequality );
      msSetOutputFormatOption( format, "QUALITY", new_value );
    }

    if( interlaced != MS_NOOVERRIDE && !interlaced != !old_interlaced ) {
      if( interlaced )
        msSetOutputFormatOption( format, "INTERLACE", "ON" );
      else
        msSetOutputFormatOption( format, "INTERLACE", "OFF" );
    }
  }

  *target = format;
  format->refcount++;
  if( MS_RENDERER_PLUGIN(format) ) {
    msInitializeRendererVTable(format);
  }


  if( formatToFree )
    msFreeOutputFormat( formatToFree );
}