IUP

 view release on metacpan or  search on metacpan

lib/IUP/Internal/Canvas_Bitmap.xs.inc  view on Meta::CPAN

                  b = cdBitmapGetData(self, CD_IBLUE);
                  if (!r || !g || !b) XSRETURN_UNDEF;
                  RETVAL = Bitmap2AV(r,g,b,NULL,NULL,self->w,self->h);
                }
                else if (self->type == CD_MAP) {
                  m = cdBitmapGetData(self, CD_INDEX);
                  if (!m) XSRETURN_UNDEF;
                  RETVAL = Bitmap2AV(NULL,NULL,NULL,NULL,m,self->w,self->h);
                }
                else XSRETURN_UNDEF;
        OUTPUT:
                RETVAL

SV*
__Bitmap__Palette(self)
                IUP::Canvas::Bitmap self;
        PREINIT:
                long *c;
                unsigned char *m;
                int max_index=0, i;
        CODE:
                if (self->type != CD_MAP) XSRETURN_UNDEF;
                c = (long*)cdBitmapGetData(self, CD_COLORS);
                m = (unsigned char*)cdBitmapGetData(self, CD_INDEX);
                if (!c || !m) XSRETURN_UNDEF;
                for(i=0; i<self->w*self->h; i++) if(m[i]>max_index) max_index=m[i];                
                if (max_index>255) max_index=255;
                RETVAL = long2AV(c, max_index+1);
        OUTPUT:
                RETVAL

long
__Bitmap__Color(self,n,...)
                IUP::Canvas::Bitmap self;
                int n;
        PREINIT:
                long *c;
        CODE:
                if (self->type!=CD_MAP) XSRETURN_UNDEF;
                if (n<0 || n>=256) XSRETURN_UNDEF;
                c = (long*)cdBitmapGetData(self, CD_COLORS);
                if (!c) XSRETURN_UNDEF;
                if (items>2) {
                  c[n] = SvIV(ST(2));
                  XSRETURN_UNDEF;
                }
                RETVAL = c[n];
        OUTPUT:
                RETVAL

void
__Bitmap__Pixel(self,x,y,...)
                IUP::Canvas::Bitmap self;
                int x;
                int y;
        PREINIT:
                unsigned char *data_buffer=NULL, *r=NULL, *g=NULL, *b=NULL, *a=NULL, *m=NULL;
                int color_space, plane_size=0, plane_count=0, color_count=0;
                int width = self->w;
                int height = self->h;
        PPCODE:
                /* warn("XXX-DEBUG: bitmap.pixel x=%d y=%d items=%d w=%d h=%d\n",x,y,items,width,height); */
                /* warn("XXX-DEBUG: rgb=%d rgba=%d\n", (self->type==CD_RGB), (self->type==CD_RGBA)); */
                if (x<0 || x>=width || y<0 || y>=height ) {
                  warn("Error: x or y out of range");
                }
                else if (self->type==CD_RGBA) {
                  plane_count = 4;
                  r = cdBitmapGetData(self, CD_IRED);
                  g = cdBitmapGetData(self, CD_IGREEN);
                  b = cdBitmapGetData(self, CD_IBLUE);
                  a = cdBitmapGetData(self, CD_IALPHA);
                  if (r && g && b && a) {
                    if (items==3) {
                      XPUSHs(sv_2mortal(newSVuv(r[width*y+x])));
                      XPUSHs(sv_2mortal(newSVuv(g[width*y+x])));
                      XPUSHs(sv_2mortal(newSVuv(b[width*y+x])));
                      XPUSHs(sv_2mortal(newSVuv(a[width*y+x])));
                    }
                                        else if (items>3 && items<7) {
                                          warn("Error: not enough parameters, expected: Pixel(x,y,r,g,b,a)");
                                        }
                    else {
                      r[width*y+x] = SvUV(ST(3));
                      g[width*y+x] = SvUV(ST(4)); 
                      b[width*y+x] = SvUV(ST(5));
                      a[width*y+x] = SvUV(ST(6));
                    }
                  }
                }
                else if (self->type==CD_RGB) {
                  plane_count = 3;
                  r = cdBitmapGetData(self, CD_IRED);
                  g = cdBitmapGetData(self, CD_IGREEN);
                  b = cdBitmapGetData(self, CD_IBLUE);
                  if (r && g && b) {
                    if (items==3) {
                      XPUSHs(sv_2mortal(newSVuv(r[width*y+x])));
                      XPUSHs(sv_2mortal(newSVuv(g[width*y+x])));
                      XPUSHs(sv_2mortal(newSVuv(b[width*y+x])));
                    }
                                        else if (items>3 && items<6) {
                                          warn("Error: not enough parameters, expected: Pixel(x,y,r,g,b)");
                                        }
                    else {
                      r[width*y+x] = SvUV(ST(3));
                      g[width*y+x] = SvUV(ST(4)); 
                      b[width*y+x] = SvUV(ST(5));
                    }
                  }
                }
                else if (self->type==CD_MAP) {
                  plane_count = 1;
                  m = cdBitmapGetData(self, CD_INDEX);
                  if (m) {
                    if (items==3) {
                      XPUSHs(sv_2mortal(newSVuv(m[width*y+x])));
                    }
                    else if (items==4) {
                      m[width*y+x] = SvUV(ST(3));
                    }



( run in 0.957 second using v1.01-cache-2.11-cpan-5511b514fd6 )