@Test public void testGenerateMissingMipmapFiles() throws Exception { final File parametersFile = new File("src/test/resources/mipmap-test/generator_parameters.json"); final MipmapGeneratorParameters parameters = MipmapGeneratorParameters.parseJson(parametersFile); parameters.initializeDerivedValues(); final List<TileSpec> tileSpecList = parameters.getTileSpecs(); Assert.assertEquals("incorrect number of tile specs parsed", 4, tileSpecList.size()); final MipmapGenerator mipmapGenerator = new MipmapGenerator(baseMipmapDirectory, parameters.getFormat(), parameters.getQuality(), true); ImageAndMask consolidatedLevel1imageAndMask = null; ImageAndMask consolidatedLevel2imageAndMask = null; TileSpec tileSpec; ChannelSpec channelSpec; for (int i = 0; i < tileSpecList.size(); i++) { tileSpec = tileSpecList.get(i); channelSpec = tileSpec.getAllChannels().get(0); Assert.assertTrue("original tile spec is missing level 0 mipmap", channelSpec.hasMipmap(0)); Assert.assertFalse("original tile spec already has level 1 mipmap", channelSpec.hasMipmap(1)); Assert.assertFalse("original tile spec already has level 2 mipmap", channelSpec.hasMipmap(2)); mipmapGenerator.generateMissingMipmapFiles(tileSpec, 2); Assert.assertTrue("updated tile spec lost level 0 mipmap", channelSpec.hasMipmap(0)); Assert.assertTrue("updated tile spec is missing level 1 mipmap", channelSpec.hasMipmap(1)); Assert.assertTrue("updated tile spec is missing level 2 mipmap", channelSpec.hasMipmap(2)); Assert.assertFalse("updated tile spec should not have level 3 mipmap", channelSpec.hasMipmap(3)); if (i == 0) { consolidatedLevel1imageAndMask = channelSpec.getMipmap(1); consolidatedLevel2imageAndMask = channelSpec.getMipmap(2); } else if (i < 3) { validateMask(channelSpec, i, consolidatedLevel1imageAndMask, 1, true); validateMask(channelSpec, i, consolidatedLevel2imageAndMask, 2, true); } else { validateMask(channelSpec, i, consolidatedLevel1imageAndMask, 1, false); validateMask(channelSpec, i, consolidatedLevel2imageAndMask, 2, false); } } }
public void generateMissingMipmapFiles(final TileSpec tileSpec, final int greatestMipmapLevel) throws IllegalArgumentException, IOException { for (final ChannelSpec channelSpec : tileSpec.getAllChannels()) { ImageAndMask imageAndMask = channelSpec.getMipmap(0); if ((imageAndMask == null) || (!imageAndMask.hasImage())) { throw new IllegalArgumentException("level 0 mipmap is missing from " + tileSpec); } final File imageMipmapBaseFile = getMipmapBaseFile(imageAndMask.getImageUrl(), true); File maskMipmapBaseFile = null; final boolean hasMask = imageAndMask.hasMask(); if (hasMask) { maskMipmapBaseFile = getMipmapBaseFile(imageAndMask.getMaskUrl(), true); if (consolidateMasks) { final File sourceMaskFile = getFileForUrlString(imageAndMask.getMaskUrl()); final String sourceDigest = getDigest(sourceMaskFile); if (sourceDigestToMaskMipmapBaseFileMap.containsKey(sourceDigest)) { maskMipmapBaseFile = sourceDigestToMaskMipmapBaseFileMap.get(sourceDigest); } else { sourceDigestToMaskMipmapBaseFileMap.put(sourceDigest, maskMipmapBaseFile); } } } File imageMipmapFile; File maskMipmapFile; for (int mipmapLevel = 1; mipmapLevel <= greatestMipmapLevel; mipmapLevel++) { if (! channelSpec.hasMipmap(mipmapLevel)) { imageMipmapFile = getMipmapFile(imageMipmapBaseFile, mipmapLevel); generateMipmapFile(imageAndMask.getImageUrl(), imageMipmapFile, 1); if (hasMask) { maskMipmapFile = getMipmapFile(maskMipmapBaseFile, mipmapLevel); generateMipmapFile(imageAndMask.getMaskUrl(), maskMipmapFile, 1); } else { maskMipmapFile = null; } imageAndMask = new ImageAndMask(imageMipmapFile, maskMipmapFile); channelSpec.putMipmap(mipmapLevel, imageAndMask); } else { imageAndMask = channelSpec.getMipmap(mipmapLevel); } } } }
MipmapGenerator { public void generateMissingMipmapFiles(final TileSpec tileSpec, final int greatestMipmapLevel) throws IllegalArgumentException, IOException { for (final ChannelSpec channelSpec : tileSpec.getAllChannels()) { ImageAndMask imageAndMask = channelSpec.getMipmap(0); if ((imageAndMask == null) || (!imageAndMask.hasImage())) { throw new IllegalArgumentException("level 0 mipmap is missing from " + tileSpec); } final File imageMipmapBaseFile = getMipmapBaseFile(imageAndMask.getImageUrl(), true); File maskMipmapBaseFile = null; final boolean hasMask = imageAndMask.hasMask(); if (hasMask) { maskMipmapBaseFile = getMipmapBaseFile(imageAndMask.getMaskUrl(), true); if (consolidateMasks) { final File sourceMaskFile = getFileForUrlString(imageAndMask.getMaskUrl()); final String sourceDigest = getDigest(sourceMaskFile); if (sourceDigestToMaskMipmapBaseFileMap.containsKey(sourceDigest)) { maskMipmapBaseFile = sourceDigestToMaskMipmapBaseFileMap.get(sourceDigest); } else { sourceDigestToMaskMipmapBaseFileMap.put(sourceDigest, maskMipmapBaseFile); } } } File imageMipmapFile; File maskMipmapFile; for (int mipmapLevel = 1; mipmapLevel <= greatestMipmapLevel; mipmapLevel++) { if (! channelSpec.hasMipmap(mipmapLevel)) { imageMipmapFile = getMipmapFile(imageMipmapBaseFile, mipmapLevel); generateMipmapFile(imageAndMask.getImageUrl(), imageMipmapFile, 1); if (hasMask) { maskMipmapFile = getMipmapFile(maskMipmapBaseFile, mipmapLevel); generateMipmapFile(imageAndMask.getMaskUrl(), maskMipmapFile, 1); } else { maskMipmapFile = null; } imageAndMask = new ImageAndMask(imageMipmapFile, maskMipmapFile); channelSpec.putMipmap(mipmapLevel, imageAndMask); } else { imageAndMask = channelSpec.getMipmap(mipmapLevel); } } } } }
MipmapGenerator { public void generateMissingMipmapFiles(final TileSpec tileSpec, final int greatestMipmapLevel) throws IllegalArgumentException, IOException { for (final ChannelSpec channelSpec : tileSpec.getAllChannels()) { ImageAndMask imageAndMask = channelSpec.getMipmap(0); if ((imageAndMask == null) || (!imageAndMask.hasImage())) { throw new IllegalArgumentException("level 0 mipmap is missing from " + tileSpec); } final File imageMipmapBaseFile = getMipmapBaseFile(imageAndMask.getImageUrl(), true); File maskMipmapBaseFile = null; final boolean hasMask = imageAndMask.hasMask(); if (hasMask) { maskMipmapBaseFile = getMipmapBaseFile(imageAndMask.getMaskUrl(), true); if (consolidateMasks) { final File sourceMaskFile = getFileForUrlString(imageAndMask.getMaskUrl()); final String sourceDigest = getDigest(sourceMaskFile); if (sourceDigestToMaskMipmapBaseFileMap.containsKey(sourceDigest)) { maskMipmapBaseFile = sourceDigestToMaskMipmapBaseFileMap.get(sourceDigest); } else { sourceDigestToMaskMipmapBaseFileMap.put(sourceDigest, maskMipmapBaseFile); } } } File imageMipmapFile; File maskMipmapFile; for (int mipmapLevel = 1; mipmapLevel <= greatestMipmapLevel; mipmapLevel++) { if (! channelSpec.hasMipmap(mipmapLevel)) { imageMipmapFile = getMipmapFile(imageMipmapBaseFile, mipmapLevel); generateMipmapFile(imageAndMask.getImageUrl(), imageMipmapFile, 1); if (hasMask) { maskMipmapFile = getMipmapFile(maskMipmapBaseFile, mipmapLevel); generateMipmapFile(imageAndMask.getMaskUrl(), maskMipmapFile, 1); } else { maskMipmapFile = null; } imageAndMask = new ImageAndMask(imageMipmapFile, maskMipmapFile); channelSpec.putMipmap(mipmapLevel, imageAndMask); } else { imageAndMask = channelSpec.getMipmap(mipmapLevel); } } } } MipmapGenerator(final File rootDirectory,
                           final String format,
                           final float jpegQuality,
                           final boolean consolidateMasks); }
MipmapGenerator { public void generateMissingMipmapFiles(final TileSpec tileSpec, final int greatestMipmapLevel) throws IllegalArgumentException, IOException { for (final ChannelSpec channelSpec : tileSpec.getAllChannels()) { ImageAndMask imageAndMask = channelSpec.getMipmap(0); if ((imageAndMask == null) || (!imageAndMask.hasImage())) { throw new IllegalArgumentException("level 0 mipmap is missing from " + tileSpec); } final File imageMipmapBaseFile = getMipmapBaseFile(imageAndMask.getImageUrl(), true); File maskMipmapBaseFile = null; final boolean hasMask = imageAndMask.hasMask(); if (hasMask) { maskMipmapBaseFile = getMipmapBaseFile(imageAndMask.getMaskUrl(), true); if (consolidateMasks) { final File sourceMaskFile = getFileForUrlString(imageAndMask.getMaskUrl()); final String sourceDigest = getDigest(sourceMaskFile); if (sourceDigestToMaskMipmapBaseFileMap.containsKey(sourceDigest)) { maskMipmapBaseFile = sourceDigestToMaskMipmapBaseFileMap.get(sourceDigest); } else { sourceDigestToMaskMipmapBaseFileMap.put(sourceDigest, maskMipmapBaseFile); } } } File imageMipmapFile; File maskMipmapFile; for (int mipmapLevel = 1; mipmapLevel <= greatestMipmapLevel; mipmapLevel++) { if (! channelSpec.hasMipmap(mipmapLevel)) { imageMipmapFile = getMipmapFile(imageMipmapBaseFile, mipmapLevel); generateMipmapFile(imageAndMask.getImageUrl(), imageMipmapFile, 1); if (hasMask) { maskMipmapFile = getMipmapFile(maskMipmapBaseFile, mipmapLevel); generateMipmapFile(imageAndMask.getMaskUrl(), maskMipmapFile, 1); } else { maskMipmapFile = null; } imageAndMask = new ImageAndMask(imageMipmapFile, maskMipmapFile); channelSpec.putMipmap(mipmapLevel, imageAndMask); } else { imageAndMask = channelSpec.getMipmap(mipmapLevel); } } } } MipmapGenerator(final File rootDirectory,
                           final String format,
                           final float jpegQuality,
                           final boolean consolidateMasks); static void main(final String[] args); void generateMissingMipmapFiles(final TileSpec tileSpec,
                                           final int greatestMipmapLevel); static void generateMipmap(final String sourceUrl,
                                      final int mipmapLevelDelta,
                                      final String format,
                                      final Float jpegQuality,
                                      final OutputStream outputStream); }
MipmapGenerator { public void generateMissingMipmapFiles(final TileSpec tileSpec, final int greatestMipmapLevel) throws IllegalArgumentException, IOException { for (final ChannelSpec channelSpec : tileSpec.getAllChannels()) { ImageAndMask imageAndMask = channelSpec.getMipmap(0); if ((imageAndMask == null) || (!imageAndMask.hasImage())) { throw new IllegalArgumentException("level 0 mipmap is missing from " + tileSpec); } final File imageMipmapBaseFile = getMipmapBaseFile(imageAndMask.getImageUrl(), true); File maskMipmapBaseFile = null; final boolean hasMask = imageAndMask.hasMask(); if (hasMask) { maskMipmapBaseFile = getMipmapBaseFile(imageAndMask.getMaskUrl(), true); if (consolidateMasks) { final File sourceMaskFile = getFileForUrlString(imageAndMask.getMaskUrl()); final String sourceDigest = getDigest(sourceMaskFile); if (sourceDigestToMaskMipmapBaseFileMap.containsKey(sourceDigest)) { maskMipmapBaseFile = sourceDigestToMaskMipmapBaseFileMap.get(sourceDigest); } else { sourceDigestToMaskMipmapBaseFileMap.put(sourceDigest, maskMipmapBaseFile); } } } File imageMipmapFile; File maskMipmapFile; for (int mipmapLevel = 1; mipmapLevel <= greatestMipmapLevel; mipmapLevel++) { if (! channelSpec.hasMipmap(mipmapLevel)) { imageMipmapFile = getMipmapFile(imageMipmapBaseFile, mipmapLevel); generateMipmapFile(imageAndMask.getImageUrl(), imageMipmapFile, 1); if (hasMask) { maskMipmapFile = getMipmapFile(maskMipmapBaseFile, mipmapLevel); generateMipmapFile(imageAndMask.getMaskUrl(), maskMipmapFile, 1); } else { maskMipmapFile = null; } imageAndMask = new ImageAndMask(imageMipmapFile, maskMipmapFile); channelSpec.putMipmap(mipmapLevel, imageAndMask); } else { imageAndMask = channelSpec.getMipmap(mipmapLevel); } } } } MipmapGenerator(final File rootDirectory,
                           final String format,
                           final float jpegQuality,
                           final boolean consolidateMasks); static void main(final String[] args); void generateMissingMipmapFiles(final TileSpec tileSpec,
                                           final int greatestMipmapLevel); static void generateMipmap(final String sourceUrl,
                                      final int mipmapLevelDelta,
                                      final String format,
                                      final Float jpegQuality,
                                      final OutputStream outputStream);  }