plugin/ppm

git-svn-id: svn://ultimatepp.org/upp/trunk@7264 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2014-04-16 12:30:31 +00:00
parent 0fa12a5c3b
commit 08d80195c4
6 changed files with 188 additions and 0 deletions

6
uppsrc/plugin/ppm/init Normal file
View file

@ -0,0 +1,6 @@
#ifndef _plugin_ppm_icpp_init_stub
#define _plugin_ppm_icpp_init_stub
#define BLITZ_INDEX__ Fdf120578bb798e5c9b5d622a2a6f7bf4
#include "ppmref.icpp"
#undef BLITZ_INDEX__
#endif

107
uppsrc/plugin/ppm/ppm.cpp Normal file
View file

@ -0,0 +1,107 @@
#include "ppm.h"
NAMESPACE_UPP
PPMRaster::PPMRaster()
{
size = Size(0, 0);
is16 = false;
}
bool PPMRaster::Create()
{
Stream& stream = GetStream();
size = Size(0, 0);
if(!stream.IsOpen()) {
SetError();
return false;
}
try {
if(stream.GetLine() != "P6")
return false;
String h = stream.GetLine();
CParser p(h);
size.cx = p.ReadInt();
size.cy = p.ReadInt();
if(size.cx <= 0 && size.cx > 99999 || size.cy <= 0 || size.cy >= 99999)
return false;
h = stream.GetLine();
CParser p1(h);
int maxval = p1.ReadInt();
if(maxval <= 0 && maxval > 65535)
return false;
is16 = maxval > 255;
pixel_pos = stream.GetPos();
return true;
}
catch(CParser::Error) {
return false;
}
}
Raster::Info PPMRaster::GetInfo()
{
return Raster::Info();
}
Size PPMRaster::GetSize()
{
return size;
}
Raster::Line PPMRaster::GetLine(int ii)
{
Stream& stream = GetStream();
Line line;
int row_bytes = size.cx * 3;
byte *ptr = new byte[size.cx * 3];
if(!IsError()) {
Stream& stream = GetStream();
stream.Seek(pixel_pos + ii * row_bytes * (1 + is16));
if(is16) {
byte *t = ptr;
for(int n = size.cx; n-- >= 0;) {
int q = stream.Get();
if(q < 0) {
SetError();
break;
}
*t++ = q; stream.Get();
}
return Line(ptr, this, true);
}
else {
if(!stream.GetAll(ptr, row_bytes))
SetError();
}
}
if(IsError())
memset(ptr, 0, row_bytes);
return Line(ptr, this, true);
}
int PPMRaster::GetPaletteCount()
{
return 0;
}
RGBA * PPMRaster::GetPalette()
{
return NULL;
}
const RasterFormat * PPMRaster::GetFormat()
{
static RasterFormat fmt;
ONCELOCK {
fmt.Set24be(0xff0000, 0x00ff00, 0x0000ff);
}
return &fmt;
}
PPMRaster::~PPMRaster()
{
}
END_UPP_NAMESPACE

38
uppsrc/plugin/ppm/ppm.h Normal file
View file

@ -0,0 +1,38 @@
#ifndef _plugin_bmp_bmp_h_
#define _plugin_bmp_bmp_h_
#include <Draw/Draw.h>
NAMESPACE_UPP
class PPMRaster : public StreamRaster {
Size size;
bool is16;
RasterFormat fmt;
int64 pixel_pos;
public:
virtual bool Create();
virtual Info GetInfo();
virtual Size GetSize();
virtual Line GetLine(int line);
virtual int GetPaletteCount();
virtual RGBA *GetPalette();
virtual const RasterFormat *GetFormat();
PPMRaster();
~PPMRaster();
};
class PPMEncoder : public StreamRasterEncoder {
Size size;
public:
virtual int GetPaletteCount();
virtual void Start(Size sz);
virtual void WriteLineRaw(const byte *data);
};
END_UPP_NAMESPACE
#endif

View file

@ -0,0 +1,6 @@
file
ppm.h,
ppmref.icpp,
ppm.cpp,
ppmenc.cpp;

View file

@ -0,0 +1,22 @@
#include "ppm.h"
NAMESPACE_UPP
int PPMEncoder::GetPaletteCount()
{
return 0;
}
void PPMEncoder::Start(Size sz)
{
size = sz;
format.Set24be(0xff0000, 0x00ff00, 0x0000ff);
GetStream() << "P6\n" << AsString(sz.cx) << ' ' << AsString(sz.cy) << "\n" << 255 << "\n";
}
void PPMEncoder::WriteLineRaw(const byte *data)
{
GetStream().Put(data, size.cx * 3);
}
END_UPP_NAMESPACE

View file

@ -0,0 +1,9 @@
#include "ppm.h"
NAMESPACE_UPP
INITBLOCK {
StreamRaster::Register<PPMRaster>();
}
END_UPP_NAMESPACE