@@ -14,12 +14,27 @@ public class PreviewManager : MonoBehaviour
1414 public Sprite successSprite ;
1515 public Sprite errorSprite ;
1616
17+ [ Header ( "Adjustments" ) ]
18+ public GameObject contrastPanel ;
19+ public GameObject brightnessPanel ;
20+ public UnityEngine . UI . Text contrastText ;
21+ public UnityEngine . UI . Text brightnessText ;
22+ public Slider contrastSlider ;
23+ public Slider brightnessSlider ;
24+
25+ static Texture2D warpedTexture ;
26+
27+ void OnDisable ( )
28+ {
29+ contrastSlider . value = brightnessSlider . value = 0 ;
30+ }
31+
1732 public void ShowPreview ( )
1833 {
1934 int width = filteredRawImage . mainTexture . width ;
2035 int height = filteredRawImage . mainTexture . height ;
2136
22- Texture2D warpedTexture = new Texture2D ( width , height , TextureFormat . RGB24 , false ) ;
37+ warpedTexture = new Texture2D ( width , height , TextureFormat . RGB24 , false ) ;
2338 Graphics . CopyTexture ( filteredRawImage . mainTexture , warpedTexture ) ;
2439
2540 Mat warpedMat = new Mat ( height , width , CvType . CV_8UC3 ) ;
@@ -35,6 +50,7 @@ public void ShowPreview()
3550
3651 warpedMat . Dispose ( ) ;
3752 newTexture = null ;
53+ warpedTexture = null ;
3854 System . GC . Collect ( ) ;
3955
4056 gameObject . SetActive ( true ) ;
@@ -48,7 +64,7 @@ public void RotateTexture(bool clockWise)
4864
4965 public void Sharpen ( )
5066 {
51- Texture2D warpedTexture = new Texture2D ( previewRawImage . mainTexture . width , previewRawImage . mainTexture . height , TextureFormat . RGB24 , false ) ;
67+ warpedTexture = new Texture2D ( previewRawImage . mainTexture . width , previewRawImage . mainTexture . height , TextureFormat . RGB24 , false ) ;
5268 Graphics . CopyTexture ( previewRawImage . texture , warpedTexture ) ;
5369
5470 Mat initMat = new Mat ( warpedTexture . height , warpedTexture . width , CvType . CV_8UC3 ) ;
@@ -63,11 +79,13 @@ public void Sharpen()
6379 initMat . Dispose ( ) ;
6480 finalMat . Dispose ( ) ;
6581 previewRawImage . texture = warpedTexture ;
82+ warpedTexture = null ;
83+ System . GC . Collect ( ) ;
6684 }
6785
6886 public void SaveTextureToDisk ( )
6987 {
70- Texture2D warpedTexture = new Texture2D ( previewRawImage . mainTexture . width , previewRawImage . mainTexture . height , TextureFormat . RGB24 , false ) ;
88+ warpedTexture = new Texture2D ( previewRawImage . mainTexture . width , previewRawImage . mainTexture . height , TextureFormat . RGB24 , false ) ;
7189 Graphics . CopyTexture ( previewRawImage . texture , warpedTexture ) ;
7290
7391 string path = GetStorageDirectory ( ) ;
@@ -115,6 +133,70 @@ IEnumerator ShowDialog(bool saveSuccessful)
115133 saveDialog . SetActive ( false ) ;
116134 }
117135
136+ //public void UpdateContrast()
137+ //{
138+ // warpedTexture = new Texture2D(filteredRawImage.mainTexture.width, filteredRawImage.mainTexture.height, TextureFormat.RGB24, false);
139+ // Graphics.CopyTexture(filteredRawImage.texture, warpedTexture);
140+
141+ // Mat initMat = new Mat(warpedTexture.height, warpedTexture.width, CvType.CV_8UC3);
142+ // Utils.texture2DToMat(warpedTexture, initMat);
143+
144+ // int val = (int)contrastSlider.value;
145+
146+ // Debug.Log(1 + val / 10f);
147+
148+ // initMat *= (1 + val / 10f);
149+
150+ // Utils.matToTexture2D(initMat, warpedTexture);
151+
152+ // contrastText.text = string.Format("Contrast +{0}0%", val);
153+
154+ // initMat.Dispose();
155+ // previewRawImage.texture = warpedTexture;
156+ // warpedTexture = null;
157+ // System.GC.Collect();
158+ //}
159+
160+ public void UpdateContrastBrightness ( )
161+ {
162+ warpedTexture = new Texture2D ( filteredRawImage . mainTexture . width , filteredRawImage . mainTexture . height , TextureFormat . RGB24 , false ) ;
163+ Graphics . CopyTexture ( filteredRawImage . texture , warpedTexture ) ;
164+
165+ Mat initMat = new Mat ( warpedTexture . height , warpedTexture . width , CvType . CV_8UC3 ) ;
166+ Utils . texture2DToMat ( warpedTexture , initMat ) ;
167+
168+ float brightnessVal = brightnessSlider . value * 5 ;
169+ float contrastVal = 1 + contrastSlider . value / 10f ;
170+
171+ Debug . Log ( brightnessVal ) ;
172+ Debug . Log ( contrastVal ) ;
173+
174+ initMat += Scalar . all ( brightnessVal ) ;
175+ initMat *= ( contrastVal ) ;
176+
177+ Utils . matToTexture2D ( initMat , warpedTexture ) ;
178+
179+ brightnessText . text = string . Format ( "Brightness +{0}" , brightnessVal ) ;
180+ contrastText . text = string . Format ( "Contrast +{0}0%" , contrastVal ) ;
181+
182+ initMat . Dispose ( ) ;
183+ previewRawImage . texture = warpedTexture ;
184+ warpedTexture = null ;
185+ System . GC . Collect ( ) ;
186+ }
187+
188+ public void ToggleContrast ( )
189+ {
190+ brightnessPanel . SetActive ( false ) ;
191+ contrastPanel . SetActive ( ! contrastPanel . activeInHierarchy ) ;
192+ }
193+
194+ public void ToggleBrightness ( )
195+ {
196+ contrastPanel . SetActive ( false ) ;
197+ brightnessPanel . SetActive ( ! brightnessPanel . activeInHierarchy ) ;
198+ }
199+
118200 void ScanMedia ( string fileName )
119201 {
120202 if ( Application . platform != RuntimePlatform . Android )
0 commit comments