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

fix: apply mipmap fixed resolution accordingly to fixed and largest resolutions #96

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions packages/assetpack/src/image/mipmap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,30 +51,34 @@ export function mipmap(_options: MipmapOptions = {}): AssetPipe<MipmapOptions, '
sharpImage: sharp(asset.buffer),
};

const { resolutions, fixedResolution } = options as Required<MipmapOptions>
|| this.defaultOptions;

const fixedResolutions = {
[fixedResolution]: resolutions[fixedResolution]
};

const largestResolution = Math.max(...Object.values(resolutions));

try
{
if (shouldMipmap)
{
const { resolutions, fixedResolution } = options as Required<MipmapOptions>
|| this.defaultOptions;

const fixedResolutions: {[x: string]: number} = {};

fixedResolutions[fixedResolution] = resolutions[fixedResolution];

const resolutionHash = asset.allMetaData[this.tags!.fix]
? fixedResolutions
: resolutions;

const largestResolution = Math.max(...Object.values(resolutionHash));

image.resolution = largestResolution;

processedImages = shouldMipmap ? await mipmapSharp(image, resolutionHash, largestResolution) : [image];
processedImages = await mipmapSharp(image, resolutionHash, largestResolution);
}
else
{
processedImages = [image];
image.resolution = fixedResolutions[fixedResolution];

processedImages = image.resolution === 1
? [image]
: processedImages = await mipmapSharp(image, fixedResolutions, largestResolution);
}
}
catch (error)
Expand Down
6 changes: 3 additions & 3 deletions packages/assetpack/test/image/Mipmap.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,15 @@ describe('Mipmap', () =>
name: testName,
files: [
{
name: 'testPng.png',
name: 'testPng{fix}.png',
content: assetPath('image/png-1.png'),
},
],
folders: [],
});

const mipmapOpts = {
resolutions: { low: 0.5 },
resolutions: { low: 0.5, default: 1 },
fixedResolution: 'low'
};

Expand Down Expand Up @@ -147,7 +147,7 @@ describe('Mipmap', () =>

it('should prevent mipmaps on file when tagged with fix', async () =>
{
const testName = 'mip-fixed';
const testName = 'mip-fixed-prevent';
const inputDir = getInputDir(pkg, testName);
const outputDir = getOutputDir(pkg, testName);

Expand Down