/** * setzt einen Pixel auf einen bestimmten Wert. * * @param[in] x X Koordinate des Pixels * @param[in] y Y Koordinate des Pixels * @param[in] r Roter Wert * @param[in] g Grüner Wert * @param[in] b Blauer Wert * @param[in] a Alpha Wert (bei paletted nur 0xFF/0x00 unterstützt) */ void ArchivItem_BitmapBase::setPixel(uint16_t x, uint16_t y, const ColorARGB clr) { assert(x < width_ && y < height_); uint8_t* pxlPtr = getPixelPtr(x, y); if(getFormat() == FORMAT_PALETTED) { // Palettenindex setzen if(clr.getAlpha() == 0) *pxlPtr = palette_->getTransparentIdx(); else *pxlPtr = palette_->lookup(clr); } else clr.toBGRA(pxlPtr); }
void shrinkSurface(SDL_Surface *s, SDL_Surface *d) { SDL_LockSurface(s); SDL_LockSurface(d); for(int x=0; x<d->w; x++){ for(int y=0; y<d->h; y++){ Uint8 *dst = (Uint8 *)getPixelPtr(d,x,y); Uint8 *src = (Uint8 *)getPixelPtr(s,x*4,y*4); int chan[4] = {0}; for(int i=0; i<4; i++){ for(int j=0; j<4; j++){ for(int ch=0; ch<4; ch++){ chan[ch] += src[s->pitch*i + j*4+ch]; } } } for(int ch=0; ch<4; ch++){ dst[ch] = chan[ch] / (4*4); } } } SDL_UnlockSurface(s); SDL_UnlockSurface(d); }
/** * setzt einen Pixel auf einen bestimmten Wert. * * @param[in] x X Koordinate des Pixels * @param[in] y Y Koordinate des Pixels * @param[in] color Farbe des Pixels * @param[in] palette Grundpalette */ void ArchivItem_BitmapBase::setPixel(uint16_t x, uint16_t y, uint8_t colorIdx) { assert(x < width_ && y < height_); uint8_t* pxlPtr = getPixelPtr(x, y); if(getFormat() == FORMAT_PALETTED) *pxlPtr = colorIdx; else { assert(palette_); // RGB+A setzen if(palette_->isTransparent(colorIdx)) // Transparenz pxlPtr[3] = 0x00; else ColorARGB(palette_->get(colorIdx)).toBGRA(pxlPtr); } }
bool isPixelTransparent(SDL_Surface *s, int x, int y){ SDL_LockSurface(s); Uint32 val = *getPixelPtr(s,x,y); SDL_UnlockSurface(s); return val == s->format->colorkey; }