Nuke Olaf - Log Store
[Android] ์๋๋ก์ด๋ - natario1/CameraView ์นด๋ฉ๋ผ ํํฐ ๋ผ์ด๋ธ๋ฌ๋ฆฌ ๋ถ์ ๋ณธ๋ฌธ
[Android] ์๋๋ก์ด๋ - natario1/CameraView ์นด๋ฉ๋ผ ํํฐ ๋ผ์ด๋ธ๋ฌ๋ฆฌ ๋ถ์
NukeOlaf 2020. 1. 4. 16:29https://github.com/natario1/CameraView
1. CameraView ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ ์ฌ์ง์ ์ดฌ์ํ๊ฑฐ๋ ๋์์์ ๋ นํํ๊ธฐ ์ฝ๋๋ก ๋ง๋ค์ด์ง ๋ผ์ด๋ธ๋ฌ๋ฆฌ์ด๋ค.
๊ณต์ ์น์ฌ์ดํธ ์ฃผ์ : https://natario1.github.io/CameraView/
2. CameraView ๋ผ์ด๋ธ๋ฌ๋ฆฌ์์ ์ง์ค์ ์ผ๋ก ๋ณด์์ผ ํ ๋ถ๋ถ์ Real-Time Filter ์ฌ๋ถ์, ํํฐ๋ฅผ ์ปค์คํ
๊ฐ๋ฅํ์ง์ ์ฌ๋ถ์ด๋ค. ๋ํ, ํํฐ์ ๊ฐ๋๋ฅผ ์กฐ์ ํ ์ ์๋์ง๋ ์ดํด๋ณด์์ผ ํ๋ค.
https://natario1.github.io/CameraView/docs/filters
์์ ๋งํฌ๋ CameraView ๊ณต์ ์ฌ์ดํธ์ Real-Time Filter ๋ฌธ์์ด๋ค.
๋ฌธ์์ ์ํ๋ฉด, ๋ฆฌ์ผํ์ ํํฐ๋ ์นด๋ฉ๋ผ ๋ฏธ๋ฆฌ๋ณด๊ธฐ๋ทฐ๊ฐ ์์ฑ๋๋ ์์ ์ ์ ์ฉ๋๋ค๊ณ ํ๋ค.
์นด๋ฉ๋ผ ํํฐ๋ XML attribute ์์ ์ ์ฉํ ์ ์๊ณ , ์นด๋ฉ๋ผ ๊ฐ์ฒด์ ์๋ช ์ฃผ๊ธฐ๋์ cameraView.setFilter() ๋ฅผ ์ด์ฉํด ์ธ์ ๋ ์ง ์ ์ฉํ ์ ์๋ค.
cameraView.setFilter(Filters.BLACK_AND_WHITE.newInstance());
cameraView.setFilter(Filters.VIGNETTE.newInstance());
cameraView.setFilter(Filters.SEPIA.newInstance());
CameraView ์์ ์ ๊ณตํ๋ ํํฐ๋ ๋ค์๊ณผ ๊ฐ๋ค
๊ธฐ๋ณธ ํํฐ๋ฅผ NoFilter( Filters.NONE) ์ด๋ผ๊ณ ํ๋ฉฐ ์ด์ ์ ์ค์ ํ ๋ค๋ฅธ ํํฐ๋ฅผ ์ง์ฐ๊ณ ๋ค์ ์ ์์ผ๋ก ๋๋๋ฆด ์ ์๋ค.
(ํํฐ ํด๋์ค), (ํํฐ ๊ฐ), (XML ๋ฆฌ์์ค ๊ฐ) ์์์ด๋ค
NoFilter | Filters.NONE | @string/cameraview_filter_none |
AutoFixFilter | Filters.AUTO_FIX | @string/cameraview_filter_autofix |
BlackAndWhiteFilter | Filters.BLACK_AND_WHITE | @string/cameraview_filter_black_and_white |
BrightnessFilter | Filters.BRIGHTNESS | @string/cameraview_filter_brightness |
ContrastFilter | Filters.CONTRAST | @string/cameraview_filter_contrast |
CrossProcessFilter | Filters.CROSS_PROCESS | @string/cameraview_filter_cross_process |
DocumentaryFilter | Filters.DOCUMENTARY | @string/cameraview_filter_documentary |
DuotoneFilter | Filters.DUOTONE | @string/cameraview_filter_duotone |
FillLightFilter | Filters.FILL_LIGHT | @string/cameraview_filter_fill_light |
GammaFilter | Filters.GAMMA | @string/cameraview_filter_gamma |
GrainFilter | Filters.GRAIN | @string/cameraview_filter_grain |
GrayscaleFilter | Filters.GRAYSCALE | @string/cameraview_filter_grayscale |
HueFilter | Filters.HUE | @string/cameraview_filter_hue |
InvertColorsFilter | Filters.INVERT_COLORS | @string/cameraview_filter_invert_colors |
LomoishFilter | Filters.LOMOISH | @string/cameraview_filter_lomoish |
PosterizeFilter | Filters.POSTERIZE | @string/cameraview_filter_posterize |
SaturationFilter | Filters.SATURATION | @string/cameraview_filter_saturation |
SepiaFilter | Filters.SEPIA | @string/cameraview_filter_sepia |
SharpnessFilter | Filters.SHARPNESS | @string/cameraview_filter_sharpness |
TemperatureFilter | Filters.TEMPERATURE | @string/cameraview_filter_temperature |
TintFilter | Filters.TINT | @string/cameraview_filter_tint |
VignetteFilter | Filters.VIGNETTE | @string/cameraview_filter_vignette |
ํํฐ ์ปจํธ๋กค
(1) camerView ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ ํํฐ๋ฅผ ์ปค์คํ ํ์ฌ ์ถ๊ฐํ ์ ์๋ค.
Advanced users with OpenGL experience can create their own filters by implementing the Filter interface and passing in a fragment shader and a vertex shader that will be used for drawing.
OpenGL ๊ฒฝํ์ด ์๋ ๊ณ ๊ธ์ฌ์ฉ์๋ filter ์ธํฐํ์ด์ค๋ฅผ ๊ตฌํํ๊ณ , drawing ์ ์ฌ์ฉ๋ fragment shader ์ vertex shader ๋ฅผ ์ ๋ฌํด์ ์์ฒด ํํฐ๋ฅผ ๋ง๋ค ์ ์๋ค
์ฆ, ํํฐ๋ฅผ ์ปค์คํ ํ๊ธฐ ์ํด์๋ ์ด๋์ ๋ OpenGL ์ ๋ํ ์ง์์ด ํ์ํ๋ค๋ ์๋ฏธ์ธ๊ฒ ๊ฐ๋ค.
Simple filters
static fragment shader ๊ฐ ์๋ ๋จ์ํ ํํฐ์ ๊ฒฝ์ฐ์๋ SimpleFilter ์ธ์คํด์ค๋ฅผ ์์ฑํ๊ธฐ๋ง ํ๋ฉด ์์ ํํฐ๋ฅผ ๊ตฌํํ ์ ์๋ค.
Filter filter = new SimpleFilter(myFragmentShader);
More complex filters
We recommend:
- Subclassing BaseFilter instead of implementing Filter, since that takes care of most of the work
- If accepting parameters, implementing OneParameterFilter or TwoParameterFilter as well
Most of all, the best way of learning is by looking at the current filters implementations in the com.otaliastudios.cameraview.filters package.
๋ณต์กํ ํํฐ ์ฌ์ฉ์ ์์ด์๋ Filter ๋ฅผ ๊ตฌํํ๋ ๊ฒ๋ณด๋ค๋ BaseFilter ํด๋์ค๋ฅผ ์์ํด์ ์ฌ์ฉํ๊ธฐ๋ฅผ ๊ถ์ฅํ๊ณ , com.otaliastudios.cameraview.filters package ๋ฅผ ๊ณต๋ถํ๋ ๊ฒ์ ์ถ์ฒํ๊ณ ์๋ค.
(2) gesture ๋ฅผ ์ง์ํ๋ค
https://natario1.github.io/CameraView/docs/gestures
FilterControl ์ด๋ผ๋ ์ ์ค์ฒ ๋์์ ํตํด ์ค์๊ฐ ํํฐ์ ๋งค๊ฐ๋ณ์๋ฅผ ์ ์ดํ ์ ์๋ค.
FilterControl ์ FILTER_CONTROL_1 ๊ณผ FILTER_CONTROL_2 ๋๊ฐ๊ฐ ์๋๋ฐ, ์ค์๊ฐ ํํฐ์ ํ๋ผ๋ฏธํฐ ๋๊ฐ๋ฅผ ์ ์ดํ ์ ์๋ ์ปจํธ๋กค์ด๋ค.
FILTER_CONTROL_1 | Controls the first parameter (if any) of a real-time filter. | PINCH SCROLL_HORIZONTAL SCROLL_VERTICAL |
FILTER_CONTROL_2 | Controls the second parameter (if any) of a real-time filter. | PINCH SCROLL_HORIZONTAL SCROLL_VERTICAL |
์ด ์ธ์๋ ํ๋ฉด์ ํ๋ํ๊ณ , ๊ธธ๊ฒ ๋๋ฅด๋ ๋ฑ์ ์ ์ค์ฒ๋ฅผ ์ง์ํ๋ค๊ณ ํ๋ค.
(3) camerView ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ DuotoneFilter (์ด์ค ํค ํจ๊ณผ) ๋ฅผ ์ ์ฉํ ์ ์๋ค.
ํํฐ ์ปค์คํ
์ ๊ด๋ จํ์ฌ ํ์ํ ์๋ ์๋ ์ ๋ณด๋ผ๋ ์๊ฐ์ด ๋ค์ด ๊ธฐ์ ํจ.
duotoneFilter.setFirstColor(Color.RED);
duotoneFilter.setSecondColor(Color.GREEN);
๋์คํค์ด๋ ๋์กฐ๋๋ ๋ ๊ฐ์ง ์์์ผ๋ก ๊ตฌ์ฑ๋ ๊ฒ์ ๋งํ๋ค. ๊ทธ๋์ ํ๊ตญ๋ง๋ก๋ 2์ ๊ทธ๋ฆผ์ด๋ผ๊ณ ๋ ํจ.
์ฌ์ง์ผ๋ก ๋ณด๋ฉด ์ดํด๊ฐ ๋น ๋ฅด๋ค. ์๋๋ Blue ์ Red ์์์ผ๋ก ์ด๋ฃจ์ด์ง ๋์คํค ์ด๋ฏธ์ง์ด๋ค.
๊ทธ๋ฌ๋, ์์ ์์๋ ๋์์ด๋๊ฐ ์์ฒด์ ์ผ๋ก ๋ง๋ ๋์คํค ์ด๋ฏธ์ง์ด๊ธฐ ๋๋ฌธ์, CameraView ์ ๋์คํค ํํฐ๋ ์ด๋ค์์ผ๋ก ๊ฒฐ๊ณผ๊ฐ ์ถ๋ ฅ๋ ์ง ํ์ธํด ๋ณด์์ผ ํ๋ค. ์๋์ฒ๋ผ ์์ด ์น์นํ๊ฒ ๋์ฌ ์๋ ์์.
(4) camerView ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ Multi Filter ๋ฅผ ์ ์ฉํ ์ ์๋ค.
ํํฐ ์ปค์คํ
์ ๊ด๋ จํ์ฌ ํ์ํ ์๋ ์๋ ์ ๋ณด๋ผ๋ ์๊ฐ์ด ๋ค์ด ๊ธฐ์ ํจ.
CameraView ๋ ์๋ก ๋ค๋ฅธ ํํฐ ๋๊ฐ๋ฅผ ๋์์ ์ ์ฉํ๋ ๊ธฐ๋ฅ์ ์ ๊ณตํ๋ค.
camera.setFilter(new MultiFilter(firstFilter, secondFilter, thirdFilter));