Exemple #1
0
def CreateAtlas(oPicPath,oAtlasFile,uDebugMsg):
    ''' creates an atlas file from all picture files in a folder '''

    if oORCA.bIgnoreAtlas:
        return

    #can\'t get JPEG lib included in package, so just ignore atlas
    #if oORCA.uPlatform=='macosx'  or oORCA.uPlatform=="ios" or oORCA.uPlatform=="win":
    if oORCA.uPlatform=='macosx'  or oORCA.uPlatform=="ios":
        return

    try:
        if not FileExists(oAtlasFile):
            Logger.debug(uDebugMsg)
            #aExtensions=[u'.png',u'.jpg',u'.bmp',u'.gif']
            # we exclude gifs as they might be animated
            aExtensions=[u'.png',u'.jpg',u'.bmp']
            aPicFiles=[]

            oDirList=GetFileList(oPicPath, bSubDirs=True,bFullPath=True)
            for uFileName in oDirList:
                uExtension = os.path.splitext(uFileName)[1].lower()
                if uExtension in aExtensions:
                    if uFileName.find( AdjustPathToOs(oORCA.uSkinPath+u'/atlas/'))==-1:
                        aPicFiles.append(uFileName)
            try:
                Atlas.create(oAtlasFile[:-6],aPicFiles,1024)
            except Exception:
                pass
    except Exception as e:
        LogError(u'Error creating Atlas File:',e)
Exemple #2
0
def create(folder):
    cwd = getcwd()
    images = []
    for root, dirname, filenames in walk(folder):
        for filename in filenames:
            image = join(root, filename)[len(folder) + 1:]
            print image
            images.append(image)

    chdir(folder)
    outfn = None
    size = DEFAULT_SIZE
    while not outfn:
        try:
            fname = join('..', basename(folder))
            outfn=Atlas.create(fname, images, size, use_path=True)
        except:
            pass
        if not outfn or ((size<1024) and (len(outfn)>1 and len(outfn[1])>2)):
                numfiles = len(outfn[1]) if outfn else 0
                for i in range (0, numfiles):
                    outf = '%s-%d.png' % (fname, i)
                    try:
                        remove(outf)
                    except:
                        pass
                outfn = None
        size *= 2
    chdir(cwd)
Exemple #3
0
def CreateAtlas(oPicPath, oAtlasFile, uDebugMsg):
    """
    creates an atlas file from all picture files in a folder

    :param cPath oPicPath: The Path to a Picture Folder
    :param cFileName oAtlasFile: The Atlas Files to Create
    :param string uDebugMsg: A Debug Message for the function
    :return:
    """
    if Globals.bIgnoreAtlas:
        return

    #can\'t get JPEG lib included in package, so just ignore atlas
    if Globals.uPlatform == 'macosx' or Globals.uPlatform == "ios":
        return

    try:
        if not oAtlasFile.Exists():
            Logger.debug(uDebugMsg)
            #aExtensions=[u'.png',u'.jpg',u'.bmp',u'.gif']
            # we exclude gifs as they might be animated
            aExtensions = [u'.png', u'.jpg', u'.bmp']
            aPicFiles = []

            aFileList = oPicPath.GetFileList(bSubDirs=False, bFullPath=True)
            for uFileName in aFileList:
                uExtension = os.path.splitext(uFileName)[1].lower()
                if uExtension in aExtensions:
                    if uFileName.find(Globals.oPathSkin.string +
                                      u'/atlas/') == -1:
                        aPicFiles.append(uFileName)
            try:
                Atlas.create(oAtlasFile[:-6], aPicFiles, 1024)
            except Exception:
                pass
    except Exception as e:
        LogError(u'Error creating Atlas File:', e)
Exemple #4
0
def build_atlas(image_paths, src_x, src_y, atlas_name, padding=2, **limit_kwarg):
    """Build a Kivy  Kivy :py:class:`~kivy.atlas.Atlas`

    Args:
        image_paths (list): Paths to images and/or image directories
        src_x: Max width of source images
        src_y: Max height of source images
        atlas_name: Name of atlas file to create
        \\*\\*limit_kwarg: At most one limit to provide to :py:func:`.get_atlas_dimensions`
    """
    from kivy.atlas import Atlas

    # Allow smallest dimension to be as low as half the max. This this works because each thumbnail
    # size category is over twice the size of the next smallest one
    min_x = ceil(src_x / 2)
    min_y = ceil(src_y / 2)
    logger.info(f'Atlas: Searching for images of dimensions ({min_x}-{src_x}) x ({min_y}-{src_y})...')
    image_paths = list(filter_images_by_size(image_paths, src_x, src_y, min_x, min_y))
    logger.info(f'Atlas: {len(image_paths)} images found')

    atlas_size = get_atlas_dimensions(len(image_paths), src_x, src_y, padding=padding, **limit_kwarg)
    logger.info(f'Atlas: Calculated atlas size: {atlas_size}')
    if atlas_size != (0, 0):
        Atlas.create(atlas_name, image_paths, atlas_size, padding=padding)
Exemple #5
0
def make_atlas():
    """method basically copied/adapted from kivy.atlas __main__"""

    sources = [
        'src/data/*.png',
    ]
    filenames = [fname for fnames in sources for fname in glob(fnames)]

    options = {'use_path': False}
    if not isdir('data'):
        mkdir('data')

    outname = 'data/theme'
    size = 4096

    ret = Atlas.create(outname, filenames, size, **options)
    if not ret:
        log.error('Error while creating atlas!')
        exit(1)

    fn, meta = ret
    log.info('Atlas created at', fn)
    log.info('%d image%s been created' %
             (len(meta), 's have' if len(meta) > 1 else ' has'))
Exemple #6
0
from kivy.atlas import Atlas
import os

path = 'assets/images/test/'

os.chdir(path)

Atlas.create('test', os.listdir('.'), 1024)
Exemple #7
0
        #print join(i, "include")
        print "  [ ] Copying included images...",
        if exists(join(i, "include")):
            for img in (join(i, "include", f) for f in os.listdir(join(i, "include"))):
                #print img
                shutil.copy(img, tmp)

        print "\r  [x] Images copied.            "

        # All done, pack everything into an atlas
        print "  [ ] Generating the atlas...",
        fnames = []
        tot_size = 0
        for i in (join(tmp, f) for f in os.listdir(tmp)):
            if i.lower().endswith(".png"):
                fnames.append(i)
                tot_size += os.stat(i).st_size
        data = Atlas.create(atlasname, fnames, get_atlas_best_size(fnames))
        if not data:
            print "\r  [!] Atlas not generated."
            continue
        else:
            fn, meta = data
            atl_size = 0
            for i in meta.keys():
                atl_size += os.stat(i).st_size
            print "\r  [x] Atlas \"{0}\" generated ({1} image{2}, {3} saved).".format(fn, len(meta), 's' if len(meta) > 1 else '', hr_size(tot_size - atl_size))

        shutil.rmtree(tmp)

    print "All done."
Exemple #8
0
def make_atlas(folder):
    fold = Path(folder)
    subdirs = fold.dirs()
    for dirc in subdirs:
        Atlas.create("images/{}".format(dirc.basename()), dirc.files("*.png"), [160,256])