1
0
mirror of https://github.com/aseprite/aseprite.git synced 2025-04-02 13:20:12 +00:00
David Capello 3ebb708000 Add CelData to share image/position/opacity between linked cels
Changes:
- Merged app::cmd::ObjectIO into doc::SubObjectsIO
- Changed app::cmd::SetCelImage with app::cmd::SetCelData
- Added Cel::createCopy/Link() to avoid confunsion with Cel copy ctor
- Renamed Sprite::getImage() -> getImageRef()
- Added Sprite::getDataCelRef()
- Added doc::CelsRange helper to iterate cels
- Added Sprite::cels()/uniqueCels() member functions (removed
  Sprite::getCels())
- Added DocumentRange::convertToCels()
2015-02-09 11:40:43 -03:00

69 lines
1.8 KiB
C++

// Aseprite Document Library
// Copyright (c) 2001-2014 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "doc/image_io.h"
#include "base/serialization.h"
#include "base/unique_ptr.h"
#include "doc/image.h"
#include <iostream>
namespace doc {
using namespace base::serialization;
using namespace base::serialization::little_endian;
// Serialized Image data:
//
// DWORD image ID
// BYTE image type
// WORD[2] w, h
// DWORD mask color
// for each line ("h" times)
// for each pixel ("w" times)
// BYTE[4] for RGB images, or
// BYTE[2] for Grayscale images, or
// BYTE for Indexed images
void write_image(std::ostream& os, Image* image)
{
write32(os, image->id());
write8(os, image->pixelFormat()); // Pixel format
write16(os, image->width()); // Width
write16(os, image->height()); // Height
write32(os, image->maskColor()); // Mask color
int size = image->getRowStrideSize();
for (int c=0; c<image->height(); c++)
os.write((char*)image->getPixelAddress(0, c), size);
}
Image* read_image(std::istream& is)
{
ObjectId id = read32(is);
int pixelFormat = read8(is); // Pixel format
int width = read16(is); // Width
int height = read16(is); // Height
uint32_t maskColor = read32(is); // Mask color
base::UniquePtr<Image> image(Image::create(static_cast<PixelFormat>(pixelFormat), width, height));
int size = image->getRowStrideSize();
for (int c=0; c<image->height(); c++)
is.read((char*)image->getPixelAddress(0, c), size);
image->setMaskColor(maskColor);
image->setId(id);
return image.release();
}
}