2017-09-11 1 views
1

이미지에 대한 많은 해결 효과를 얻었습니다. 그러나 나는 선택 GPUImage (GPUImageLookupFilter) 내 이미지를 확인하십시오.
내 소스 코드를 사용합니다. 나 라이브러리에 비디오 또는 선택 많은 이미지 배열의 이미지 (엄지 손가락으로 작동 할 때
IO - Objective-c GPUImage 조회 필터는 조회 이미지와 함께 효과를냅니다. 4x4

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; 


우선 전 조회 화상의 8x8 (512 2)

enter image description here
를 사용하지만) 메모리가 더 높습니다.
작은 조회 이미지 (4x4)를 사용하면 메모리를 줄일 수 있다고 생각합니다. 조회 이미지 4x4 (16)를 만듭니다.

enter image description here
와 나는 GPUImageLookupFilter의 편집 코드를 시도했지만 작동하지.

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); 
} 


날 이미지 4 × 4와 코드가 작동을 편집 할 수 있습니다.
고맙습니다!.

답변

1

다음 알고리즘은 룩업 텍스처의 크기에 상관없이 작동합니다. tiles을 x 및 y 방향의 타일 수에 맞춰야 만하고 색상 검색 텍스처의 전체 크기에 colTexSize을 적용하면됩니다.
알고리즘은 고정 크기 값을 제외하고는 원래 알고리즘과 동일하지만 tilescolTexSize 변수로 바뀌 었습니다.

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); 
} 
+0

왜 63.0을 변경하지 않습니까? 나는 15.0을 바꾼다? –

+0

왜 63입니까? 63 = 2^6 - 1? 감사합니다. –

+0

. 그것은 작동합니다. 63.0은 알 수 없습니다 :). –