20 #include "../gpu/bgl.h"
23 using namespace NNets;
29 const std::string&
name,
36 input(nullptr), output(nullptr), program(nullptr),
37 linearInterpolation(linearInterp), centerCrop(centerCrop),
rotation(0)
49 this->
input = &texture;
56 "ImageSampler output size mismatch");
64 ImageSamplerDeserializer() : Deserializer(
"image_sampler") {}
79 IntPoint(block.
get<
int>(
"output_width"), block.
get<
int>(
"output_height")),
80 block.
get<
bool>(
"center_crop",
true),
81 block.
get<
bool>(
"linear_interp",
true)
93 {
"_type",
"image_sampler" },
97 {
"center_crop",
centerCrop ?
"true" :
"false" }
129 gl_FragColor = %s(%s, %s);
135 program = bank(gpu, code, enableExtTexExt);
158 float hMargin = 0, vMargin = 0;
175 Point topLeft(texCoords.
a), topRight(texCoords.
b.
x, texCoords.
a.
y), bottomLeft(texCoords.
a.
x, texCoords.
b.
y), bottomRight(texCoords.
b), tmp;
179 bottomLeft = bottomRight;
180 bottomRight = topRight;
186 topLeft = bottomRight;
189 topRight = bottomLeft;
195 topRight = bottomRight;
196 bottomRight = bottomLeft;
A key-value pair set storing pieces of arbitrary data (chunks) under string keys.
Basic class: task and memory management, any kind of static data.
void enable(const GraphicPipeline &gpu)
static const char * DIALECT_SAMPLER_DECL_TYPE
glsl type name to declare a texture in Beatmup dialect
static const char * DIALECT_TEXTURE_SAMPLING_FUNC
glsl function name to sample a texture in Beatmup dialect
Stores linked GLSL programs and their associated fragment shader codes.
void release(GraphicPipeline &gpu, GL::RenderingProgram *program)
Marks a program as unused any more.
void blend(bool onScreen)
static const char * TEXTURE_COORDINATES_ID
Texture coordinates shader variable name in vertex shader.
static const char * DECLARE_TEXTURE_COORDINATES_IN_FRAG
Declaring texture coordinates in fragment shader.
virtual const int getHeight() const =0
Height of the texture in pixels.
virtual const TextureFormat getTextureFormat() const =0
Returns the texture format specifying how the shader must interpret the data.
virtual const int getWidth() const =0
Width of the texture in pixels.
Internal low-level GPU control API.
static Rectangle getTextureCoordinates(const Rectangle &area, const IntPoint &size, const IntPoint &sampling)
Computes floating-point texture coordinates for pixel-accurate sampling: a texture gets sampled exact...
void bindOutput(AbstractBitmap &bitmap)
Binds a bitmap to the pipeline output.
void setTextureCoordinates(const Rectangle &coords)
Specifies texture coordinates for the next rendering pass.
void bind(GL::TextureHandler &texture, size_t texUnit, const TextureParam param)
static void check(const bool condition, const std::string &message)
T get(const std::string &key) const
Returns a value by key casted to a given type.
Enables construction of an operation from its serialized representation.
Abstract neural net operation (layer).
std::string getName() const
void prepare(GraphicPipeline &gpu, ChunkCollection &data, GL::ProgramBank &bank)
Compiles GLSL shaders.
void execute(TaskThread &thread, GraphicPipeline &gpu)
Executes the operation.
bool linearInterpolation
if true, the input image is linearly interpolated when possible
void getOutput(GL::TextureHandler *&texture, int index=0)
Returns a GL::TextureHandler bound to a specific operation output.
std::map< std::string, std::string > serialize() const
Returns a serialized representation of th operation;.
void setOutput(GL::TextureHandler &texture, int outputIndex=0)
static bool initDeserializer()
Sets up deserialization of the operation.
GL::TextureHandler * output
bool centerCrop
if true, a center crop is performed to sample the output image from the input; otherwise the input is...
GL::TextureHandler * input
void disconnect()
Assigns empty inputs and outputs.
ImageSampler(const std::string &name, const IntPoint &size, bool centerCrop=true, bool linearInterp=true)
Creates an instance of image preprocessing operation.
GL::RenderingProgram * program
int rotation
clockwise rotation to apply to the input image; 1 unit = 90 degrees
void setInput(GL::TextureHandler &texture, int inputIndex=0)
unsigned long countTexelFetches() const
Counts (approximate) number of texels fetches.
static void check(const bool condition, const std::string &message)
StringBuilder & printf(const char *format,...)
StringBuilder including a string container.
static const char * UNIFORM_INPUT
CustomPoint< int > IntPoint
CustomRectangle< float > Rectangle
@ INTERP_LINEAR
bilinear pixel interpolation
@ INTERP_NEAREST
nearest neighbor pixel interpolation
std::string to_string(Beatmup::NNets::ActivationFunction function)
return(jlong) new Beatmup jlong jstring name
JNIEnv jlong jint rotation