/* Copyright (c) 2023 Alex Diener This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. Alex Diener alex@ludobloom.com */ #ifndef __ImageCollection_H__ #define __ImageCollection_H__ #include "bitmapimage/BitmapImage.h" #include "gamemath/TextureAtlas.h" #include "gamemath/Vector2u.h" #include "serialization/DeserializationContext.h" #include "serialization/SerializationContext.h" #define IMAGE_COLLECTION_FORMAT_TYPE "image_collection" #define IMAGE_COLLECTION_FORMAT_VERSION 0 #define IMAGE_COLLECTION_ENTRY_COUNT_MAX 16384 #define IMAGE_COLLECTION_SECTION_COUNT_MAX 2 typedef uint32_t ImageCollectionID; typedef uint32_t ImageID; #define IMAGE_ID_NONE ((ImageID) -1) typedef struct ImageCollectionEntry { ImageID identifier; char * name; BitmapImage * image[IMAGE_COLLECTION_SECTION_COUNT_MAX]; // Set by unpackImageEntries unsigned int imageDirtyValue[IMAGE_COLLECTION_SECTION_COUNT_MAX]; Vector2u size; // Set by resolveAtlasEntries; can be used to reference bitmap dimensions if images aren't unpacked Rect4f atlasEntry; // Set by resolveAtlasEntries } ImageCollectionEntry; typedef struct ImageCollection { ImageCollectionID identifier; char * name; unsigned int imageCount; ImageCollectionEntry * images; } ImageCollection; // Does not take ownership of images or any of its contents ImageCollection * ImageCollection_create(ImageCollectionID identifier, const char * name, unsigned int imageCount, ImageCollectionEntry * images); ImageCollection * ImageCollection_copy(ImageCollection * imageCollection); void ImageCollection_dispose(ImageCollection * imageCollection); ImageCollection * ImageCollection_deserializeMinimal(compat_type(DeserializationContext *) deserializationContext, uint16_t formatVersion); ImageCollection * ImageCollection_deserialize(compat_type(DeserializationContext *) deserializationContext); void ImageCollection_serializeMinimal(ImageCollection * imageCollection, compat_type(SerializationContext *) serializationContext); void ImageCollection_serialize(ImageCollection * imageCollection, compat_type(SerializationContext *) serializationContext); void ImageCollection_resolveAtlasEntries(ImageCollection * imageCollection, TextureAtlas * textureAtlas); // Call resolveAtlasEntries before unpackImageEntries void ImageCollection_unpackImageEntries(ImageCollection * imageCollection, BitmapImage * atlasImage, unsigned int sectionIndex); ImageID ImageCollection_getUnusedImageID(ImageCollection * imageCollection, ImageID afterImageID); ImageCollectionEntry * ImageCollection_getImage(ImageCollection * imageCollection, ImageID imageID); unsigned int ImageCollection_getImageIndex(ImageCollection * imageCollection, ImageID imageID); // Takes ownership of name and image, if specified void ImageCollection_addImage(ImageCollection * imageCollection, ImageCollectionEntry imageEntry); void ImageCollection_insertImage(ImageCollection * imageCollection, unsigned int imageIndex, ImageCollectionEntry imageEntry); void ImageCollection_removeImageAtIndex(ImageCollection * imageCollection, unsigned int imageIndex); void ImageCollection_reorderImage(ImageCollection * imageCollection, unsigned int fromIndex, unsigned int toIndex); #endif