Esempio n. 1
0
void GfxSurface::drawPixel(const uint16_t &x, const uint16_t &y, const uint32_t &argbInp, const PixelFormat &src) {
	assert(fb);
	if (x >= width || y >= height)
		return;
	const uint32_t &argb = convertPixel(src, argbInp);
	const size_t offset = (bitsDepth == ColorDepth_4) ?
			(y*bytesPerLine + x/2) : (y*bytesPerLine + x*bytesPerPixel);
	uint8_t *ptrRaw = &fb[offset];

	switch (bitsDepth) {
		case ColorDepth_4: {
			const uint32_t tmp = argb & 0x0F;
			if (x % 2) {
				*ptrRaw &= 0xF0;
				*ptrRaw |= tmp;
			} else {
				*ptrRaw &= 0x0F;
				*ptrRaw |= tmp<<4;
			}
			break;
		}
		default:
			switch (pixelFormat) {
			case PixelFormat_GrayScale:
				// should newer get here
				break;
			case PixelFormat_ARGB8888: {
				uint32_t *ptr = reinterpret_cast<uint32_t *>(ptrRaw);
				*ptr = argb;
				break;
			}
			case PixelFormat_RGB888: {
				uint8_t *ptr = &fb[offset];
				ptr[0] = argb & 0xFF;
				ptr[1] = argb>>8 & 0xFF;;
				ptr[2] = argb>>16 & 0xFF;;
				break;
			}
			case PixelFormat_RGB565: {
				uint16_t *ptr = reinterpret_cast<uint16_t *>(ptrRaw);
				*ptr = argb & 0xFFFF;
				break;
			}
			case PixelFormat_ARGB1555:
			case PixelFormat_ARGB4444:
			case PixelFormat_AL88:
				break;
			case PixelFormat_L8:
			case PixelFormat_AL44:
				break;
			}
	}
}
Esempio n. 2
0
vector<Uint32> BitmapManager::getPixelsFromSurface(SDL_Surface *pSurface) {
    int bpp = pSurface->format->BytesPerPixel;
    int width = pSurface->w;
    int height = pSurface->h;
    vector<Uint32> pixels;


    for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
            Uint8* p = (Uint8 *)pSurface->pixels + y * pSurface->pitch + x * bpp;
            Uint32 pixel = convertPixel(p, bpp);
            pixels.push_back(pixel);
        }
    }

    return pixels;
}
void	ImageTest::testYUYVImage() {
	debug(LOG_DEBUG, DEBUG_LOG, 0, "testYUYVImage() begin");
	// test the conversion of an individual pixel
	YUYV<unsigned char>	p((unsigned char)47, 11);
	unsigned char	v;
	convertPixel(v, p);
	CPPUNIT_ASSERT(47 == v);

	// convert a complete image
	Image<YUYV<unsigned char> >	image2(640, 480);
	convertImage(image2, *image);
	CPPUNIT_ASSERT(image2.pixel(13, 15).y == (13 + 15 * 640) % 160);

	// convert to an unsigned short image
	Image<unsigned char>	image3(640, 480);
	convertImage(image3, image2);
	CPPUNIT_ASSERT(image3 == *image);
	image3.pixel(14,15) = 1;
	CPPUNIT_ASSERT(!(image3 == *image));
	debug(LOG_DEBUG, DEBUG_LOG, 0, "testYUYVImage() end");
}