update library/src/main/ets/downsampling/DownsampleUtils.ets.
Signed-off-by: 田双明 <tianshuangming@h-partners.com>
This commit is contained in:
parent
1b812f8431
commit
d2cead637b
|
@ -12,6 +12,8 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
import { DownsampleStrategy } from './DownsampleStartegy';
|
||||||
|
|
||||||
export enum SampleSizeRounding {
|
export enum SampleSizeRounding {
|
||||||
/**
|
/**
|
||||||
* Prefer to round the sample size up so that the image is downsampled to smaller than the
|
* Prefer to round the sample size up so that the image is downsampled to smaller than the
|
||||||
|
@ -26,6 +28,7 @@ export enum SampleSizeRounding {
|
||||||
//(质量优先)
|
//(质量优先)
|
||||||
QUALITY
|
QUALITY
|
||||||
}
|
}
|
||||||
|
|
||||||
export function highestOneBit(i: number): number {
|
export function highestOneBit(i: number): number {
|
||||||
i |= (i >> 1);
|
i |= (i >> 1);
|
||||||
i |= (i >> 2);
|
i |= (i >> 2);
|
||||||
|
@ -33,4 +36,22 @@ export function highestOneBit(i: number): number {
|
||||||
i |= (i >> 8);
|
i |= (i >> 8);
|
||||||
i |= (i >> 16);
|
i |= (i >> 16);
|
||||||
return i - (i >>> 1);
|
return i - (i >>> 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export function getScale(sourceWidth: number, sourceHeight: number, requestedWidth: number, requestedHeight: number,
|
||||||
|
downsampType: DownsampleStrategy
|
||||||
|
): number {
|
||||||
|
if (downsampType === DownsampleStrategy.FIT_CENTER_MEMORY) {
|
||||||
|
const widthPercentage = requestedWidth / sourceWidth
|
||||||
|
const heightPercentage = requestedHeight / sourceHeight
|
||||||
|
return Math.min(widthPercentage, heightPercentage)
|
||||||
|
} else {
|
||||||
|
const maxIntegerFactor = Math.max(sourceHeight / requestedHeight, sourceWidth / requestedWidth);
|
||||||
|
return maxIntegerFactor === 0 ? 1 : 1 / highestOneBit(maxIntegerFactor);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
export function round(value: number): number {
|
||||||
|
return Math.floor(value + 0.5);
|
||||||
}
|
}
|
Loading…
Reference in New Issue