add option for discarding partial frames

This commit is contained in:
Tomáš Mládek 2019-11-01 11:00:42 +01:00
parent 7ef1778cad
commit 1707379e78

View file

@ -32,6 +32,10 @@
</label> </label>
<input type="checkbox" v-model="sortDirection" id="sortDirection"> <input type="checkbox" v-model="sortDirection" id="sortDirection">
</div> </div>
<div>
<label for="discard">Discard partial frames</label>
<input type="checkbox" v-model="discardPartial" id="discard">
</div>
</div> </div>
</div> </div>
</template> </template>
@ -55,6 +59,7 @@ export default {
fullscreen: false, fullscreen: false,
sortBySize: false, sortBySize: false,
sortDirection: false, sortDirection: false,
discardPartial: false,
position: 0, position: 0,
tmp_ctx: null, tmp_ctx: null,
animation_id: null, animation_id: null,
@ -68,7 +73,8 @@ export default {
computed: { computed: {
frames: function () { frames: function () {
if (this.image === null) return 0; if (this.image === null) return 0;
return Math.ceil((this.image.width - this.offset[0]) / this.width) * Math.ceil((this.image.height - this.offset[1]) / this.height); const roundFn = this.discardPartial ? Math.floor : Math.ceil;
return roundFn((this.image.width - this.offset[0]) / this.width) * roundFn((this.image.height - this.offset[1]) / this.height);
}, },
canvas_height: function () { canvas_height: function () {
return this.height * this.zoom; return this.height * this.zoom;
@ -81,7 +87,7 @@ export default {
let sequence = []; let sequence = [];
for (let pos = 0; pos < this.frames; pos++) { for (let pos = 0; pos < this.frames; pos++) {
let wb = Math.ceil((this.image.width - this.offset[0]) / this.width); // width_blocks let wb = (this.discardPartial ? Math.floor : Math.ceil)((this.image.width - this.offset[0]) / this.width); // width_blocks
let x = this.offset[0] + (pos % wb) * this.width; // x offset let x = this.offset[0] + (pos % wb) * this.width; // x offset
let w = x + this.width < this.image.width ? this.width : this.image.width - x; // frame width let w = x + this.width < this.image.width ? this.width : this.image.width - x; // frame width
let y = this.offset[1] + Math.floor(pos / wb) * this.height; // y offset let y = this.offset[1] + Math.floor(pos / wb) * this.height; // y offset