forked from umlaeute/Gem
-
Notifications
You must be signed in to change notification settings - Fork 1
/
pix_share_read.cpp
61 lines (52 loc) · 1.38 KB
/
pix_share_read.cpp
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
/*
* pix_share_read.cpp
* GEM_darwin
*
* Created by lincoln on 9/29/05.
* Copyright 2005 __MyCompanyName__. All rights reserved.
*
*/
#include "Gem/Image.h"
#include "pix_share_read.h"
#include "Gem/State.h"
#include <errno.h>
CPPEXTERN_NEW_WITH_GIMME(pix_share_read);
pix_share_read :: pix_share_read(int argc, t_atom*argv)
: pix_share_write(argc,argv)
{}
pix_share_read :: ~pix_share_read()
{
/* the destructor of the parent class pix_free_write already frees the shm-segment */
//freeShm();
}
void pix_share_read :: render(GemState *state)
{
#ifndef _WIN32
if(shm_id>0){
#else
if(m_MapFile){
#endif /* _WIN32 */
if (shm_addr != (void *)-1) {
t_pixshare_header *h=(t_pixshare_header *)shm_addr;
unsigned char* data=shm_addr+sizeof(t_pixshare_header);
int csize=pix.image.setCsizeByFormat(h->format);
int imgsize=csize*h->xsize*h->ysize;
if(imgsize){
pix.image.xsize=h->xsize;
pix.image.ysize=h->ysize;
pix.image.reallocate();
pix.image.upsidedown=h->upsidedown;
memcpy(pix.image.data,data,imgsize);
pix.newimage = true;
state->set(GemState::_PIX, &pix);
}
} else {
error("no shmaddr. error #%d",errno);
t_atom atom;
SETFLOAT(&atom, -1);
outlet_anything(m_outlet, gensym("error"), 1, &atom);
}
}
}
void pix_share_read :: obj_setupCallback(t_class *classPtr)
{}