Package org.ngengine.stbimage
Class StbImage
java.lang.Object
org.ngengine.stbimage.StbImage
Pure Java implementation of stb_image.h
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionStbImage()Creates an instance using heap allocation (ByteBuffer.allocate(int)).StbImage(IntFunction<ByteBuffer> allocator) Creates an instance with a custom output buffer allocator. -
Method Summary
Modifier and TypeMethodDescriptiongetDecoder(ByteBuffer buffer, boolean flipVertically) Selects and instantiates a decoder for the provided buffer.intReturns the number of registered decoders.Returns a list of registered decoder formats.booleanReturns whether iPhone PNG channel conversion is enabled.booleanReturns whether GIF first-frame untouched pixels are filled from background color.booleanReturns whether iPhone PNG unpremultiply is enabled.voidregisterDecoder(String format, StbImage.StbDecoderInstancer instancer, Predicate<ByteBuffer> formatChecker) Registers a decoder type and its format probe.voidsetConvertIphonePngToRgb(boolean convertIphonePngToRgb) Enables/disables automatic iPhone PNG BGR->RGB conversion for CgBI PNGs.voidsetFillGifFirstFrameBackground(boolean fillGifFirstFrameBackground) Enables/disables logical-screen background fill for untouched pixels on GIF first frame.voidsetUnpremultiplyOnLoad(boolean unpremultiplyOnLoad) Enables/disables unpremultiply for iPhone PNG alpha data.voidUnregisters all decoders, leaving the instance with no supported formats.voidunregisterDecoder(String format) Unregisters a decoder previously added withregisterDecoder(String, StbDecoderInstancer, Predicate).voidunregisterDecoder(StbImage.StbDecoderInstancer instancer) Unregisters a decoder by its instancer reference.
-
Constructor Details
-
StbImage
public StbImage()Creates an instance using heap allocation (ByteBuffer.allocate(int)). -
StbImage
Creates an instance with a custom output buffer allocator.- Parameters:
allocator- allocation strategy, or null to useByteBuffer.allocate(int)
-
-
Method Details
-
registerDecoder
public void registerDecoder(String format, StbImage.StbDecoderInstancer instancer, Predicate<ByteBuffer> formatChecker) Registers a decoder type and its format probe.- Parameters:
format- format name of the decoderinstancer- decoder class with constructor (ByteBuffer, IntFunction, boolean)formatChecker- predicate that returns true when buffer matches decoder format
-
unregisterDecoder
Unregisters a decoder previously added withregisterDecoder(String, StbDecoderInstancer, Predicate).- Parameters:
format- format name of the decoder to remove
-
unregisterDecoder
Unregisters a decoder by its instancer reference.- Parameters:
instancer- decoder class reference to remove
-
unregisterAllDecoders
public void unregisterAllDecoders()Unregisters all decoders, leaving the instance with no supported formats. -
getRegisteredFormats
Returns a list of registered decoder formats.- Returns:
- list of format names
-
getDecoderCount
public int getDecoderCount()Returns the number of registered decoders.- Returns:
- decoder count
-
setConvertIphonePngToRgb
public void setConvertIphonePngToRgb(boolean convertIphonePngToRgb) Enables/disables automatic iPhone PNG BGR->RGB conversion for CgBI PNGs.- Parameters:
convertIphonePngToRgb- true to convert CgBI channel order to RGB(A)
-
isConvertIphonePngToRgb
public boolean isConvertIphonePngToRgb()Returns whether iPhone PNG channel conversion is enabled.- Returns:
- true when CgBI PNGs are converted from BGR(A) to RGB(A)
-
setUnpremultiplyOnLoad
public void setUnpremultiplyOnLoad(boolean unpremultiplyOnLoad) Enables/disables unpremultiply for iPhone PNG alpha data.- Parameters:
unpremultiplyOnLoad- true to unpremultiply by alpha during decode
-
isUnpremultiplyOnLoad
public boolean isUnpremultiplyOnLoad()Returns whether iPhone PNG unpremultiply is enabled.- Returns:
- true when unpremultiply is enabled
-
setFillGifFirstFrameBackground
public void setFillGifFirstFrameBackground(boolean fillGifFirstFrameBackground) Enables/disables logical-screen background fill for untouched pixels on GIF first frame.True matches stb_image behavior. False keeps untouched pixels transparent.
- Parameters:
fillGifFirstFrameBackground- true to match stb-style first-frame fill
-
isFillGifFirstFrameBackground
public boolean isFillGifFirstFrameBackground()Returns whether GIF first-frame untouched pixels are filled from background color.- Returns:
- true when stb-style first-frame background fill is enabled
-
getDecoder
Selects and instantiates a decoder for the provided buffer.- Parameters:
buffer- input image bytesflipVertically- true to vertically flip decoded output- Returns:
- matching decoder instance
-