if (!stbi_info_from_memory(imageBuffer, w, h, c)) { throw new RuntimeException("Failed to read image information: " + stbi_failure_reason()); ByteBuffer image = stbi_load_from_memory(imageBuffer, w, h, c, 0); if (image == null) { throw new RuntimeException("Failed to load image: " + stbi_failure_reason()); stbi_image_free(image);
/** * Indicate whether we should process iPhone images back to canonical format, or just pass them through "as-is". * * @param flag_true_if_should_convert the convert iPhone PNG to RGB flag */ public static void stbi_convert_iphone_png_to_rgb(@NativeType("int") boolean flag_true_if_should_convert) { nstbi_convert_iphone_png_to_rgb(flag_true_if_should_convert ? 1 : 0); }
/** Returns a brief reason for failure. */ @Nullable @NativeType("char const *") public static String stbi_failure_reason() { long __result = nstbi_failure_reason(); return memASCIISafe(__result); }
public static ByteBuffer decodeImage(String file){ String absolutePath = VkImageLoader.class.getClassLoader().getResource(file).getPath().substring(1); if (!System.getProperty("os.name").contains("Windows")) { // TODO Language/region agnostic value for 'Windows' ? // stbi_load requires a file system path, NOT a classpath resource path absolutePath = File.separator + absolutePath; } IntBuffer x = BufferUtils.createIntBuffer(1); IntBuffer y = BufferUtils.createIntBuffer(1); IntBuffer channels = BufferUtils.createIntBuffer(1); ByteBuffer image = stbi_load(absolutePath, x, y, channels, STBI_rgb_alpha); if (image == null) { System.err.println("Could not decode image file ["+ absolutePath +"]: ["+ STBImage.stbi_failure_reason() +"]"); } return image; }
public static ImageMetaData getImageMetaData(String file){ ByteBuffer imageBuffer; try { imageBuffer = ioResourceToByteBuffer(file, 128 * 128); } catch (IOException e) { throw new RuntimeException(e); } IntBuffer x = BufferUtils.createIntBuffer(1); IntBuffer y = BufferUtils.createIntBuffer(1); IntBuffer channels = BufferUtils.createIntBuffer(1); // Use info to read image metadata without decoding the entire image. if (!stbi_info_from_memory(imageBuffer, x, y, channels)) { throw new RuntimeException("Failed to read image information: " + stbi_failure_reason()); } return new ImageMetaData(x.get(0), y.get(0), channels.get(0)); }
public Texture(ByteBuffer imageData) { try (MemoryStack stack = stackPush()) { IntBuffer w = stack.mallocInt(1); IntBuffer h = stack.mallocInt(1); IntBuffer avChannels = stack.mallocInt(1); // Decode texture image into a byte buffer ByteBuffer decodedImage = stbi_load_from_memory(imageData, w, h, avChannels, 4); this.width = w.get(); this.height = h.get(); // Create a new OpenGL texture this.id = glGenTextures(); // Bind the texture glBindTexture(GL_TEXTURE_2D, this.id); // Tell OpenGL how to unpack the RGBA bytes. Each component is 1 byte size glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); // Upload the texture data glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, this.width, this.height, 0, GL_RGBA, GL_UNSIGNED_BYTE, decodedImage); // Generate Mip Map glGenerateMipmap(GL_TEXTURE_2D); } }
IntBuffer components = BufferUtils.createIntBuffer(1); ByteBuffer imageBuffer = stbi_load_from_memory((ByteBuffer) memory.nativeBuffer(), width, height, components, 4); throw new SilenceException("Failed to load image: " + stbi_failure_reason()); stbi_image_free(imageBuffer);
/** * Should be used to load image data from source. */ @Override public void load() { try { ByteBuffer byteBuffer = IOUtil.resourceToByteBuffer(getPath()); int[] width = {0}; int[] height = {0}; int[] channels = {0}; ByteBuffer imageData = STBImage.stbi_load_from_memory(byteBuffer, width, height, channels, 4); if (imageData != null) { this.width = width[0]; this.height = height[0]; this.channels = ImageChannels.instance(channels[0]); this.imageData = imageData; } else { // if error occurs throw LeguiExceptionTemplate.FAILED_TO_LOAD_IMAGE.create(STBImage.stbi_failure_reason()); } } catch (IOException e) { throw LeguiExceptionTemplate.FAILED_TO_LOAD_IMAGE.create(e, e.getMessage()); } }
public Texture(ByteBuffer imageData) { try (MemoryStack stack = stackPush()) { IntBuffer w = stack.mallocInt(1); IntBuffer h = stack.mallocInt(1); IntBuffer avChannels = stack.mallocInt(1); // Decode texture image into a byte buffer ByteBuffer decodedImage = stbi_load_from_memory(imageData, w, h, avChannels, 4); this.width = w.get(); this.height = h.get(); // Create a new OpenGL texture this.id = glGenTextures(); // Bind the texture glBindTexture(GL_TEXTURE_2D, this.id); // Tell OpenGL how to unpack the RGBA bytes. Each component is 1 byte size glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); // Upload the texture data glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, this.width, this.height, 0, GL_RGBA, GL_UNSIGNED_BYTE, decodedImage); // Generate Mip Map glGenerateMipmap(GL_TEXTURE_2D); } }
public Texture(ByteBuffer imageData) { try (MemoryStack stack = stackPush()) { IntBuffer w = stack.mallocInt(1); IntBuffer h = stack.mallocInt(1); IntBuffer avChannels = stack.mallocInt(1); // Decode texture image into a byte buffer ByteBuffer decodedImage = stbi_load_from_memory(imageData, w, h, avChannels, 4); this.width = w.get(); this.height = h.get(); // Create a new OpenGL texture this.id = glGenTextures(); // Bind the texture glBindTexture(GL_TEXTURE_2D, this.id); // Tell OpenGL how to unpack the RGBA bytes. Each component is 1 byte size glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); // Upload the texture data glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, this.width, this.height, 0, GL_RGBA, GL_UNSIGNED_BYTE, decodedImage); // Generate Mip Map glGenerateMipmap(GL_TEXTURE_2D); } }
ByteBuffer decodedImage = stbi_load_from_memory(imageData, w, h, avChannels, 4); int width = w.get(); int height = h.get();
ByteBuffer decodedImage = stbi_load_from_memory(imageData, w, h, avChannels, 4); int width = w.get(); int height = h.get();
ByteBuffer decodedImage = stbi_load_from_memory(imageData, w, h, avChannels, 4); int width = w.get(); int height = h.get();