13 #include <OpenGL/CGLMacro.h>
18 "title" :
"VuoImageResize",
30 \n#include
"VuoGlslAlpha.glsl"
32 varying vec2 fragmentTextureCoordinate;
33 uniform sampler2D texture;
37 bool outOfBounds(vec2 coord)
39 return coord.x < 0 || coord.x > 1 || coord.y < 0 || coord.y > 1;
44 vec2 uv = (fragmentTextureCoordinate - offset) * scale;
45 gl_FragColor = outOfBounds(uv) ? vec4(0.,0.,0.,0.) : VuoGlsl_sample(texture, uv);
53 \n#include
"VuoGlslAlpha.glsl"
55 varying vec2 fragmentTextureCoordinate;
56 uniform sampler2DRect texture;
59 uniform vec2 textureSize;
61 bool outOfBounds(vec2 coord)
63 return coord.x < 0 || coord.x > 1 || coord.y < 0 || coord.y > 1;
68 vec2 uv = (fragmentTextureCoordinate - offset) * scale;
69 gl_FragColor = outOfBounds(uv) ? vec4(0.,0.,0.,0.) : VuoGlsl_sampleRect(texture, uv * textureSize);
120 if (sizingMode == VuoSizingMode_Proportional)
123 int targetWidth = image->pixelsWide;
124 int targetHeight = image->pixelsHigh;
125 if (image->pixelsWide > width)
128 targetHeight *= (float)width / image->pixelsWide;
130 if (targetHeight > height)
132 targetWidth *= (float)height / targetHeight;
133 targetHeight = height;
136 width =
MAX(1, targetWidth);
137 height =
MAX(1, targetHeight);
140 float u = width / (float)(image->pixelsWide);
141 float v = height / (float)(image->pixelsHigh);
143 VuoPoint2d scale = (VuoPoint2d) { 1, 1 };
144 VuoPoint2d offset = (VuoPoint2d) { 0, 0 };
148 case VuoSizingMode_Fit:
149 if( u < v && u * image->pixelsHigh < height)
151 scale = (VuoPoint2d) { 1, height/(image->pixelsHigh*u) };
152 offset = (VuoPoint2d) { 0, ((height-(image->pixelsHigh*u))/2)/height };
156 scale = (VuoPoint2d) { width/(image->pixelsWide*v), 1 };
157 offset = (VuoPoint2d) { ((width-(image->pixelsWide*v))/2)/width, 0 };
161 case VuoSizingMode_Fill:
164 scale = (VuoPoint2d) { 1, height/(image->pixelsHigh*u) };
165 offset = (VuoPoint2d) { 0, ((height-(image->pixelsHigh*u))/2)/height };
169 scale = (VuoPoint2d) { width/(image->pixelsWide*v), 1 };
170 offset = (VuoPoint2d) { ((width-(image->pixelsWide*v))/2)/width, 0 };
180 if (image->glTextureTarget == GL_TEXTURE_2D)
181 shader = resize->shader;
182 else if (image->glTextureTarget == GL_TEXTURE_RECTANGLE_ARB)
184 shader = resize->shaderRect;