1 #ifndef LWPP_IMAGEIO_HANDLER
2 #define LWPP_IMAGEIO_HANDLER
16 LWImageProtocolID prot;
20 : prot(_prot), rc(IPSTAT_OK)
26 LWImageProtocolID
getID()
const {
return prot;}
33 if (prot) prot->done(prot->priv_data, rc);
43 if (prot) prot->setSize(prot->priv_data, w, h);
46 int SetParam (LWImageParam param,
const char *data)
48 if (prot)
return prot->setParam(prot->priv_data, param, data);
52 int SetParam (LWImageParam param,
const std::string data)
54 return SetParam(param, data.c_str());
70 return prot->sendLine(prot->priv_data, line, pix);
75 void SetMap (
int idx,
const unsigned char col[3])
77 if (prot)
return prot->setMap(prot->priv_data, idx, col);
86 void (*
setParam) (
void *, LWImageParam, int, float);
87 int (*
sendLine) (
void *, int,
const LWPixelID);
88 void (*
setMap) (
void *, int,
const unsigned char[3]);
96 int (*
setParam) (
void *, LWImageParam,
const char*);
97 int (*
sendLine) (
void *, int,
const LWPixelID);
98 void (*
setMap) (
void *, int,
const unsigned char[3]);
120 return (protocol != 0);
125 if (protocol) ret = protocol->done ((LWImageProtocolID)protocol->priv_data, rc);
126 if (protocol)
local->done(
local->priv_data, (LWImageProtocolID)protocol);
132 if (protocol) protocol->setSize(protocol->priv_data,w, h);
136 if ((
version == 2) && (protocol))
138 protocol->setParam(protocol->priv_data,p,i,f);
143 if (protocol)
return protocol->sendLine(protocol->priv_data,y,buffer);
146 void SetMap (
int index,
const unsigned char colour[3] )
148 if (protocol) protocol->setMap(protocol->priv_data,index,colour);
153 if ((
version == 3) && (protocol3))
155 return protocol3->setParam(protocol->priv_data,p,c);
159 int SetParam (LWImageParam p,
const std::string str)
161 if ((
version == 3) && (protocol3))
163 return protocol3->setParam(protocol->priv_data,p,str.c_str());
169 if ((
version == 3) && (protocol3))
171 std::ostringstream ss;
179 if ((
version == 3) && (protocol3))
181 std::ostringstream ss;
196 virtual int LoadImage(
const char *filename) = 0;
209 static int Activate(
int version, GlobalFunc *global,
void *l,
void *serverData )
215 LWImageLoaderLocal *local =
static_cast<LWImageLoaderLocal *
>(l);
217 loader.InitHandler(local, version);
218 return loader.LoadImage(local->filename);
220 catch (std::exception &e)
223 return AFUNC_BADAPP_SILENT;
248 static int CBdone(LWInstance inst,
int rc)
254 return saver->
Done(rc);
256 catch (std::exception &e)
259 return IPSTAT_FAILED;
270 catch (std::exception &e)
276 static void CBsetParam(LWInstance inst, LWImageParam p,
int i,
float f)
283 catch (std::exception &e)
289 static int CBsetParam3(LWInstance inst, LWImageParam p,
const char *c)
296 catch (std::exception &e)
302 static int CBsendLine(LWInstance inst,
int y,
const LWPixelID pixel)
310 catch (std::exception &e)
313 return IPSTAT_FAILED;
316 static void CBsetMap(LWInstance inst,
int index,
const unsigned char rgb[3])
321 saver->
SetMap(index, rgb);
323 catch (std::exception &e)
335 protocol.type =
local->type;
336 protocol.priv_data =
this;
342 return local->sendData (
local->priv_data, reinterpret_cast<LWImageProtocolID>(&protocol), flags);
346 protocol3.type =
local->type;
347 protocol3.priv_data =
this;
353 return local->sendData (
local->priv_data, reinterpret_cast<LWImageProtocolID>(&protocol3), flags);
355 else return IPSTAT_FAILED;
377 catch (std::exception &e)
379 SetRC(IPSTAT_FAILED);
393 virtual void SetParam (LWImageParam p,
int i,
float f) {}
394 virtual int SetParam (LWImageParam p,
const char *c) {
return 0;}
396 virtual int SendLine (
int y,
const LWPixelRGB24 *buffer){
return IPSTAT_OK;}
397 virtual int SendLine (
int y,
const LWPixelRGBFP *buffer) {
return IPSTAT_OK;}
398 virtual int SendLine (
int y,
const LWPixelRGBA32 *buffer) {
return IPSTAT_OK;}
399 virtual int SendLine (
int y,
const LWPixelRGBAFP *buffer) {
return IPSTAT_OK;}
400 virtual int SendLine (
int y,
const float *buffer) {
return IPSTAT_OK;}
401 virtual int SendLine (
int y,
const unsigned char *buffer) {
return IPSTAT_OK;}
404 virtual int SendLine (
int y,
const LWPixelID buffer)
407 if (rc != IPSTAT_OK)
return rc;
408 switch (protocol.type)
412 rc =
SendLine(y, static_cast<const unsigned char*>(buffer));
416 rc =
SendLine(y, static_cast<const LWPixelRGB24 *>(buffer));
420 rc =
SendLine(y, static_cast<const LWPixelRGBA32 *>(buffer));
424 rc =
SendLine(y, static_cast<const float *>(buffer));
428 rc =
SendLine(y, static_cast<const LWPixelRGBFP *>(buffer));
432 rc =
SendLine(y, static_cast<const LWPixelRGBAFP *>(buffer));
436 return IPSTAT_FAILED;
439 if (rc != IPSTAT_OK)
return rc;
442 virtual void SetMap (
int index,
const unsigned char colour[3] ) {}
456 static int Activate(
int version, GlobalFunc *global,
void *l,
void *serverData )
462 LWImageSaverLocal *local =
static_cast<LWImageSaverLocal *
>(l);
463 T saver(version, local);
464 return saver.SaveImage(local->filename);
466 catch (std::exception &e)
469 return AFUNC_BADAPP_SILENT;
476 #endif // LWPP_IMAGEIO_HANDLER