Skip to content

Commit 3c70056

Browse files
committed
Fixed Aspect Ratio of Final Texture
1 parent 2e8b735 commit 3c70056

File tree

4 files changed

+81
-34
lines changed

4 files changed

+81
-34
lines changed

Assets/Scripts/Managers/CropSizeManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ Dimm GetWideScreenPixels(WideScreenResolution screenResolution)
148148
/// </summary>
149149
/// <param name="paperType"></param>
150150
/// <returns>Dimmensions of the Paper in Pixels</returns>
151-
Dimm GetPaperPixels(ISOPaperType paperType)
151+
public Dimm GetPaperPixels(ISOPaperType paperType)
152152
{
153153
switch (paperType)
154154
{

Assets/Scripts/Managers/PreviewManager.cs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,34 @@ void OnDisable()
3131

3232
public void ShowPreview()
3333
{
34+
int newWidth = (int)(filteredRawImage.mainTexture.width * WarpManager.DeltaWidth);
35+
int newHeight = (int)(filteredRawImage.mainTexture.height * WarpManager.DeltaHeight);
36+
3437
int width = filteredRawImage.mainTexture.width;
3538
int height = filteredRawImage.mainTexture.height;
3639

40+
//Debug.LogWarning("Delta Width: " + WarpManager.DeltaWidth);
41+
//Debug.LogWarning("Delta Height: " + WarpManager.DeltaHeight);
42+
43+
//Debug.LogWarning("Width: " + width);
44+
//Debug.LogWarning("Height: " + height);
45+
46+
//Debug.LogWarning("New Width: " + newWidth);
47+
//Debug.LogWarning("New Height: " + newHeight);
48+
3749
warpedTexture = new Texture2D(width, height, TextureFormat.RGB24, false);
3850
Graphics.CopyTexture(filteredRawImage.mainTexture, warpedTexture);
3951

4052
Mat warpedMat = new Mat(height, width, CvType.CV_8UC3);
4153
Utils.texture2DToMat(warpedTexture, warpedMat);
4254

43-
Texture2D newTexture = new Texture2D(width, height, TextureFormat.RGB24, false);
55+
Texture2D newTexture = new Texture2D(newWidth, newHeight, TextureFormat.RGB24, false);
4456

45-
Imgproc.resize(warpedMat, warpedMat, new Size(width, height));
57+
Imgproc.resize(warpedMat, warpedMat, new Size(newWidth, newHeight));
4658
Utils.matToTexture2D(warpedMat, newTexture);
4759

4860
previewRawImage.texture = newTexture;
49-
ratioFitter.aspectRatio = width / (float)height;
61+
ratioFitter.aspectRatio = newWidth / (float)newHeight;
5062

5163
warpedMat.Dispose();
5264
newTexture = null;
@@ -225,6 +237,8 @@ string GetStorageDirectory()
225237

226238
public void ResetTexture()
227239
{
240+
brightnessPanel.SetActive(false);
241+
contrastPanel.SetActive(false);
228242
ShowPreview();
229243
}
230244

Assets/Scripts/Managers/WarpManager.cs

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ public class WarpManager : MonoBehaviour
1212

1313
Vector2 origSizeDelta;
1414

15-
public const float WIDTH = 750;
16-
public static float HEIGHT = WIDTH * (StreamManager.WebcamSize.y / (float)StreamManager.WebcamSize.x);
15+
public static float WIDTH = 750;
16+
public static float HEIGHT;// = WIDTH * CropSizeManager.CurrentDimmension.height / (float)CropSizeManager.CurrentDimmension.width;// (StreamManager.WebcamSize.y / (float)StreamManager.WebcamSize.x);
1717

18-
const float FILTER_WIDTH = 500;
19-
static float FILTER_HEIGHT = FILTER_WIDTH * (StreamManager.WebcamSize.y/ (float)StreamManager.WebcamSize.x);
18+
static float FILTER_WIDTH = 500;
19+
static float FILTER_HEIGHT;// = FILTER_WIDTH * CropSizeManager.CurrentDimmension.height / (float)CropSizeManager.CurrentDimmension.width;//(StreamManager.WebcamSize.y / (float)StreamManager.WebcamSize.x);
2020

2121
public const float X_PADDING = 150;
2222
public const float Y_PADDING = 50;
@@ -30,6 +30,16 @@ public class WarpManager : MonoBehaviour
3030
void Start()
3131
{
3232
DeltaHeight = DeltaWidth = 1;
33+
//Debug.LogWarning("Orig\n" + warpedImage.mainTexture.width + " " + warpedImage.mainTexture.height);
34+
}
35+
36+
public static void SetupDimm()
37+
{
38+
WIDTH = 750;
39+
HEIGHT = WIDTH * CropSizeManager.CurrentDimmension.height / (float)CropSizeManager.CurrentDimmension.width;// (StreamManager.WebcamSize.y / (float)StreamManager.WebcamSize.x);
40+
41+
FILTER_WIDTH = 500;
42+
FILTER_HEIGHT = FILTER_WIDTH * CropSizeManager.CurrentDimmension.height / (float)CropSizeManager.CurrentDimmension.width;//(StreamManager.WebcamSize.y / (float)StreamManager.WebcamSize.x);
3343
}
3444

3545
public void ResizeImage()
@@ -38,15 +48,16 @@ public void ResizeImage()
3848
DeltaWidth = warpedImage.rectTransform.rect.width / WIDTH;
3949
DeltaHeight = warpedImage.rectTransform.rect.height / HEIGHT;
4050

51+
//Debug.LogWarning("WIDTH: " + WIDTH + "\nRect Width: " + warpedImage.rectTransform.rect.width);
52+
//Debug.LogWarning("HEIGHT: " + HEIGHT + "\nRect Height: " + warpedImage.rectTransform.rect.height);
53+
4154
filteredImage.rectTransform.sizeDelta = new Vector2(FILTER_WIDTH * DeltaWidth, FILTER_HEIGHT * DeltaHeight);
4255
}
4356

4457
public void UpdateHandlers()
4558
{
46-
//Debug.LogFormat("Width: {0}, Height: {1}", WIDTH, HEIGHT);
47-
//Debug.LogFormat("X Padding: {0}, Y Padding: {1}", X_PADDING, Y_PADDING);
48-
//Debug.LogFormat("X Offset: {0}, Y Offset: {1}", X_OFFSET, Y_OFFSET);
49-
59+
SetupDimm();
60+
5061
warpedImage.rectTransform.position = new Vector2(X_PADDING, Screen.height - Y_PADDING);
5162
warpedImage.rectTransform.sizeDelta = new Vector2(WIDTH, HEIGHT);
5263

Assets/_Scenes/Transformations.unity

Lines changed: 44 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3453,6 +3453,11 @@ PrefabInstance:
34533453
propertyPath: m_Name
34543454
value: Right_Bottom
34553455
objectReference: {fileID: 0}
3456+
- target: {fileID: 4300375211899077909, guid: 3306ae3e592240b42bc8be96421056e1,
3457+
type: 3}
3458+
propertyPath: pointerType
3459+
value: 2
3460+
objectReference: {fileID: 0}
34563461
- target: {fileID: 4300375211899077905, guid: 3306ae3e592240b42bc8be96421056e1,
34573462
type: 3}
34583463
propertyPath: m_LocalPosition.x
@@ -3558,11 +3563,6 @@ PrefabInstance:
35583563
propertyPath: m_Pivot.y
35593564
value: 0.5
35603565
objectReference: {fileID: 0}
3561-
- target: {fileID: 4300375211899077909, guid: 3306ae3e592240b42bc8be96421056e1,
3562-
type: 3}
3563-
propertyPath: pointerType
3564-
value: 2
3565-
objectReference: {fileID: 0}
35663566
- target: {fileID: 1558920371333794789, guid: 3306ae3e592240b42bc8be96421056e1,
35673567
type: 3}
35683568
propertyPath: m_AnchoredPosition.x
@@ -3756,6 +3756,11 @@ PrefabInstance:
37563756
propertyPath: m_Name
37573757
value: Left_Bottom
37583758
objectReference: {fileID: 0}
3759+
- target: {fileID: 4300375211899077909, guid: 3306ae3e592240b42bc8be96421056e1,
3760+
type: 3}
3761+
propertyPath: pointerType
3762+
value: 1
3763+
objectReference: {fileID: 0}
37593764
- target: {fileID: 4300375211899077905, guid: 3306ae3e592240b42bc8be96421056e1,
37603765
type: 3}
37613766
propertyPath: m_LocalPosition.x
@@ -3861,11 +3866,6 @@ PrefabInstance:
38613866
propertyPath: m_Pivot.y
38623867
value: 0.5
38633868
objectReference: {fileID: 0}
3864-
- target: {fileID: 4300375211899077909, guid: 3306ae3e592240b42bc8be96421056e1,
3865-
type: 3}
3866-
propertyPath: pointerType
3867-
value: 1
3868-
objectReference: {fileID: 0}
38693869
- target: {fileID: 1558920371333794789, guid: 3306ae3e592240b42bc8be96421056e1,
38703870
type: 3}
38713871
propertyPath: m_AnchoredPosition.x
@@ -4791,7 +4791,7 @@ MonoBehaviour:
47914791
m_Name:
47924792
m_EditorClassIdentifier:
47934793
m_Material: {fileID: 0}
4794-
m_Color: {r: 0, g: 0, b: 0, a: 1}
4794+
m_Color: {r: 0.3137255, g: 0.3137255, b: 0.3137255, a: 1}
47954795
m_RaycastTarget: 1
47964796
m_OnCullStateChanged:
47974797
m_PersistentCalls:
@@ -5358,7 +5358,7 @@ MonoBehaviour:
53585358
m_Name:
53595359
m_EditorClassIdentifier:
53605360
m_Material: {fileID: 0}
5361-
m_Color: {r: 0, g: 0, b: 0, a: 1}
5361+
m_Color: {r: 0.3137255, g: 0.3137255, b: 0.3137255, a: 1}
53625362
m_RaycastTarget: 1
53635363
m_OnCullStateChanged:
53645364
m_PersistentCalls:
@@ -5740,6 +5740,28 @@ MonoBehaviour:
57405740
m_StringArgument:
57415741
m_BoolArgument: 0
57425742
m_CallState: 2
5743+
- m_Target: {fileID: 1643450434}
5744+
m_MethodName: SetActive
5745+
m_Mode: 6
5746+
m_Arguments:
5747+
m_ObjectArgument: {fileID: 0}
5748+
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
5749+
m_IntArgument: 0
5750+
m_FloatArgument: 0
5751+
m_StringArgument:
5752+
m_BoolArgument: 0
5753+
m_CallState: 2
5754+
- m_Target: {fileID: 397413077}
5755+
m_MethodName: SetActive
5756+
m_Mode: 6
5757+
m_Arguments:
5758+
m_ObjectArgument: {fileID: 0}
5759+
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
5760+
m_IntArgument: 0
5761+
m_FloatArgument: 0
5762+
m_StringArgument:
5763+
m_BoolArgument: 0
5764+
m_CallState: 2
57435765
m_TypeName: UnityEngine.UI.Button+ButtonClickedEvent, UnityEngine.UI, Version=1.0.0.0,
57445766
Culture=neutral, PublicKeyToken=null
57455767
--- !u!114 &1773812329
@@ -5827,6 +5849,11 @@ PrefabInstance:
58275849
propertyPath: m_Name
58285850
value: Left_Top
58295851
objectReference: {fileID: 0}
5852+
- target: {fileID: 4300375211899077909, guid: 3306ae3e592240b42bc8be96421056e1,
5853+
type: 3}
5854+
propertyPath: pointerType
5855+
value: 3
5856+
objectReference: {fileID: 0}
58305857
- target: {fileID: 4300375211899077905, guid: 3306ae3e592240b42bc8be96421056e1,
58315858
type: 3}
58325859
propertyPath: m_LocalPosition.x
@@ -5932,11 +5959,6 @@ PrefabInstance:
59325959
propertyPath: m_Pivot.y
59335960
value: 0.5
59345961
objectReference: {fileID: 0}
5935-
- target: {fileID: 4300375211899077909, guid: 3306ae3e592240b42bc8be96421056e1,
5936-
type: 3}
5937-
propertyPath: pointerType
5938-
value: 3
5939-
objectReference: {fileID: 0}
59405962
- target: {fileID: 1558920371333794789, guid: 3306ae3e592240b42bc8be96421056e1,
59415963
type: 3}
59425964
propertyPath: m_AnchorMin.y
@@ -6789,6 +6811,11 @@ PrefabInstance:
67896811
propertyPath: m_Name
67906812
value: Right_Top
67916813
objectReference: {fileID: 0}
6814+
- target: {fileID: 4300375211899077909, guid: 3306ae3e592240b42bc8be96421056e1,
6815+
type: 3}
6816+
propertyPath: pointerType
6817+
value: 4
6818+
objectReference: {fileID: 0}
67926819
- target: {fileID: 4300375211899077905, guid: 3306ae3e592240b42bc8be96421056e1,
67936820
type: 3}
67946821
propertyPath: m_LocalPosition.x
@@ -6894,11 +6921,6 @@ PrefabInstance:
68946921
propertyPath: m_Pivot.y
68956922
value: 0.5
68966923
objectReference: {fileID: 0}
6897-
- target: {fileID: 4300375211899077909, guid: 3306ae3e592240b42bc8be96421056e1,
6898-
type: 3}
6899-
propertyPath: pointerType
6900-
value: 4
6901-
objectReference: {fileID: 0}
69026924
- target: {fileID: 1558920371333794789, guid: 3306ae3e592240b42bc8be96421056e1,
69036925
type: 3}
69046926
propertyPath: m_LocalRotation.z

0 commit comments

Comments
 (0)