Giter Club home page Giter Club logo

tga's Introduction

Aseprite TGA Library

build MIT Licensed

Library to read/write Truevision TGA/TARGA files. Tested with libfuzzer.

Example:

#include "tga/tga.h"

#include <cstdio>
#include <vector>

int main(int argc, char* argv[])
{
  if (argc < 2)
    return 1;

  FILE* f = std::fopen(argv[1], "rb");
  tga::StdioFileInterface file(f);
  tga::Decoder decoder(&file);
  tga::Header header;
  if (!decoder.readHeader(header))
    return 2;

  tga::Image image;
  image.bytesPerPixel = header.bytesPerPixel();
  image.rowstride = header.width * header.bytesPerPixel();

  std::vector<uint8_t> buffer(image.rowstride * header.height);
  image.pixels = &buffer[0];

  if (!decoder.readImage(header, image, nullptr))
    return 3;

  // Optional post-process to fix the alpha channel in
  // some TGA files where alpha=0 for all pixels when
  // it shouldn't.
  decoder.postProcessImage(header, image);

  return 0;
}

tga's People

Contributors

dacap avatar kevinw1998 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

tga's Issues

Some minor casting warnings

Thanks for the nice little library - works great so far. I'm going to use it in Mineways.

I use Visual Studio 2019 and tend to put warnings at 4, "show me everything." For stdio.cpp there are two warning, casting mismatches, which I fix as follows:

void StdioFileInterface::seek(size_t absPos)
{
  fseek(m_file, (long)absPos, SEEK_SET);  // <-- cast added
}

uint8_t StdioFileInterface::read8()
{
  int value = fgetc(m_file);
  if (value != EOF)
    return (uint8_t)value;  // <-- cast added

  m_ok = false;
  return 0;
}

For decoder.cpp there were enough that I didn't bother. Here's the list, if you want to fix these yourself:

1>decoder.cpp(25,26): warning C4244: '=': conversion from 'uint32_t' to 'uint8_t', possible loss of data 1>decoder.cpp(26,30): warning C4244: '=': conversion from 'uint32_t' to 'uint8_t', possible loss of data 1>decoder.cpp(27,27): warning C4244: '=': conversion from 'uint32_t' to 'uint8_t', possible loss of data 1>decoder.cpp(28,33): warning C4244: '=': conversion from 'uint32_t' to 'uint16_t', possible loss of data 1>decoder.cpp(29,34): warning C4244: '=': conversion from 'uint32_t' to 'uint16_t', possible loss of data 1>decoder.cpp(30,31): warning C4244: '=': conversion from 'uint32_t' to 'uint8_t', possible loss of data 1>decoder.cpp(31,26): warning C4244: '=': conversion from 'uint32_t' to 'uint16_t', possible loss of data 1>decoder.cpp(32,26): warning C4244: '=': conversion from 'uint32_t' to 'uint16_t', possible loss of data 1>decoder.cpp(33,24): warning C4244: '=': conversion from 'uint32_t' to 'uint16_t', possible loss of data 1>decoder.cpp(34,25): warning C4244: '=': conversion from 'uint32_t' to 'uint16_t', possible loss of data 1>decoder.cpp(35,30): warning C4244: '=': conversion from 'uint32_t' to 'uint8_t', possible loss of data 1>decoder.cpp(36,33): warning C4244: '=': conversion from 'uint32_t' to 'uint8_t', possible loss of data 1>decoder.cpp(98,36): warning C4244: 'argument': conversion from 'int' to 'uint8_t', possible loss of data 1>decoder.cpp(97,36): warning C4244: 'argument': conversion from 'int' to 'uint8_t', possible loss of data 1>decoder.cpp(96,36): warning C4244: 'argument': conversion from 'int' to 'uint8_t', possible loss of data 1>decoder.cpp(112,44): warning C4244: 'argument': conversion from 'int' to 'uint8_t', possible loss of data 1>decoder.cpp(112,41): warning C4244: 'argument': conversion from 'const int' to 'uint8_t', possible loss of data 1>decoder.cpp(112,38): warning C4244: 'argument': conversion from 'const int' to 'uint8_t', possible loss of data 1>decoder.cpp(112,35): warning C4244: 'argument': conversion from 'const int' to 'uint8_t', possible loss of data 1>decoder.cpp(326,26): warning C4244: 'initializing': conversion from 'uint32_t' to 'uint8_t', possible loss of data 1>decoder.cpp(326,19): warning C4244: 'initializing': conversion from 'uint32_t' to 'const uint8_t', possible loss of data 1>decoder.cpp(327,26): warning C4244: 'initializing': conversion from 'uint32_t' to 'uint8_t', possible loss of data 1>decoder.cpp(327,19): warning C4244: 'initializing': conversion from 'uint32_t' to 'const uint8_t', possible loss of data 1>decoder.cpp(328,26): warning C4244: 'initializing': conversion from 'uint32_t' to 'uint8_t', possible loss of data 1>decoder.cpp(328,19): warning C4244: 'initializing': conversion from 'uint32_t' to 'const uint8_t', possible loss of data 1>decoder.cpp(329,13): warning C4244: 'initializing': conversion from 'uint32_t' to 'uint8_t', possible loss of data 1>decoder.cpp(337,26): warning C4244: 'initializing': conversion from 'uint32_t' to 'uint8_t', possible loss of data 1>decoder.cpp(337,19): warning C4244: 'initializing': conversion from 'uint32_t' to 'const uint8_t', possible loss of data 1>decoder.cpp(338,26): warning C4244: 'initializing': conversion from 'uint32_t' to 'uint8_t', possible loss of data 1>decoder.cpp(338,19): warning C4244: 'initializing': conversion from 'uint32_t' to 'const uint8_t', possible loss of data 1>decoder.cpp(339,26): warning C4244: 'initializing': conversion from 'uint32_t' to 'uint8_t', possible loss of data 1>decoder.cpp(339,19): warning C4244: 'initializing': conversion from 'uint32_t' to 'const uint8_t', possible loss of data 1>decoder.cpp(345,28): warning C4244: 'initializing': conversion from 'uint32_t' to 'uint16_t', possible loss of data 1>decoder.cpp(345,20): warning C4244: 'initializing': conversion from 'uint32_t' to 'const uint16_t', possible loss of data 1>decoder.cpp(353,35): warning C4244: 'argument': conversion from 'int' to 'uint8_t', possible loss of data 1>decoder.cpp(352,35): warning C4244: 'argument': conversion from 'int' to 'uint8_t', possible loss of data 1>decoder.cpp(351,35): warning C4244: 'argument': conversion from 'int' to 'uint8_t', possible loss of data 1>decoder.cpp(254,50): warning C4244: 'argument': conversion from 'tga::color_t' to 'const T', possible loss of data 1> with 1> [ 1> T=uint8_t 1> ] 1>decoder.cpp(132): message : see reference to function template instantiation 'bool tga::Decoder::readUncompressedData<uint8_t>(const int,uint32_t (__cdecl tga::Decoder::* )(void))' being compiled 1>decoder.cpp(273,41): warning C4244: 'initializing': conversion from 'tga::color_t' to 'T', possible loss of data 1> with 1> [ 1> T=uint8_t 1> ] 1>decoder.cpp(165): message : see reference to function template instantiation 'bool tga::Decoder::readRleData<uint8_t>(const int,uint32_t (__cdecl tga::Decoder::* )(void))' being compiled 1>decoder.cpp(273,21): warning C4244: 'initializing': conversion from 'tga::color_t' to 'const T', possible loss of data 1> with 1> [ 1> T=uint8_t 1> ] 1>decoder.cpp(282,54): warning C4244: 'argument': conversion from 'tga::color_t' to 'const T', possible loss of data 1> with 1> [ 1> T=uint8_t 1> ]

I hope this is a help - I just want to make your code look perfect. Feel free to ignore.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.