frame: improve photo recycling
parent
56d2f2f65e
commit
4a36705f42
|
@ -45,6 +45,7 @@
|
||||||
@touchcancel.passive="$emit('touchend', $event)"
|
@touchcancel.passive="$emit('touchend', $event)"
|
||||||
>
|
>
|
||||||
<XImg
|
<XImg
|
||||||
|
v-if="src"
|
||||||
ref="ximg"
|
ref="ximg"
|
||||||
:class="['ximg', 'fill-block', `memories-thumb-${data.key}`]"
|
:class="['ximg', 'fill-block', `memories-thumb-${data.key}`]"
|
||||||
draggable="false"
|
draggable="false"
|
||||||
|
@ -101,8 +102,7 @@ export default defineComponent({
|
||||||
|
|
||||||
data: () => ({
|
data: () => ({
|
||||||
touchTimer: 0,
|
touchTimer: 0,
|
||||||
src: null,
|
faceSrc: null,
|
||||||
hasFaceRect: false,
|
|
||||||
}),
|
}),
|
||||||
|
|
||||||
watch: {
|
watch: {
|
||||||
|
@ -113,16 +113,10 @@ export default defineComponent({
|
||||||
oldData.flag & (this.c.FLAG_SELECTED | this.c.FLAG_LOAD_FAIL);
|
oldData.flag & (this.c.FLAG_SELECTED | this.c.FLAG_LOAD_FAIL);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
"data.etag": function () {
|
|
||||||
this.hasFaceRect = false;
|
|
||||||
this.refresh();
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
|
|
||||||
mounted() {
|
mounted() {
|
||||||
this.hasFaceRect = false;
|
this.faceSrc = null;
|
||||||
this.refresh();
|
|
||||||
|
|
||||||
// Setup video hooks
|
// Setup video hooks
|
||||||
const video = this.$refs.video as HTMLVideoElement;
|
const video = this.$refs.video as HTMLVideoElement;
|
||||||
|
@ -136,8 +130,8 @@ export default defineComponent({
|
||||||
clearTimeout(this.touchTimer);
|
clearTimeout(this.touchTimer);
|
||||||
|
|
||||||
// Clean up blob url if face rect was created
|
// Clean up blob url if face rect was created
|
||||||
if (this.hasFaceRect) {
|
if (this.faceSrc) {
|
||||||
URL.revokeObjectURL(this.src);
|
URL.revokeObjectURL(this.faceSrc);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -154,6 +148,20 @@ export default defineComponent({
|
||||||
return utils.getLivePhotoVideoUrl(this.data, true);
|
return utils.getLivePhotoVideoUrl(this.data, true);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
src(): string | null {
|
||||||
|
this.data.etag; // dependency
|
||||||
|
|
||||||
|
if (this.data.flag & this.c.FLAG_PLACEHOLDER) {
|
||||||
|
return null;
|
||||||
|
} else if (this.data.flag & this.c.FLAG_LOAD_FAIL) {
|
||||||
|
return errorsvg;
|
||||||
|
} else if (this.faceSrc) {
|
||||||
|
return this.faceSrc;
|
||||||
|
} else {
|
||||||
|
return this.url();
|
||||||
|
}
|
||||||
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
|
@ -161,21 +169,6 @@ export default defineComponent({
|
||||||
this.$emit("select", data);
|
this.$emit("select", data);
|
||||||
},
|
},
|
||||||
|
|
||||||
async refresh() {
|
|
||||||
this.src = await this.getSrc();
|
|
||||||
},
|
|
||||||
|
|
||||||
/** Get src for image to show */
|
|
||||||
async getSrc() {
|
|
||||||
if (this.data.flag & this.c.FLAG_PLACEHOLDER) {
|
|
||||||
return null;
|
|
||||||
} else if (this.data.flag & this.c.FLAG_LOAD_FAIL) {
|
|
||||||
return errorsvg;
|
|
||||||
} else {
|
|
||||||
return this.url();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
/** Get url of the photo */
|
/** Get url of the photo */
|
||||||
url() {
|
url() {
|
||||||
let base = 256;
|
let base = 256;
|
||||||
|
@ -205,8 +198,7 @@ export default defineComponent({
|
||||||
|
|
||||||
/** Set src with overlay face rect */
|
/** Set src with overlay face rect */
|
||||||
async addFaceRect() {
|
async addFaceRect() {
|
||||||
if (!this.data.facerect || this.hasFaceRect) return;
|
if (!this.data.facerect || this.faceSrc) return;
|
||||||
this.hasFaceRect = true;
|
|
||||||
|
|
||||||
const canvas = document.createElement("canvas");
|
const canvas = document.createElement("canvas");
|
||||||
const context = canvas.getContext("2d");
|
const context = canvas.getContext("2d");
|
||||||
|
@ -226,7 +218,7 @@ export default defineComponent({
|
||||||
|
|
||||||
canvas.toBlob(
|
canvas.toBlob(
|
||||||
(blob) => {
|
(blob) => {
|
||||||
this.src = URL.createObjectURL(blob);
|
this.faceSrc = URL.createObjectURL(blob);
|
||||||
},
|
},
|
||||||
"image/jpeg",
|
"image/jpeg",
|
||||||
0.95
|
0.95
|
||||||
|
@ -241,7 +233,6 @@ export default defineComponent({
|
||||||
/** Error in loading image */
|
/** Error in loading image */
|
||||||
error(e: any) {
|
error(e: any) {
|
||||||
this.data.flag |= this.c.FLAG_LOAD_FAIL;
|
this.data.flag |= this.c.FLAG_LOAD_FAIL;
|
||||||
this.refresh();
|
|
||||||
},
|
},
|
||||||
|
|
||||||
toggleSelect() {
|
toggleSelect() {
|
||||||
|
|
Loading…
Reference in New Issue