Пример #1
0
void Texture::setTransparentColor(unsigned char r, unsigned char g, unsigned char b)
{
	assert( m_data != 0 );
	GLenum fmt;
	if( getBytesPerPixel() == 4 )
	{	
		fmt = GL_RGBA;
		for( int y=0; y<getHeight(); ++y )
		{
			for( int x=0; x<getWidth(); ++x )
			{
				unsigned char* data = getPixel(x,y);
				if( data[0] == r && data[1] == g && data[2] == b )
				{
					data[3] = 0;
				}
			}
		}
	}
	else if( getBytesPerPixel() == 3 )
	{		
		unsigned char* newData = new unsigned char[m_width*m_height*4];
		
		for( int y=0; y<getHeight(); ++y )
		{
			for( int x=0; x<getWidth(); ++x )
			{
				unsigned char* data = getPixel(x,y);
				unsigned char* d = &newData[(y*getWidth()+x)*4];
				d[0] = data[0];
				d[1] = data[1];
				d[2] = data[2];
				d[3] = 0xff;
				if( data[0] == r && data[1] == g && data[2] == b )
				{
					d[3] = 0x00;
				}
			}
		}

		m_bpp = 4;
		fmt = GL_RGBA;
		delete [] m_data;
		m_data = newData;
	}
	else
	{
		esLogEngineError("[%s] Unsupported bytes per pixel: %d", __FUNCTION__, m_bpp);
		return;
	}
	
	glBindTexture(GL_TEXTURE_2D, getNativeId());
	glTexImage2D(GL_TEXTURE_2D, 0, fmt, m_width, m_height, 0,  fmt, GL_UNSIGNED_BYTE, m_data );
	glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
	glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
	glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
}
Пример #2
0
void Bitmap::setInfo(uint32_t w, uint32_t h, Format c, Alpha a, uint32_t stride) {
	_width = w;
	_height = h;
	_stride = max(stride, w * getBytesPerPixel(c));
	_color = c;
	_alpha = a;
}
Пример #3
0
void egl_server_platform_display(
    uint32_t	win,
    KHRN_IMAGE_T*	image,
    uint32_t	cb_arg)
{
#ifdef DIRECT_RENDERING
    assert(0);
    return;
#else
    assert(win != EGL_PLATFORM_WIN_NONE);

    if (!displaying) {
        displaying = true;
        current_win = win;
    }
    assert(win == current_win);    //Can only display on a single window

    {
        android_native_buffer_t* buffer;
        void* bits;

        if (!nativeWindow)
            nativeWindow = get_android_native_window();

        if (nativeWindow) {
            int fenceFd;
            nativeWindow->dequeueBuffer(nativeWindow, &buffer,&fenceFd);
            if(fenceFd >= 0)
                close(fenceFd);

            module->lock(module, buffer->handle,
                         GRALLOC_USAGE_SW_WRITE_OFTEN,
                         0, 0, buffer->width, buffer->height, &bits);

            if (!bpp)
                bpp = getBytesPerPixel(buffer->format);

            if (check_color_format_khrn_image_vs_native_window(image, buffer)) {
                VC_IMAGE_T vc_image;
                khrn_image_fill_vcimage(image, &vc_image);
                vc_image_to_RSO_memory(&vc_image, buffer, bits);
            } else {
                khrn_image_to_native_buffer(image, buffer, bits);
            }

            module->unlock(module, buffer->handle);

            nativeWindow->queueBuffer(nativeWindow, buffer,&fenceFd);
            if(fenceFd >= 0)
                close(fenceFd);
        }
    }

    /* May as well call callback immediately */
    if (egl_callback)
        egl_callback(cb_arg);
#endif
}
Пример #4
0
bool ofPixels_<PixelType>::pasteInto(ofPixels_<PixelType> &dst, int xTo, int yTo) const{
	if (!(isAllocated()) || !(dst.isAllocated()) || getBytesPerPixel() != dst.getBytesPerPixel() || xTo + getWidth()>dst.getWidth() || yTo + getHeight()>dst.getHeight()) return false;

	int bytesToCopyPerRow = (xTo + getWidth()<=dst.getWidth() ? getWidth() : dst.getWidth()-xTo) * getBytesPerPixel();
	int columnsToCopy = yTo + getHeight() <= dst.getHeight() ? getHeight() : dst.getHeight()-yTo;
	PixelType * dstPix = dst.getData() + ((xTo + yTo*dst.getWidth())*dst.getBytesPerPixel());
	const PixelType * srcPix = getData();
	int srcStride = getWidth()*getBytesPerPixel();
	int dstStride = dst.getWidth()*dst.getBytesPerPixel();

	for(int y=0;y<columnsToCopy; y++){
		memcpy(dstPix,srcPix,bytesToCopyPerRow);
		dstPix += dstStride;
		srcPix += srcStride;
	}

	return true;
}
Пример #5
0
uint32 Texture::getPixelNearest(int x, int y) const
{
	if (m_data.empty() || x >= m_width || y >= m_height || x < 0 || y < 0 ||
		getBytesPerPixel() != 4)
	{
		return 0;
	}

	return *(uint32*)&m_data[(x + y * m_width) * 4];
}
Пример #6
0
//! Sets the position of the next read.
bool MrcFileImpl::protectedSetPosition(unsigned int variable, unsigned int timeStep, qulonglong offset)
{
	if (variable>=m_NumVariables || timeStep>=m_NumTimeSteps) {
		return false;
	}
	else {
		m_File.at(1024 + (m_DimX*m_DimY*m_DimZ*timeStep + offset)*getBytesPerPixel(variable));
		return true;
	}
}
Пример #7
0
void ofPixels_<PixelType>::setFromAlignedPixels(const PixelType * newPixels, int width, int height, int channels, int stride) {
	allocate(width, height, channels);
	int dstStride = width * getBytesPerPixel();
	const unsigned char* src = (unsigned char*) newPixels;
	unsigned char* dst =  (unsigned char*) pixels;
	for(int i = 0; i < height; i++) {
		memcpy(dst, src, dstStride);
		src += stride;
		dst += dstStride;
	}
}
Пример #8
0
void Image::crop(Rectangle roi, Image* orgImg) {

	// Crop from own image
	if (orgImg == NULL && isValid()) {
		assert(roi.getTop() >= 0 && roi.getBottom() <= getHeight()
				&& roi.getLeft() >= 0 && roi.getRight() <= getWidth());
		// Temp buffer
		unsigned char* newBuff = new unsigned char[(int)(roi.getWidth()	* roi.getHeight() * getBytesPerPixel())];
		unsigned char* newBuffPtr = newBuff;

		LOG_DEBUG("Crop from own buffer");
		for (int h = roi.getTop(); h < roi.getBottom(); h++) {
			memcpy(newBuffPtr, getPtr<unsigned char>(h,roi.getLeft()),
					getBytesPerPixel() * roi.getWidth());

			newBuffPtr += (int)(getBytesPerPixel() * roi.getWidth());
		}
		if (m_ownMem)
			releaseData();

		m_data = newBuff;
		m_ownMem = true;
		m_width = roi.getWidth();
		m_height = roi.getHeight();

	}
	// Crop from other image
	else if(orgImg != NULL){
		assert(	roi.getTop() >= 0 && roi.getBottom() <= orgImg->getHeight()
				&& roi.getLeft() >= 0
				&& roi.getRight() <= orgImg->getWidth());

		init(roi.getWidth(), roi.getHeight(), orgImg->getFormat());
		for (int h = roi.getTop(); h < roi.getBottom(); h++) {
			memcpy(getPtr<unsigned char>(h), orgImg->getPtr<unsigned char>(h,roi.getLeft()),	orgImg->getBytesPerPixel() * roi.getWidth());
		}
	}else{
		LOG_ERROR("Can't crop from my own buffer. Not initialized!");
	}

}
Пример #9
0
void ofPixels_<PixelType>::setFromAlignedPixels(const PixelType * newPixels, int width, int height, ofPixelFormat _pixelFormat, int stride) {
	int channels = channelsFromPixelFormat(_pixelFormat);
	if(channels==0) return;

	if(width*channels==stride){
		setFromPixels(newPixels,width,height,_pixelFormat);
		return;
	}
	allocate(width, height, _pixelFormat);
	int dstStride = width * getBytesPerPixel();
	const unsigned char* src = (unsigned char*) newPixels;
	unsigned char* dst =  (unsigned char*) pixels;
	for(int i = 0; i < height; i++) {
		memcpy(dst, src, dstStride);
		src += stride;
		dst += dstStride;
	}
}
Пример #10
0
bool ofPixels_<PixelType>::blendInto(ofPixels_<PixelType> &dst, int xTo, int yTo) const{
	if (!(isAllocated()) || !(dst.isAllocated()) || getBytesPerPixel() != dst.getBytesPerPixel() || xTo + getWidth()>dst.getWidth() || yTo + getHeight()>dst.getHeight() || getNumChannels()==0) return false;

	std::function<void(const ConstPixel&,Pixel&)> blendFunc;
	switch(getNumChannels()){
	case 1:
		blendFunc = [](const ConstPixel&src, Pixel&dst){
			dst[0] = clampedAdd(src[0], dst[0]);
		};
		break;
	case 2:
		blendFunc = [](const ConstPixel&src, Pixel&dst){
			dst[0] = clampedAdd(src[0], dst[0] / ofColor_<PixelType>::limit() * (ofColor_<PixelType>::limit() - src[1]));
			dst[1] = clampedAdd(src[1], dst[1] / ofColor_<PixelType>::limit() * (ofColor_<PixelType>::limit() - src[1]));
		};
		break;
	case 3:
		blendFunc = [](const ConstPixel&src, Pixel&dst){
			dst[0] = clampedAdd(src[0], dst[0]);
			dst[1] = clampedAdd(src[1], dst[1]);
			dst[2] = clampedAdd(src[2], dst[2]);
		};
		break;
	case 4:
		blendFunc = [](const ConstPixel&src, Pixel&dst){
			dst[0] = clampedAdd(src[0], dst[0] / ofColor_<PixelType>::limit() * (ofColor_<PixelType>::limit() - src[3]));
			dst[1] = clampedAdd(src[1], dst[1] / ofColor_<PixelType>::limit() * (ofColor_<PixelType>::limit() - src[3]));
			dst[2] = clampedAdd(src[2], dst[2] / ofColor_<PixelType>::limit() * (ofColor_<PixelType>::limit() - src[3]));
			dst[3] = clampedAdd(src[3], dst[3] / ofColor_<PixelType>::limit() * (ofColor_<PixelType>::limit() - src[3]));
		};
		break;
	}
	auto dstLine = dst.getLine(yTo);
	for(auto line: getConstLines()){
		auto dstPixel = dstLine.getPixels().begin() + xTo;
		for(auto p: line.getPixels()){
			blendFunc(p,dstPixel);
			dstPixel++;
		}
		dstLine++;
	}

	return true;
}
Пример #11
0
  void ImageDecoder::getRawBytes(unsigned char *image_buffer) {
    ERR err = WMP_errSuccess;
	I32 width, height, bytesPerPixel;
    PKRect rc;

    bytesPerPixel = (I32) getBytesPerPixel();
    Call(pDecoder->GetSize(pDecoder, &width, &height));

    rc.X = 0;
    rc.Y = 0;
    rc.Width = width;
    rc.Height = height;

    Call(pDecoder->Copy(pDecoder, &rc, image_buffer, width * bytesPerPixel));
    return;
  Cleanup:
    std::stringstream msg;
    msg << "ERROR: Could not get image bytes: " << err;
    std::string errMsg = msg.str();
    throw FormatError(errMsg);
  }
Пример #12
0
bool OGLTextDriver::init(const char* fontTextureName, int charStep, int fontWidth, int fontHeight, int screenWidth, int screenHeight)
{
	if(!fontTextureName) return false;
	texName_ = fontTextureName;

	//fontTexture_ = SDL_LoadBMP(texName_.c_str());
	//if(!fontTexture_) return false;

	fontTexture_ = new Image();
	if( false == fontTexture_->loadFromFile( texName_.c_str() ) )
		return false;
	
	// support only 32bit textures :P

	//int bpp = fontTexture_->format->BytesPerPixel;
	//if(4 != bpp) return false; 
	if( 4 != getBytesPerPixel(fontTexture_->getFormat()))
		return false;

	glGenTextures(1, &texID_);
	glBindTexture(GL_TEXTURE_2D, texID_);

	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, fontTexture_->getWidth(), 
		fontTexture_->getHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, 
		fontTexture_->getPixels());

	fontWidth_ = fontWidth;
	fontHeight_ = fontHeight;

	scrWidth_ = screenWidth;
	scrHeight_ = screenHeight;

	charStep_ = charStep;

	return true;
}
Пример #13
0
void ImagesLoader::saveToFile(const Image* object, const std::string& fileName){
    Image img(object->getSize(), PXF_A8R8G8B8);
    img.copyImage(*object);

    img.flip();

    ILuint tx;
    ilGenImages(1, &tx);
    ilBindImage(tx);

    const glm::ivec2& size = img.getSize();

    if(!ilTexImage(size.x, size.y, 1, getBytesPerPixel(img.getFormat()),
                   IL_BGRA, IL_UNSIGNED_BYTE, (void*)img.getData()))
        throw LoadingFailed(fileName);

    if(!ilSaveImage(const_cast<ILstring>(fileName.c_str())))
        throw LoadingFailed(fileName);

    ilBindImage(0);
    ilDeleteImages(1, &tx);

}
Пример #14
0
BitmapPtr FWCamera::getImage(bool bWait)
{
#ifdef AVG_ENABLE_1394_2
    bool bGotFrame = false;
    unsigned char * pCaptureBuffer = 0;
    dc1394video_frame_t * pFrame;
    dc1394error_t err;
    if (bWait) {
        err = dc1394_capture_dequeue(m_pCamera, DC1394_CAPTURE_POLICY_WAIT, &pFrame);
    } else {
        err = dc1394_capture_dequeue(m_pCamera, DC1394_CAPTURE_POLICY_POLL, &pFrame);
    }
    if (err == DC1394_SUCCESS && pFrame) {
        bGotFrame = true;
        pCaptureBuffer = pFrame->image;
    }
    if (bGotFrame) {
        int lineLen;
        if (getCamPF() == YCbCr411) {
            lineLen = getImgSize().x*1.5;
        } else {
            lineLen = getImgSize().x*getBytesPerPixel(getCamPF());
        }
        BitmapPtr pCamBmp(new Bitmap(getImgSize(), getCamPF(), pCaptureBuffer, lineLen,
                false, "TempCameraBmp"));
        BitmapPtr pDestBmp = convertCamFrameToDestPF(pCamBmp);
//        cerr << "CamBmp: " << pCamBmp->getPixelFormat() << ", DestBmp: " 
//                << pDestBmp->getPixelFormat() << endl;
        dc1394_capture_enqueue(m_pCamera, pFrame);
        return pDestBmp;
    } else {
        return BitmapPtr();
    }
#else
    return BitmapPtr();
#endif
}
Пример #15
0
    void Mem2Native::updateTexture()
    {
        int SIZE = _size;
        if (!SIZE)
            SIZE = RECT_SIZE;

        MemoryTexture* src = _opt->src.get();
        NativeTexture* dest = _opt->dest.get();
        Point& prev = _prev;

        bool done = false;

        if (isCompressedFormat(src->getFormat()))
        {
            dest->init(src->lock(), false);
            done = true;
        }
        else
        {

            Rect textureRect(0, 0, src->getWidth(), src->getHeight());

            if (dest->getHandle() == 0)
                dest->init(textureRect.getWidth(), textureRect.getHeight(), src->getFormat());


            Rect srcRect(prev.x, prev.y,
                         std::min(SIZE, textureRect.getWidth()), std::min(SIZE, textureRect.getHeight()));
            srcRect.clip(textureRect);


            ImageData srcim = src->lock(&srcRect);


            ImageData destim;
            if (srcRect != textureRect)
            {
                int pitch = srcRect.getWidth() * getBytesPerPixel(dest->getFormat());
                _buffer.resize(srcRect.getHeight() * pitch);
                destim = ImageData(
                             srcRect.getWidth(), srcRect.getHeight(),
                             pitch,
                             dest->getFormat(),
                             &_buffer[0]
                         );

                operations::copy(srcim, destim);
            }
            else
            {
                destim = srcim;
            }

            dest->updateRegion(srcRect.pos.x, srcRect.pos.y, destim);

            prev.x += SIZE;
            if (prev.x >= textureRect.getWidth())
            {
                prev.x = 0;
                prev.y += SIZE;
            }

            if (prev.y >= textureRect.getBottom())
            {
                _buffer.clear();
                prev = Point(0, 0);
                done = true;
            }
        }

        if (done)
        {
            textureDone();
        }
    }
Пример #16
0
Bitmap::Bitmap(Bytes &&d, uint32_t width, uint32_t height, Format c, Alpha a, uint32_t stride)
: _color(c), _alpha(a), _width(width), _height(height), _stride(max(stride, width * getBytesPerPixel(c))), _data(std::move(d)) { }
Пример #17
0
Bitmap::Bitmap(const uint8_t *d, uint32_t width, uint32_t height, Format c, Alpha a, uint32_t stride)
: _color(c), _alpha(a), _width(width), _height(height), _stride(max(stride, width * getBytesPerPixel(c))), _data(d, d + _stride * height) { }
Пример #18
0
int AdobeSurface::estimateLength( const QSize surf_size, QImage::Format format )
{
    return getBytesPerPixel( format )  * surf_size.width() * surf_size.height();
}
Пример #19
0
const string CompressedImage::toString() const {
    stringstream sstr;
    sstr << "name = " << getName() << ", width = " << getWidth() << ", height = " << getHeight() << ", bytes per pixel = " << getBytesPerPixel() << ", compressed size = " << getCompressedSize();
    return sstr.str();
}
Пример #20
0
void ofPixels_<PixelType>::setFromPixels(const PixelType * newPixels,int w, int h, int channels){
	allocate(w, h, channels);
	memcpy(pixels, newPixels, w * h * getBytesPerPixel());
}
    TexturesInspector::TexturesInspector(const Vector2& size)
    {
        setSize(size);

        spSlidingActor slide = new SlidingActor;
        slide->setSize(size);
        addChild(slide);


        float offsetY = 0;

        std::vector<spNativeTexture> textures = NativeTexture::getCreatedTextures();


        spTextField text = initActor(new TextField,
                                     arg_color = Color::White,
                                     arg_pos = Vector2(1, 1),
                                     arg_w = itemSize.x * 3.0f,
                                     arg_h = 30.0f,
                                     arg_vAlign = TextStyle::VALIGN_TOP,
                                     arg_hAlign = TextStyle::HALIGN_LEFT,
                                     arg_multiline = true,
                                     arg_attachTo = slide
                                    );


        offsetY += text->getTextRect().getBottom() + 5;

        spActor content = new Actor;
        content->setX(2);


        int numX = (int)(size.x / itemSize.x);

        int n = 0;
        int mem = 0;
        for (std::vector<spNativeTexture>::reverse_iterator i = textures.rbegin(); i != textures.rend(); ++i)
        {
            spNativeTexture t = *i;
            TextureLine* line = new TextureLine(t);

            float x = (n % numX) * (itemSize.x + 5.0f);
            float y = (n / numX) * (itemSize.y + 5.0f);
            line->setX(x);
            line->setY(y + offsetY);
            content->addChild(line);
            ++n;

            if (t->getHandle())
            {
                TextureFormat fmt = t->getFormat();
                int ram = t->getWidth() * t->getHeight();
                if (isCompressedFormat(fmt))
                {
                    switch (fmt)
                    {
                        case TF_PVRTC_4RGBA:
                            ram /= 2;
                            break;
                        case TF_ETC1:
                            ram /= 2;
                            break;
                        default:
                            break;
                    }
                }
                else
                    ram *= getBytesPerPixel(fmt);

                mem += ram;
            }
        }

        char txt[255];
        safe_sprintf(txt, "created textures: %d, vram: %d kb", textures.size(), mem / 1024);

        text->setText(txt);
        if (numX > n)
            numX = n;

        content->setSize(
            (itemSize.x + 5.0f) * numX,
            (itemSize.y + 5.0f) * (n + numX - 1.0f) / numX + offsetY);

        setWidth(content->getWidth());
        slide->setWidth(content->getWidth());

        //slide->setSize()
        slide->setContent(content);
    }
Пример #22
0
void ofPixels_<PixelType>::setFromPixels(const PixelType * newPixels, int w, int h, ofPixelFormat format){
	allocate(w,h,format);
	memcpy(pixels, newPixels, w * h * getBytesPerPixel());
}
Пример #23
0
bool Bitmap::convert(Format color, const StrideFn &strideFn) {
	bool ret = false;
	Bytes out;
	uint32_t outStride = (strideFn)?max(strideFn(color, _width), _width*getBytesPerPixel(color)):_width*getBytesPerPixel(color);
	if (_color == color && outStride != _stride) {
		out.resize(_height * outStride);
		size_t minStride = _width * getBytesPerPixel(_color);
		for (size_t j = 0; j < _height; j ++) {
			memcpy(out.data() + j * outStride, _data.data() + j * _stride, minStride);
		}
		_data = std::move(out);
		_stride = outStride;
		return true;
	}
	switch (_color) {
	case Format::A8:
		switch (color) {
		case Format::A8: return true; break;
		case Format::I8: _color = color; return true; break;
		case Format::IA88: ret = convertData<Format::A8, Format::IA88>(_data, out, _stride, outStride); break;
		case Format::RGB888: ret = convertData<Format::A8, Format::RGB888>(_data, out, _stride, outStride); break;
		case Format::RGBA8888: ret = convertData<Format::A8, Format::RGBA8888>(_data, out, _stride, outStride); break;
		}
		break;
	case Format::I8:
		switch (color) {
		case Format::A8: _color = color; return true; break;
		case Format::I8: return true; break;
		case Format::IA88: ret = convertData<Format::I8, Format::IA88>(_data, out, _stride, outStride); break;
		case Format::RGB888: ret = convertData<Format::I8, Format::RGB888>(_data, out, _stride, outStride); break;
		case Format::RGBA8888: ret = convertData<Format::I8, Format::RGBA8888>(_data, out, _stride, outStride); break;
		}
		break;
	case Format::IA88:
		switch (color) {
		case Format::A8: ret = convertData<Format::IA88, Format::A8>(_data, out, _stride, outStride); break;
		case Format::I8: ret = convertData<Format::IA88, Format::I8>(_data, out, _stride, outStride); break;
		case Format::IA88: return true; break;
		case Format::RGB888: ret = convertData<Format::IA88, Format::RGB888>(_data, out, _stride, outStride); break;
		case Format::RGBA8888: ret = convertData<Format::IA88, Format::RGBA8888>(_data, out, _stride, outStride); break;
		}
		break;
	case Format::RGB888:
		switch (color) {
		case Format::A8: ret = convertData<Format::RGB888, Format::A8>(_data, out, _stride, outStride); break;
		case Format::I8: ret = convertData<Format::RGB888, Format::I8>(_data, out, _stride, outStride); break;
		case Format::IA88: ret = convertData<Format::RGB888, Format::IA88>(_data, out, _stride, outStride); break;
		case Format::RGB888: return true; break;
		case Format::RGBA8888: ret = convertData<Format::RGB888, Format::RGBA8888>(_data, out, _stride, outStride); break;
		}
		break;
	case Format::RGBA8888:
		switch (color) {
		case Format::A8: ret = convertData<Format::RGBA8888, Format::A8>(_data, out, _stride, outStride); break;
		case Format::I8: ret = convertData<Format::RGBA8888, Format::I8>(_data, out, _stride, outStride); break;
		case Format::IA88: ret = convertData<Format::RGBA8888, Format::IA88>(_data, out, _stride, outStride); break;
		case Format::RGB888: ret = convertData<Format::RGBA8888, Format::RGB888>(_data, out, _stride, outStride); break;
		case Format::RGBA8888: return true; break;
		}
		break;
	}

	if (ret) {
		_color = color;
		_data = std::move(out);
		_stride = outStride;
	}

	return ret;
}
Пример #24
0
	ImageData::ImageData(int W, int H, int Pitch, TextureFormat Format, void *Data):w(W), h(H), pitch(Pitch), format(Format), data((unsigned char *)Data)
	{
		bytespp = getBytesPerPixel(Format);
	}
Пример #25
0
bool ofPixels_<PixelType>::resizeTo(ofPixels_<PixelType>& dst, ofInterpolationMethod interpMethod) const{
	if(&dst == this){
		return true;
	}

	if (!(isAllocated()) || !(dst.isAllocated()) || getBytesPerPixel() != dst.getBytesPerPixel()) return false;

	int srcWidth      = getWidth();
	int srcHeight     = getHeight();
	int dstWidth	  = dst.getWidth();
	int dstHeight	  = dst.getHeight();
	int bytesPerPixel = getBytesPerPixel();


	PixelType * dstPixels = dst.getData();

	switch (interpMethod){

			//----------------------------------------
		case OF_INTERPOLATE_NEAREST_NEIGHBOR:{
			int dstIndex = 0;
			float srcxFactor = (float)srcWidth/dstWidth;
			float srcyFactor = (float)srcHeight/dstHeight;
			float srcy = 0.5;
			for (int dsty=0; dsty<dstHeight; dsty++){
				float srcx = 0.5;
				int srcIndex = int(srcy)*srcWidth;
				for (int dstx=0; dstx<dstWidth; dstx++){
					int pixelIndex = int(srcIndex + srcx) * bytesPerPixel;
					for (int k=0; k<bytesPerPixel; k++){
						dstPixels[dstIndex] = pixels[pixelIndex];
						dstIndex++;
						pixelIndex++;
					}
					srcx+=srcxFactor;
				}
				srcy+=srcyFactor;
			}
		}break;

			//----------------------------------------
		case OF_INTERPOLATE_BILINEAR:
			// not implemented yet
			ofLogError("ofPixels") << "resizeTo(): bilinear resize not implemented, not resizing";
			break;

			//----------------------------------------
		case OF_INTERPOLATE_BICUBIC:
			float px1, py1;
			float px2, py2;
			float px3, py3;

			float srcColor = 0;
			float interpCol;
			int patchRow;
			int patchIndex;
			float patch[16];

			int srcRowBytes = srcWidth*bytesPerPixel;
			int loIndex = (srcRowBytes)+1;
			int hiIndex = (srcWidth*srcHeight*bytesPerPixel)-(srcRowBytes)-1;

			for (int dsty=0; dsty<dstHeight; dsty++){
				for (int dstx=0; dstx<dstWidth; dstx++){

					int   dstIndex0 = (dsty*dstWidth + dstx) * bytesPerPixel;
					float srcxf = srcWidth  * (float)dstx/(float)dstWidth;
					float srcyf = srcHeight * (float)dsty/(float)dstHeight;
					int   srcx = (int) MIN(srcWidth-1,   srcxf);
					int   srcy = (int) MIN(srcHeight-1,  srcyf);
					int   srcIndex0 = (srcy*srcWidth + srcx) * bytesPerPixel;

					px1 = srcxf - srcx;
					py1 = srcyf - srcy;
					px2 = px1 * px1;
					px3 = px2 * px1;
					py2 = py1 * py1;
					py3 = py2 * py1;

					for (int k=0; k<bytesPerPixel; k++){
						int   dstIndex = dstIndex0+k;
						int   srcIndex = srcIndex0+k;

						for (int dy=0; dy<4; dy++) {
							patchRow = srcIndex + ((dy-1)*srcRowBytes);
							for (int dx=0; dx<4; dx++) {
								patchIndex = patchRow + (dx-1)*bytesPerPixel;
								if ((patchIndex >= loIndex) && (patchIndex < hiIndex)) {
									srcColor = pixels[patchIndex];
								}
								patch[dx*4 + dy] = srcColor;
							}
						}

						interpCol = (PixelType)bicubicInterpolate(patch, px1,py1, px2,py2, px3,py3);
						dstPixels[dstIndex] = interpCol;
					}

				}
			}
			break;
	}

	return true;
}