커스텀 코어 이미지 필터를 사용하여 특정 효과를 얻는 OS X 앱을 개발 중입니다 : 이미지의 루미넌스를 다른 이미지의 알파 채널로 설정하십시오. 이미지를 다른 이미지의 마스크로 사용하는 필터가 있지만 세 번째 배경 이미지가 필요합니다. 배경이없는 투명한 부분으로 이미지를 출력해야합니다.커스텀 코어 이미지 필터는 정의되지 않은 크기의 이미지를 생성합니다 - 고정
설명 된대로 in Apple's documentation, 나는 커널 코드를 작성하고 QuartzComposer에서 테스트했습니다. 그것은 예상대로 작동합니다.
kernel vec4 setMask(sampler src, sampler mask)
{
vec4 color = sample(src, samplerCoord(src));
vec4 alpha = sample(mask, samplerCoord(mask));
color.a = alpha.r;
// (mask image is grayscale; any channel colour will do)
return color;
}
하지만 (두 이미지 단위로 직접 응용 프로그램 소스에서 포장) 내 코드에서 필터를 사용하려고하면, 출력 이미지가 밝혀 :
커널 코드는
extent CGRect origin=(x=-8.988465674311579E+307, y=-8.988465674311579E+307) size=(width=1.797693134862316E+308, height=1.797693134862316E+308)
및 그 이상의 처리 (NSImage 비트 맵 표현으로 변환, 파일 쓰기 등)가 실패합니다. 필터 자체가 완벽하게로드되고 (nil이 아님) 생성 된 출력 이미지가 nil이 아니며 올바르지 않은 rect가 있습니다.
편집 : (이 QuartzComposer의 패치 도서관에 나타나도록 또한, 나는, /Library/Graphics/Image Units
및 ~/Library/Graphics/Image Units
모두 내 보낸 영상 장치 (플러그인)을 복사하지만 원본 이미지와 빌보드 렌더러에 연결할 때, 아무것도 그려지지 않습니다 투명 배경).
내가 누락 된 항목이 있습니까?
편집 : 기본 동작은 -[CIFilter apply:]
으로 가정합니다.
- (CIImage*) outputImage
{
CISampler* src = [CISampler samplerWithImage:inputImage];
CISampler* mask = [CISampler samplerWithImage:inputMaskImage];
return [self apply:setMaskKernel, src, mask, nil];
}
그래서 나는 노력이 그것을 변경 :
내 필터 서브 클래스 코드의 -outputImage
구현이 있었다
- (CIImage*) outputImage
{
CISampler* src = [CISampler samplerWithImage:inputImage];
CISampler* mask = [CISampler samplerWithImage:inputMaskImage];
CGRect extent = [inputImage extent];
NSDictionary* options = @{ kCIApplyOptionExtent: @[@(extent.origin.x),
@(extent.origin.y),
@(extent.size.width),
@(extent.size.height)],
kCIApplyOptionDefinition: @[@(extent.origin.x),
@(extent.origin.y),
@(extent.size.width),
@(extent.size.height)]
};
return [self apply:setMaskKernel arguments:@[src, mask] options:options];
}
... 지금은 작동한다!
[여기] (http://stackoverflow.com/questions/9558265/unrecognized-selector-when-attempting-to-access-cifilters-outputimage)와 같이 필터의 이미지 범위를 설정해야 할 수 있습니다. – user1118321
그게 바로 내가 한 것입니다 (편집 참조), 고마워! –