← 블로그 목록

[Core2026] ETC - Mask

Core2026 › Engine › CPU Engine › ETC

@Nor-s
  • #ThorVG
  • #Core
  • #CPU
  • #Mask
목차

Overview

Paint::mask(Paint* target, MaskMethod method)

One avatar Scene follows Paint::mask, the Mask structure, target and child tasks, a Grayscale8 mask buffer, the Scene color buffer, and final composition. Each section loops locally; the final result stays fixed.
0:00
코드 보기: 마스킹 예제와 소스

마스크와 Scene을 각각 렌더한 뒤 마스크 알파로 합성합니다.

// Canvas target: transparent 16 × 12 ABGR8888 pixels.
// photoPixels: decoded opaque 16 × 12 ABGR8888 pixels.
auto avatar = Scene::gen();
auto photo = Picture::gen();
photo->load(photoPixels, 16, 12, ColorSpace::ABGR8888, true);
auto badge = Shape::gen();
badge->appendCircle(12, 8.5, 2, 2);
badge->fill(35, 160, 100);
avatar->add(photo);
avatar->add(badge);

auto fadeMask = Shape::gen();
fadeMask->appendCircle(8, 5.5, 5, 5);
fadeMask->fill(45, 160, 210, 160);
avatar->mask(fadeMask, MaskMethod::Alpha);
canvas->add(avatar);
canvas->update();
canvas->draw(true);
canvas->sync();

Pixel pipeline

Follow target coverage, badge coverage, group RGBA, matte attenuation, and source-over at the same native Canvas pixel. Independent loops construct bytes, contract all four premultiplied channels, and write pixels; final results stay fixed.
0:00
코드 보기: 마스크 픽셀 연산과 래스터 분기

마스크 알파로 Scene 픽셀을 감쇠한 뒤 대상 픽셀과 합성합니다.

q = MULTIPLY(203, 160) = (203 × 160 + 255) >> 8 = 127
// Group opacity is 255 in this example.
auto tmp = ALPHA_BLEND(*src, alpha(cmp));
*dst = tmp + ALPHA_BLEND(*dst, IA(tmp));

MaskMethod Comparison

Compare None, Alpha, InvAlpha, Luma, InvLuma, Add, Subtract, Intersect, Difference, Lighten, and Darken with the same avatar and partially opaque masks. Native CPU weights are built locally while every final result stays fixed.
0:00
코드 보기: 콘텐츠 마스킹과 마스크 결합 API

콘텐츠에 마스크를 적용하는 방식과 마스크끼리 결합하는 방식을 비교합니다.

content->mask(B, method);  // Alpha, InvAlpha, Luma, InvLuma
A->mask(B, method);       // Add, Subtract, Intersect, Difference, Lighten, Darken
content->mask(A, MaskMethod::Alpha);

Clipping · Viewport