Esempio n. 1
0
void
UnitSymbol::Load(ResourceId id)
{
#ifdef USE_MEMORY_CANVAS
  assert(IsScreenInitialized());
  assert(buffer.data == nullptr);

  ResourceLoader::Data data = ResourceLoader::Load(id);
  assert(!data.IsNull());

  const UncompressedImage uncompressed = LoadPNG(data.data, data.size);
  assert(uncompressed.GetFormat() == UncompressedImage::Format::GRAY);

  const size_t size = uncompressed.GetPitch() * uncompressed.GetHeight();
  buffer.data = new Luminosity8[size];
  memcpy(buffer.data, uncompressed.GetData(), size);

  buffer.pitch = uncompressed.GetPitch();
  buffer.width = uncompressed.GetWidth();
  buffer.height = uncompressed.GetHeight();
#else
  bitmap.Load(id, Bitmap::Type::MONO);
  size = bitmap.GetSize();
#endif
}
Esempio n. 2
0
bool
Bitmap::Load(const UncompressedImage &uncompressed, gcc_unused Type type)
{
  delete texture;
  texture = type == Type::MONO
    ? ImportAlphaTexture(uncompressed)
    : ImportTexture(uncompressed);
  if (texture == nullptr)
    return false;

  if (interpolation)
    texture->EnableInterpolation();

  size = { uncompressed.GetWidth(), uncompressed.GetHeight() };
  return true;
}
Esempio n. 3
0
static inline void
ImportSurface(WritableImageBuffer<PixelTraits> &buffer,
              const UncompressedImage &uncompressed)
{
  buffer.Allocate(uncompressed.GetWidth(), uncompressed.GetHeight());

  switch (uncompressed.GetFormat()) {
  case UncompressedImage::Format::INVALID:
    assert(false);
    gcc_unreachable();

  case UncompressedImage::Format::RGB:
  case UncompressedImage::Format::RGBA:
    ConvertFromRGB<PixelTraits>(buffer,
                                (const uint8_t *)uncompressed.GetData(),
                                uncompressed.GetPitch());
    break;

  case UncompressedImage::Format::GRAY:
    ConvertFromGray<PixelTraits>(buffer,
                                 (const uint8_t *)uncompressed.GetData(),
                                 uncompressed.GetPitch());
    break;
  }
}
Esempio n. 4
0
  bool IsDefined() const {
#ifdef ANDROID
    return bmp != nullptr || uncompressed.IsDefined();
#elif defined(ENABLE_OPENGL)
    return texture != nullptr;
#elif defined(USE_MEMORY_CANVAS)
    return buffer.data != nullptr;
#else
    return bitmap != nullptr;
#endif
  }
Esempio n. 5
0
bool
Bitmap::Load(const UncompressedImage &uncompressed, Type type)
{
  assert(IsScreenInitialized());
  assert(uncompressed.IsVisible());

  Reset();

  ImportSurface(buffer, uncompressed);
  return true;
}
Esempio n. 6
0
Bitmap::Bitmap(ConstBuffer<void> _buffer)
  :
#ifdef ENABLE_OPENGL
#ifdef ANDROID
  id(0),
#endif
  texture(nullptr), interpolation(false)
#else
  buffer(WritableImageBuffer<BitmapPixelTraits>::Empty())
#endif
{
  Load(_buffer);
}

bool
Bitmap::Load(ConstBuffer<void> buffer, Type type)
{
  const UncompressedImage uncompressed = LoadPNG(buffer.data, buffer.size);
  return Load(uncompressed, type);
}

static UncompressedImage
DecompressImageFile(Path path)
{
#ifdef USE_LIBTIFF
  if (path.MatchesExtension(_T(".tif")) || path.MatchesExtension(_T(".tiff")))
    return LoadTiff(path);
#endif

  if (path.MatchesExtension(_T(".png")))
    return LoadPNG(path);

  return LoadJPEGFile(path);
}

bool
Bitmap::LoadFile(Path path)
{
  const UncompressedImage uncompressed = DecompressImageFile(path);
  return uncompressed.IsVisible() && Load(uncompressed);
}
Esempio n. 7
0
void
UnitSymbol::Load(unsigned id)
{
  assert(IsScreenInitialized());
  assert(buffer.data == nullptr);

  ResourceLoader::Data data = ResourceLoader::Load(id);
  assert(data.first != nullptr);

  const UncompressedImage uncompressed = LoadPNG(data.first, data.second);
  assert(uncompressed.GetFormat() == UncompressedImage::Format::GRAY);

  const size_t size = uncompressed.GetPitch() * uncompressed.GetHeight();
  buffer.data = new Luminosity8[size];
  memcpy(buffer.data, uncompressed.GetData(), size);

  buffer.pitch = uncompressed.GetPitch();
  buffer.width = uncompressed.GetWidth();
  buffer.height = uncompressed.GetHeight();
}
Esempio n. 8
0
Bitmap::Bitmap(ConstBuffer<void> _buffer)
  :
#ifdef ENABLE_OPENGL
#ifdef ANDROID
  id(0),
#endif
  texture(nullptr), interpolation(false)
#else
  buffer(WritableImageBuffer<BitmapPixelTraits>::Empty())
#endif
{
  Load(_buffer);
}

bool
Bitmap::Load(ConstBuffer<void> buffer, Type type)
{
  const UncompressedImage uncompressed = LoadPNG(buffer.data, buffer.size);
  return (uncompressed.IsVisible() && Load(uncompressed, type));
}

#ifdef USE_LIBJPEG
bool
Bitmap::LoadFile(const TCHAR *path)
{
  const UncompressedImage uncompressed = LoadJPEGFile(path);
  return (uncompressed.IsVisible() && Load(uncompressed));
}
#endif

bool
Bitmap::LoadPNGFile(const TCHAR *path)
{
  const UncompressedImage uncompressed = ::LoadPNGFile(path);
  return (uncompressed.IsVisible() && Load(uncompressed));
}