void  GUIText::printCenteredXY(int x, int y, int startIndex, int endIndex)
{
  if (!text.getLength())
    return;
    
  computeDimensions();
  print(x - size.x/2, y - size.y/2, startIndex, endIndex);
}
Exemple #2
0
//namespace io {
GatherFolderImg::GatherFolderImg( const fs::path &folderpath ) {
	_minFrequencyMask = 100 ;

	_folderpath = folderpath ;
	if ( ! fs::is_directory( _folderpath) ) {
		Pgm3dFactory<arma::u8> factory ;
		_scene = factory.read( QString( _folderpath.c_str() ) );
		_folderpath = _folderpath.parent_path() ;
		if ( _folderpath.empty() ) _folderpath = ".";

		// _scene 's values have to be either 0 or 1
		if ( _scene->max() > 1 )
			*_scene /= _scene->max() ;
	} else {
		std::cerr<<"call computeDimensions()"<<std::endl;
		computeDimensions() ;
	}
}
void  GUIText::print(int x, int y, int startIndex, int endIndex)
{
  if (!text.getLength())
    return;
    
  endIndex   = (endIndex  < 0) ? int(text.getLength()) : endIndex;
  startIndex = clamp(startIndex, 0, endIndex);
  
  GUIFontManager::setCurrentFont(fontIndex);
  GUIFont *currentFont = GUIFontManager::getCurrentFont();
  computeDimensions();
  
  if (!currentFont && !(currentFont = GUIFontManager::getDefaultFont()))
    return;
    
  currentFont->getFontObject()->printSubString(float(x), float(y), scales.x, scales.y,
      color.x, color.y, color.z,
      startIndex, endIndex,
      text);
}
Exemple #4
0
void
getBasicXcfInfo(void)
{
  uint32_t ptr, data, layerfile ;
  PropType type ;
  int i ;
  
  xcfCheckspace(0,14+7*4,"(very short)");
  if( strcmp((char*)xcf_file,"gimp xcf file") == 0 )
    XCF.version = 0 ;
  else if( xcf_file[13] == 0 &&
          sscanf((char*)xcf_file,"gimp xcf v%d",&XCF.version) == 1 )
    ;
  else
    FatalBadXCF(_("Not an XCF file at all (magic not recognized)"));

  if( XCF.version < 0 || XCF.version > 2 ) {
    fprintf(stderr,
            _("Warning: XCF version %d not supported (trying anyway...)\n"),
            XCF.version);
  }
  
  XCF.compression = COMPRESS_NONE ;
  XCF.colormapptr = 0 ;
  
  ptr = 14 ;
  XCF.width    = xcfL(ptr); ptr += 4 ;
  XCF.height   = xcfL(ptr); ptr += 4 ;
  XCF.type     = xcfL(ptr); ptr += 4 ;
  while( (type = xcfNextprop(&ptr,&data)) != PROP_END ) {
    switch(type) {
    case PROP_COLORMAP:
      XCF.colormapptr = data ;
      break ;
    case PROP_COMPRESSION:
      XCF.compression = xcf_file[data] ;
      break ;
    default:
      /* Ignore unknown properties */
      break ;
    }
  }

  layerfile = ptr ;
  for( XCF.numLayers = 0 ; xcfOffset(ptr,8*4) ; XCF.numLayers++, ptr+=4  )
    ;
  XCF.layers = xcfmalloc(XCF.numLayers * sizeof(struct xcfLayer)) ;
  for( i = 0 ; i < XCF.numLayers ; i++ ) {
    struct xcfLayer *L = XCF.layers + i ;
    ptr = xcfL(layerfile+4*(XCF.numLayers-1-i)) ;
    L->mode = GIMP_NORMAL_MODE ;
    L->opacity = 255 ;
    L->isVisible = 1 ;
    L->hasMask = 0 ;
    L->dim.width = xcfL(ptr); ptr+=4 ;
    L->dim.height = xcfL(ptr); ptr+=4 ;
    L->type = xcfL(ptr); ptr+=4 ;
    L->name = xcfString(ptr,&ptr);
    L->propptr = ptr ;
    while( (type = xcfNextprop(&ptr,&data)) != PROP_END ) {
      switch(type) {
      case PROP_OPACITY:
        L->opacity = xcfL(data);
        if( L->opacity > 255 )
          L->opacity = 255 ;
        break ;
      case PROP_VISIBLE:
        L->isVisible = xcfL(data) != 0 ;
        break ;
      case PROP_APPLY_MASK:
        L->hasMask = xcfL(data) != 0 ;
        break ;
      case PROP_OFFSETS:
        L->dim.c.l = (int32_t)(xcfL(data  )) ;
        L->dim.c.t = (int32_t)(xcfL(data+4)) ;
        break ;
      case PROP_MODE:
        L->mode = xcfL(data);
        break ;
      default:
        /* Ignore unknown properties */
        break ;
      }
    }
    xcfCheckspace(ptr,8,"(end of layer %s)",L->name);
    L->pixels.tileptrs = 0 ;
    L->pixels.hierarchy = xcfOffset(ptr  ,4*4);
    L->mask.tileptrs = 0 ;
    L->mask.hierarchy   = xcfOffset(ptr+4,4*4);

    computeDimensions(&L->dim);
  }
}
void
complete_flatspec(struct FlattenSpec *spec, guesser guess_callback)
{
    unsigned i ;
    int anyPartial ;

    /* Find the layers to convert.
     */
    if( spec->numLayers == 0 ) {
        spec->layers = XCF.layers ;
        spec->numLayers = XCF.numLayers ;
    } else {
        for( i=0; i<spec->numLayers; i++ ) {
            GimpLayerModeEffects mode ;
            int opacity, hasMask ;
            unsigned j ;

            for( j=0; ; j++ ) {
                if( j == XCF.numLayers )
                    FatalGeneric(22,_("The image has no layer called '%s'"),
                                 spec->layers[i].name);
                if( strcmp(spec->layers[i].name,XCF.layers[j].name) == 0 )
                    break ;
            }
            mode = spec->layers[i].mode == (GimpLayerModeEffects)-1 ?
                   XCF.layers[j].mode : spec->layers[i].mode ;
            opacity = spec->layers[i].opacity == 9999 ?
                      XCF.layers[j].opacity : spec->layers[i].opacity ;
            hasMask = spec->layers[i].hasMask == -1 ?
                      XCF.layers[j].hasMask : spec->layers[i].hasMask ;
            if( hasMask && !XCF.layers[j].hasMask &&
                    XCF.layers[j].mask.hierarchy == 0 )
                FatalGeneric(22,_("Layer '%s' has no layer mask to enable"),
                             spec->layers[i].name);
            spec->layers[i] = XCF.layers[j] ;
            spec->layers[i].mode = mode ;
            spec->layers[i].opacity = opacity ;
            spec->layers[i].hasMask = hasMask ;
            spec->layers[i].isVisible = 1 ;
        }
    }

    /* Force the mode of the lowest visible layer to be Normal or Dissolve.
     * That may not be logical, but the Gimp does it
     */
    for( i=0; i < spec->numLayers; i++ ) {
        if( spec->layers[i].isVisible ) {
            if( spec->layers[i].mode != GIMP_DISSOLVE_MODE )
                spec->layers[i].mode = GIMP_NORMAL_MODE ;
            break ;
        }
    }

    /* Mimic the Gimp's behavior on indexed layers */
    if( XCF.type == GIMP_INDEXED && spec->gimpish_indexed ) {
        for( i=0; i<spec->numLayers; i++ )
            if( spec->layers[i].mode != GIMP_DISSOLVE_MODE )
                spec->layers[i].mode = GIMP_NORMAL_NOPARTIAL_MODE ;
    } else
        spec->gimpish_indexed = 0 ;

    /* compute dimensions of the window */
    if( spec->window_mode == AUTOCROP ) {
        int first = 1 ;
        for( i=0; i<spec->numLayers; i++ )
            if( spec->layers[i].isVisible ) {
                computeDimensions(&spec->layers[i].dim) ;
                if( first ) {
                    spec->dim = spec->layers[i].dim ;
                    first = 0 ;
                } else {
                    if( spec->dim.c.l < spec->layers[i].dim.c.l )
                        spec->dim.c.l = spec->layers[i].dim.c.l ;
                    if( spec->dim.c.r > spec->layers[i].dim.c.r )
                        spec->dim.c.r = spec->layers[i].dim.c.r ;
                    if( spec->dim.c.t < spec->layers[i].dim.c.t )
                        spec->dim.c.t = spec->layers[i].dim.c.t ;
                    if( spec->dim.c.b > spec->layers[i].dim.c.b )
                        spec->dim.c.b = spec->layers[i].dim.c.b ;
                }
            }
        if( first ) {
            spec->window_mode = USE_CANVAS ;
        } else {
            spec->dim.width = spec->dim.c.r - spec->dim.c.l ;
            spec->dim.height = spec->dim.c.b - spec->dim.c.t ;
        }
    }
    if( spec->window_mode != AUTOCROP ) {
        if( (spec->window_mode & MANUAL_OFFSET) == 0 )
            spec->dim.c.t = spec->dim.c.l = 0 ;
        if( (spec->window_mode & MANUAL_CROP) == 0 ) {
            spec->dim.height = XCF.height ;
            spec->dim.width = XCF.width ;
        }
    }
    computeDimensions(&spec->dim);

    /* We can't handle negative coordinates properly, so abort rather than
     * crash chaotically. See CVE-2009-217; Debian bug #533361.
     */
    if( spec->dim.c.t < 0 || spec->dim.c.l < 0 ) {
        FatalUnsupportedXCF("This version cannot extract pixels above or to the "
                            "left of the canvas");
    }

    /* Turn off layers that we don't hit at all */
    for( i=0; i<spec->numLayers; i++ )
        if( spec->layers[i].isVisible &&
                disjointRects(spec->dim.c,spec->layers[i].dim.c) )
            spec->layers[i].isVisible = 0 ;

    /* See if there is a completely covering layer somewhere in the stack */
    /* Also check if partial transparency is possible */
    anyPartial = 0 ;
    for( i=spec->numLayers; i-- ; ) {
        if( !spec->layers[i].isVisible )
            continue ;
        if( typeHasTransparency(spec->layers[i].type) ) {
            if( spec->layers[i].mode == GIMP_NORMAL_MODE )
                anyPartial = 1;
        } else if( isSubrect(spec->dim.c,spec->layers[i].dim.c) &&
                   (spec->layers[i].mode == GIMP_NORMAL_MODE ||
                    spec->layers[i].mode == GIMP_NORMAL_NOPARTIAL_MODE ||
                    spec->layers[i].mode == GIMP_DISSOLVE_MODE) ) {
            /* This layer fills out the entire image.
             * Turn off anly lower layers, and note that we cannot have
             * transparency at all.
             */
            while(i) spec->layers[--i].isVisible = 0 ;
            if( spec->default_pixel != FORCE_ALPHA_CHANNEL )
                spec->default_pixel = NEWALPHA(colormap[0],255);
            anyPartial = 0 ;
            break ;
        }
    }
    if( spec->partial_transparency_mode == ALLOW_PARTIAL_TRANSPARENCY &&
            (!anyPartial || ALPHA(spec->default_pixel) >= 128) )
        spec->partial_transparency_mode = PARTIAL_TRANSPARENCY_IMPOSSIBLE ;

    /* Initialize layers and print overview if we're verbose */
    for( i=spec->numLayers; i--; )
        if( spec->layers[i].isVisible ) {
            initLayer(&spec->layers[i]) ;
            if( verboseFlag ) {
                fprintf(stderr,"%dx%d%+d%+d %s %s",
                        spec->layers[i].dim.width, spec->layers[i].dim.height,
                        spec->layers[i].dim.c.l - spec->dim.c.l,
                        spec->layers[i].dim.c.t - spec->dim.c.t,
                        _(showGimpImageType(spec->layers[i].type)),
                        _(showGimpLayerModeEffects(spec->layers[i].mode)));
                if( spec->layers[i].opacity < 255 )
                    fprintf(stderr,"/%02d%%",spec->layers[i].opacity * 100 / 255);
                if( XCF.layers[i].hasMask )
                    fprintf(stderr,_("/mask"));
                fprintf(stderr," %s\n",spec->layers[i].name);
            }
        }

    /* Resolve color mode unless we wait until we have the entire image */
    if( spec->out_color_mode == COLOR_BY_CONTENTS &&
            !spec->process_in_memory ) {
        if( guess_callback )
            spec->out_color_mode = guess_callback(spec,NULL);
        if( spec->out_color_mode == COLOR_BY_CONTENTS )
            spec->out_color_mode = color_by_layers(spec) ;
    }
}