osx - IO - Objective-c GPUImage Lookup Filter make effect with lookup image 4x4 -


i know have many solve make effect image. choice gpuimage (gpuimagelookupfilter) make image.
source code use.

gpuimagepicture *sourceimagepic = [[gpuimagepicture alloc] initwithimage:sourceimage]; gpuimagepicture *lookupimagesource = [[gpuimagepicture alloc] initwithimage:[uiimage imagenamed:@"lookup.png"]]; gpuimagelookupfilter *lookupimagefilter = [[gpuimagelookupfilter alloc] init];  [sourceimagepic addtarget:lookupimagefilter]; [lookupimagesource addtarget:lookupimagefilter]; [lookupimagefilter usenextframeforimagecapture];  [sourceimagepic processimage]; [lookupimagesource processimage]; resultimage = [lookupimagefilter imagefromcurrentframebufferwithorientation:uiimageorientationup];  return resultimage; 


first use lookup image 8x8 (5122)

enter image description here
when working array image (thumb in video or choice many image in library) memory higher.
think if use small lookup image (4x4) memory can reduced. make lookup image 4x4(162).

enter image description here
, try edit code of gpuimagelookupfilter not work.

 void main(){  highp vec4 texturecolor = texture2d(inputimagetexture, texturecoordinate);   highp float bluecolor = texturecolor.b * 63.0;   highp vec2 quad1;  quad1.y = floor(floor(bluecolor) / 8.0);  quad1.x = floor(bluecolor) - (quad1.y * 8.0);   highp vec2 quad2;  quad2.y = floor(ceil(bluecolor) / 8.0);  quad2.x = ceil(bluecolor) - (quad2.y * 8.0);   highp vec2 texpos1;  texpos1.x = (quad1.x * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * texturecolor.r);  texpos1.y = (quad1.y * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * texturecolor.g);   highp vec2 texpos2;  texpos2.x = (quad2.x * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * texturecolor.r);  texpos2.y = (quad2.y * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * texturecolor.g);   lowp vec4 newcolor1 = texture2d(inputimagetexture2, texpos1);  lowp vec4 newcolor2 = texture2d(inputimagetexture2, texpos2);   lowp vec4 newcolor = mix(newcolor1, newcolor2, fract(bluecolor));  gl_fragcolor = mix(texturecolor, vec4(newcolor.rgb, texturecolor.w), intensity); } 


can me edit code work image 4x4.
thank you!.

the following algorithm work size of lookup texture. have adapt tiles number of tiles in x , y direction, , coltexsize full size of color lookup texture.
algorithm identical original algorithm, except constant size values, substituted variable tiles , coltexsize.

void main() {     vec2 tiles      = vec2( 4.0, 4.0 );   // original texture vec2( 8.0, 8.0 )     vec2 coltexsize = vec2( 64.0, 64.0 )  // original texture vec2( 512.0, 512.0 )      highp vec4 texturecolor = texture2d(inputimagetexture, texturecoordinate);      highp float bluecolor = texturecolor.b * ((tiles.x*tiles.y)-1.0);      highp vec2 quad1;     quad1.y = floor(floor(bluecolor) / tiles.y);     quad1.x = floor(bluecolor) - (quad1.y * tiles.x);      highp vec2 quad2;     quad2.y = floor(ceil(bluecolor) / tiles.y);     quad2.x = ceil(bluecolor) - (quad2.y * tiles.x);      highp vec2 texpos1;     texpos1.x = (quad1.x / tiles.x) + 0.5/coltexsize.x + (1.0/(tiles.x - coltexsize.x) * texturecolor.r);     texpos1.y = (quad1.y / tiles.y) + 0.5/coltexsize.y + (1.0/(tiles.y - coltexsize.y) * texturecolor.g);      highp vec2 texpos2;     texpos2.x = (quad2.x / tiles.x) + 0.5/coltexsize.x + (1.0/(tiles.x - coltexsize.x) * texturecolor.r);     texpos2.y = (quad2.y / tiles.y) + 0.5/coltexsize.y + (1.0/(tiles.y - coltexsize.y) * texturecolor.g);      lowp vec4 newcolor1 = texture2d(inputimagetexture2, texpos1);     lowp vec4 newcolor2 = texture2d(inputimagetexture2, texpos2);      lowp vec4 newcolor = mix(newcolor1, newcolor2, fract(bluecolor));     gl_fragcolor = mix(texturecolor, vec4(newcolor.rgb, texturecolor.w), intensity); } 

Comments

Popular posts from this blog

Sort a complex associative array in PHP -

vb.net - How to ignore if a cell is empty nothing -

recursion - Can every recursive algorithm be improved with dynamic programming? -