Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding an X and Y offset to the current crop effect (large refactor) #724

Merged
merged 2 commits into from Sep 4, 2021

Conversation

jonoomph
Copy link
Member

@jonoomph jonoomph commented Sep 3, 2021

Adding an X and Y offset to the current crop effect, to better support previous clip crop parameters (for migrating crop options from OpenShot 2.5.1 to OpenShot 2.6). Also refactoring the crop effect, to actually copy the pixels into a new image buffer.

Below are my notes I used to come up with this logic (for anyone curious what kind of mental juggling is required for this):

0 1 2 3 4 5 6 7 8 9 10
0 1 2 3 4 5 6 7 8 9 10
0 1 2 3 4 5 6 7 8 9 10
0 1 2 3 4 5 6 7 8 9 10
0 1 2 3 4 5 6 7 8 9 10
0 1 2 3 4 5 6 7 8 9 10
0 1 2 3 4 5 6 7 8 9 10
0 1 2 3 4 5 6 7 8 9 10
0 1 2 3 4 5 6 7 8 9 10
0 1 2 3 4 5 6 7 8 9 10
0 1 2 3 4 5 6 7 8 9 10
0 1 2 3 4 5 6 7 8 9 10


1) Apply the bounds (DEST start + length)
   DEST START == SRC START
   LENGTH == CROPPED-WIDTH

    2 3 4 5 6 7 8 
    2 3 4 5 6 7 8 
    2 3 4 5 6 7 8 
    2 3 4 5 6 7 8 


2A) x_offset > 0 = 2
   CHANGE SRC-START += 2 = 4
   CHANGE LENGTH
     IF WIDTH - SRC-START > CROPPED-WIDTH
     IF 11 - 4 => 7
         LENGTH = CROPPED-WIDTH = 7
     ELSE
         LENGTH = WIDTH - SRC-START

    4 5 6 7 8 9 10 
    4 5 6 7 8 9 10
    4 5 6 7 8 9 10
    4 5 6 7 8 9 10


2B) x_offset > 0 = 4
   CHANGE SRC-START += 4 = 6
   CHANGE LENGTH
     IF WIDTH - SRC-START > CROPPED-WIDTH
     IF 11 - 6 => 7
         LENGTH = CROPPED-WIDTH = 7
     ELSE
         LENGTH = WIDTH - SRC-START = 11 - 6 = 5

    6 7 8 9 10 - - 
    6 7 8 9 10 - -
    6 7 8 9 10 - -
    6 7 8 9 10 - -
                        

2C) x_offset > 0
   CHANGE SRC-START = 6
   CHANGE LENGTH
     LENGTH = WIDTH - SRC START
     LENGTH = 11 - 6 = 5
        MAX-LENGTH IS CROPPED-WIDTH = 7

    6 7 8 9 10 - - 
    6 7 8 9 10 - -
    6 7 8 9 10 - -
    6 7 8 9 10 - -
       
                        
3A) x_offset < 0 = -1
   CHANGE SRC START += -1   (from 2 to 1)
     IF SRC-START < 0:
	...
     ELSE
	SRC-START = 1
	LENGTH = CROPPED-WIDTH = 7
    MAX-LENGTH IS CROPPED-WIDTH = 7

    1 2 3 4 5 6 7 
    1 2 3 4 5 6 7 
    1 2 3 4 5 6 7 
    1 2 3 4 5 6 7 
    
    
3B) x_offset < 0 = -4
   CHANGE SRC START += -4   (from 2 to -2)
     IF SRC-START < 0:
        DIFF = abs(SRC-START) = 2
	SRC-START = 0
	DEST-START += DIFF = 2 + abs(-2) = 4
	LENGTH = CROPPED-WIDTH - DIFF = 7 - 2 = 5
     ELSE
	...
    MAX-LENGTH IS CROPPED-WIDTH = 7

    - - 0 1 2 3 4 
    - - 0 1 2 3 4
    - - 0 1 2 3 4
    - - 0 1 2 3 4

…t previous clip crop parameters (for migrating crop options from OpenShot 2.5.1 to OpenShot 2.6). Also refactoring the crop effect, to actually copy the pixels into a new image buffer.
@codecov
Copy link

codecov bot commented Sep 3, 2021

Codecov Report

Merging #724 (5f91ddc) into develop (d58febf) will decrease coverage by 0.07%.
The diff coverage is 0.00%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop     #724      +/-   ##
===========================================
- Coverage    46.24%   46.16%   -0.08%     
===========================================
  Files          182      182              
  Lines        16725    16753      +28     
===========================================
  Hits          7734     7734              
- Misses        8991     9019      +28     
Impacted Files Coverage Δ
src/effects/Crop.cpp 0.92% <0.00%> (-0.33%) ⬇️
src/effects/Crop.h 0.00% <ø> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d58febf...5f91ddc. Read the comment docs.

@jonoomph jonoomph merged commit 5a8ffe3 into develop Sep 4, 2021
@jonoomph jonoomph deleted the improved-crop-effect branch September 4, 2021 02:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant