1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
|
/*
*
* Copyright (C) 1996 by Josh Osborne.
* All rights reserved.
*
* This software may be freely copied, modified and redistributed without
* fee for non-commerical purposes provided that this copyright notice is
* preserved intact on all copies and modified copies.
*
* There is no warranty or other guarantee of fitness of this software.
* It is provided solely "as is". The author(s) disclaim(s) all
* responsibility and liability with respect to this software's usage
* or its effect upon hardware, computer systems, other software, or
* anything else.
*
*/
#ifndef CODEC_INCLUDED
#define CODEC_INCLUDED
#include "ppm.h"
#include "chunk.h"
class codec {
public:
codec::codec();
virtual int need_prescan();
virtual void start(chunkstream *, int w, int h, int nframes);
virtual void prescan(ppm *, int framenum);
virtual void frame(ppm *, int framenum) = 0;
virtual void done();
virtual chunk *strf() = 0;
virtual chunk *strd() { return NULL; }
virtual char *type_str() = 0;
protected:
chunkstream *cs;
int w, h;
int nframes;
};
struct color {
int operator==(color &c) {
// *only* check rgb
return this->r == c.r && this->g == c.g && this->b == c.b;
}
int dist2(color &c) {
return
+ (this->r - c.r) * (this->r - c.r)
+ (this->g - c.g) * (this->g - c.g)
+ (this->b - c.b) * (this->b - c.b);
}
unsigned char r, g, b;
int cnt;
};
class rgb24_strf : public chunk {
public:
rgb24_strf(chunkstream *cs, int w, int h);
private:
int w, h;
void WRITE();
};
class cram16_strf : public chunk {
public:
cram16_strf(chunkstream *cs, int w, int h);
private:
int w, h;
void WRITE();
};
class rgb24 : public codec {
public:
char *type_str() { return "rgb "; };
chunk *strf() { return new rgb24_strf(this->cs, this->w, this->h); };
void frame(ppm *, int framenum);
};
class cram16 : public codec {
public:
cram16::cram16();
char *type_str() { return "msvc"; }
chunk *strf() { return new cram16_strf(this->cs, this->w, this->h); }
void frame(ppm *, int framenum);
private:
unsigned char *last_frame;
void c8quad(unsigned char *&bp, ppm *p, int x, int y, int setflag,
unsigned char& p1, unsigned char& p2);
void c2block(unsigned char *&bp, ppm *p, int x, int y,
color *ca, int ncolors,
unsigned int& pixel_bits);
void c0blocks(unsigned char *&fstart, unsigned char *&fend, int &count,
int &dealloc);
int csize(unsigned char *c);
unsigned int c24toc16(color *c);
};
#endif
|