GithubHelp home page GithubHelp logo

image's Introduction

image

Library to work with image files

image is a library (or small set of functions) to work with image files. Mostly it can read and write binary data into a file.

Constructors

The library admits two types of constructors:

image(void);

image(std::string fname);

The first one only creates the file. The second, also opens the file. You can check if an image is open with the method:

bool is_open(void);

To open and close a file you must use the following methods:

int open(std::string fname);

int close(void);

Both functions return zero on correct ending and a non-zero value on error. To perform the write or read of a file, you can use one of the following methods:

int read(char *c);
int read(char *buff, std::streamsize n);
int read(char *buff, std::streamsize n, std::streampos offset);

int write(const char *c);
int write(const char *buff, std::streamsize n);
int write(const char *buff, std::streamsize n, std::streampos offset);

The first one reads/writes one character at the actual position, the second reads/writes n bytes at the actual position, and the last one, reads/writes n bytes at the offset position.

Example

/* test-image.cpp - tests the image library
 * g++ -o test-image -Iinclude -L. test-image.cpp -limage
 */

#include <iostream>
#include <cstring>
#include <image>

int
main(void) {
  image img;
  char dot, elf[3];

  if (img.open("file.elf") != 0) {
    std::cerr << "error openning file 'file.elf'" << std::endl;
    return 1;
  }
  /* Open an ELF file */

  if (img.is_open()) {
    if (img.read(&dot) != 0 || dot != 0x7f) {
      std::cerr << "error reading file" << std::endl;
      return 2;
    }
    if (img.read(elf, 3, 1) != 0 || elf[0] != 0x45 || elf[1] != 0x4c ||
      elf[2] != 0x46) {
      std::cerr << "error reading file" << std::endl;
      return 3;
    }
  }
  /* Read ELF header */

  /* img.close();
  Closing the file isn't necessary, the destructor will do it for us */

  return 0;
}

image's People

Contributors

pawpperoni avatar

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.