com.jme3.texture.Image.getWidth()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(9.8k)|赞(0)|评价(0)|浏览(76)

本文整理了Java中com.jme3.texture.Image.getWidth()方法的一些代码示例,展示了Image.getWidth()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Image.getWidth()方法的具体详情如下:
包路径:com.jme3.texture.Image
类名称:Image
方法名:getWidth

Image.getWidth介绍

[英]getWidth returns the width of this image.
[中]

代码示例

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

@Override
public int getWidth() {
 return image.getWidth();
}

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

/**
 * For this class the index should be considered as a pixel index in AWT image format.
 */
public void read(Image image, int layer, TexturePixel pixel, int index) {
  this.read(image, layer, pixel, index % image.getWidth(), index / image.getWidth());
}

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

public void write(Image image, int layer, TexturePixel pixel, int x, int y) {
    int index = y * image.getWidth() + x;
    this.write(image, layer, pixel, index);
  }
}

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

public void read(Image image, int layer, TexturePixel pixel, int x, int y) {
  int index = y * image.getWidth() + x;
  this.read(image, layer, pixel, index);
}

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

private static void checkImage(Image image) {
//        if (image.getDepth() != 1)
//            throw new IllegalArgumentException("3D/Array images not allowed");

    if (image.getWidth() != image.getHeight()) {
      throw new IllegalArgumentException("Image width and height must be the same");
    }

    if (image.getMultiSamples() != 1) {
      throw new IllegalArgumentException("Multisample textures not allowed");
    }
  }

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

private Image convertImageToAwt(Image source) {
  //use awt dependent classes without actual dependency via reflection
  try {
    Class clazz = Class.forName("jme3tools.converters.ImageToAwt");
    if (clazz == null) {
      return null;
    }
    Image newImage = new Image(format, source.getWidth(), source.getHeight(), BufferUtils.createByteBuffer(source.getWidth() * source.getHeight() * 4), null, ColorSpace.Linear);
    clazz.getMethod("convert", Image.class, Image.class).invoke(clazz.newInstance(), source, newImage);
    return newImage;
  } catch (InstantiationException ex) {
  } catch (IllegalAccessException ex) {
  } catch (IllegalArgumentException ex) {
  } catch (InvocationTargetException ex) {
  } catch (NoSuchMethodException ex) {
  } catch (SecurityException ex) {
  } catch (ClassNotFoundException ex) {
  }
  return null;
}

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

public RenderImageJme(Texture2D texture){
  if (texture.getImage() == null) {
    throw new IllegalArgumentException("texture.getImage() cannot be null");
  }
  
  this.texture = texture;
  this.image = texture.getImage();
  width = image.getWidth();
  height = image.getHeight();
}

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

/**
 * This method computes the final UV coordinates for the image (after it
 * is combined with other images and drawed on the result image).
 * 
 * @param totalImageWidth
 *            the result image width
 * @param totalImageHeight
 *            the result image height
 * @param xPos
 *            the most left x coordinate of the image
 * @param yPos
 *            the most top y coordinate of the image
 * @param result
 *            a vector where the result is stored
 */
public void computeFinalUVCoordinates(int totalImageWidth, int totalImageHeight, int xPos, int yPos, Vector2f[] result) {
  for (int i = 0; i < 3; ++i) {
    result[i] = new Vector2f();
    result[i].x = xPos / (float) totalImageWidth + uv[i].x * (image.getWidth() / (float) totalImageWidth);
    result[i].y = yPos / (float) totalImageHeight + uv[i].y * (image.getHeight() / (float) totalImageHeight);
  }
}

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

public void write(Image image, int layer, TexturePixel pixel, int x, int y) {
    int index = (y * image.getWidth() + x) * (image.getFormat().getBitsPerPixel() >> 3);
    this.write(image, layer, pixel, index);
  }
}

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

/**
 * Creates a CubeMapWrapper for the given cube map
 * Note that the cube map must be initialized, and the mipmaps sizes should 
 * be set if relevant for them to be readable/writable
 * @param cubeMap the cubemap to wrap.
 */
public CubeMapWrapper(TextureCubeMap cubeMap) {
  image = cubeMap.getImage();
  if (image.hasMipmaps()) {
    int nbMipMaps = image.getMipMapSizes().length;
    sizes = new int[nbMipMaps];
    mipMapRaster = new MipMapImageRaster(image, 0);
    for (int i = 0; i < nbMipMaps; i++) {
      sizes[i] = Math.max(1, image.getWidth() >> i);
    }
  } else {
    sizes = new int[1];
    sizes[0] = image.getWidth();
  }
  raster = new DefaultImageRaster(image, 0,0 , false);
}

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

public void read(Image image, int layer, TexturePixel pixel, int x, int y) {
  int index = (y * image.getWidth() + x) * (image.getFormat().getBitsPerPixel() >> 3);
  this.read(image, layer, pixel, index);
}

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

public static void flipImage(Image img, int index){
  if (img.getFormat().isCompressed())
    throw new UnsupportedOperationException("Flipping compressed " +
                        "images is unsupported.");
  int w = img.getWidth();
  int h = img.getHeight();
  int halfH = h / 2;
  // bytes per pixel
  int bpp = img.getFormat().getBitsPerPixel() / 8;
  int scanline = w * bpp;
  ByteBuffer data = img.getData(index);
  ByteBuffer temp = BufferUtils.createByteBuffer(scanline);
  
  data.rewind();
  for (int y = 0; y < halfH; y++){
    int oppY = h - y - 1;
    // read in scanline
    data.position(y * scanline);
    data.limit(data.position() + scanline);
    temp.rewind();
    temp.put(data);
  }
}

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

private void checkSetTexture(Texture tex, boolean depth){
  Image img = tex.getImage();
  if (img == null)
    throw new IllegalArgumentException("Texture not initialized with RTT.");
  if (depth && !img.getFormat().isDepthFormat())
    throw new IllegalArgumentException("Texture image format must be depth.");
  else if (!depth && img.getFormat().isDepthFormat())
    throw new IllegalArgumentException("Texture image format must be color/luminance.");
  // check that resolution matches texture resolution
  if (width != img.getWidth() || height != img.getHeight())
    throw new IllegalArgumentException("Texture image resolution " +
                      "must match FB resolution");
  if (samples != tex.getImage().getMultiSamples())
    throw new IllegalStateException("Texture samples must match framebuffer samples");
}

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

public static Image resizeToPowerOf2(Image original){
  int potWidth = FastMath.nearestPowerOfTwo(original.getWidth());
  int potHeight = FastMath.nearestPowerOfTwo(original.getHeight());
  return scaleImage(original, potWidth, potHeight);
}

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

public static void createData(Image image, boolean mipmaps){
  int bpp = image.getFormat().getBitsPerPixel();
  int w = image.getWidth();
  int h = image.getHeight();
  if (!mipmaps){
    image.setData(BufferUtils.createByteBuffer(w*h*bpp/8));
    return;
  }
  int expectedMipmaps = 1 + (int) Math.ceil(Math.log(Math.max(h, w)) / LOG2);
  int[] mipMapSizes = new int[expectedMipmaps];
  int total = 0;
  for (int i = 0; i < mipMapSizes.length; i++){
    int size = (w * h * bpp) / 8;
    total += size;
    mipMapSizes[i] = size;
    w /= 2;
    h /= 2;
  }
  image.setMipMapSizes(mipMapSizes);
  image.setData(BufferUtils.createByteBuffer(total));
}

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

private Image convertImage(Image image, Format newFormat) {
  int width = image.getWidth();
  int height = image.getHeight();
  ByteBuffer data = BufferUtils.createByteBuffer( (int)Math.ceil(newFormat.getBitsPerPixel() / 8.0) * width * height);
  Image convertedImage = new Image(newFormat, width, height, data,null, image.getColorSpace());
  
  ImageRaster sourceReader = ImageRaster.create(image);
  ImageRaster targetWriter = ImageRaster.create(convertedImage);
  for (int x = 0; x < width; x++) {
    for (int y = 0; y < height; y++) {
      ColorRGBA color = sourceReader.getPixel(x, y);
      targetWriter.setPixel(x, y, color);
    }
  }
  
  return convertedImage;
}

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

@Override
public void setTexture(int unit, Texture tex) {
  Image image = tex.getImage();
  if (image.isUpdateNeeded() || (image.isGeneratedMipmapsRequired() && !image.isMipmapsGenerated())) {
    // Check NPOT requirements
    boolean scaleToPot = false;
    try {
      checkNonPowerOfTwo(tex);
    } catch (RendererException ex) {
      if (logger.isLoggable(Level.WARNING)) {
        int nextWidth = FastMath.nearestPowerOfTwo(tex.getImage().getWidth());
        int nextHeight = FastMath.nearestPowerOfTwo(tex.getImage().getHeight());
        logger.log(Level.WARNING,
            "Non-power-of-2 textures are not supported! Scaling texture '" + tex.getName() +
                "' of size " + tex.getImage().getWidth() + "x" + tex.getImage().getHeight() +
                " to " + nextWidth + "x" + nextHeight);
      }
      scaleToPot = true;
    }
    updateTexImageData(image, tex.getType(), unit, scaleToPot);
  }
  int texId = image.getId();
  assert texId != -1;
  setupTextureParams(unit, tex);
}

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

public RenderImageJme(String filename, boolean linear, NiftyJmeDisplay display){
  TextureKey key = new TextureKey(filename, true);
  key.setAnisotropy(0);
  key.setGenerateMips(false);
  
  texture = (Texture2D) display.getAssetManager().loadTexture(key);
  texture.setMagFilter(linear ? MagFilter.Bilinear : MagFilter.Nearest);
  texture.setMinFilter(linear ? MinFilter.BilinearNoMipMaps : MinFilter.NearestNoMipMaps);
  image = texture.getImage();
  width = image.getWidth();
  height = image.getHeight();
}

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

public static void resizeToPowerOf2(Image image){
  BufferedImage original = ImageToAwt.convert(image, false, true, 0);
  int potWidth = FastMath.nearestPowerOfTwo(image.getWidth());
  int potHeight = FastMath.nearestPowerOfTwo(image.getHeight());
  int potSize = Math.max(potWidth, potHeight);
  BufferedImage scaled = scaleDown(original, potSize, potSize);
  AWTLoader loader = new AWTLoader();
  Image output = loader.load(scaled, false);
  image.setWidth(potSize);
  image.setHeight(potSize);
  image.setDepth(0);
  image.setData(output.getData(0));
  image.setFormat(output.getFormat());
  image.setMipMapSizes(null);
}

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

@Override
public void simpleInitApp() {
  // create a simple plane/quad
  Quad quadMesh = new Quad(1, 1);
  quadMesh.updateGeometry(1, 1, true);
  Geometry quad = new Geometry("Textured Quad", quadMesh);
  assetManager.registerLocator("https://raw.githubusercontent.com/jMonkeyEngine/BookSamples/master/assets/Textures/",
              UrlLocator.class);
  TextureKey key = new TextureKey("mucha-window.png", false);
  key.setGenerateMips(true);
  Texture tex = assetManager.loadTexture(key);
  Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
  mat.setTexture("ColorMap", tex);
  quad.setMaterial(mat);
  float aspect = tex.getImage().getWidth() / (float) tex.getImage().getHeight();
  quad.setLocalScale(new Vector3f(aspect * 1.5f, 1.5f, 1));
  quad.center();
  rootNode.attachChild(quad);
}

相关文章