// test that we can draw an aa-rect at coordinates > 32K (bigger than fixedpoint)
static void test_big_aa_rect(skiatest::Reporter* reporter) {
    SkBitmap output;
    SkPMColor pixel[1];
    output.installPixels(SkImageInfo::MakeN32Premul(1, 1), pixel, 4);

    auto surf = SkSurface::MakeRasterN32Premul(300, 33300);
    SkCanvas* canvas = surf->getCanvas();

    SkRect r = { 0, 33000, 300, 33300 };
    int x = SkScalarRoundToInt(r.left());
    int y = SkScalarRoundToInt(r.top());

    // check that the pixel in question starts as transparent (by the surface)
    if (surf->readPixels(output, x, y)) {
        REPORTER_ASSERT(reporter, 0 == pixel[0]);
    } else {
        REPORTER_ASSERT(reporter, false, "readPixels failed");
    }

    SkPaint paint;
    paint.setAntiAlias(true);
    paint.setColor(SK_ColorWHITE);

    canvas->drawRect(r, paint);

    // Now check that it is BLACK
    if (surf->readPixels(output, x, y)) {
        // don't know what swizzling PMColor did, but white should always
        // appear the same.
        REPORTER_ASSERT(reporter, 0xFFFFFFFF == pixel[0]);
    } else {
        REPORTER_ASSERT(reporter, false, "readPixels failed");
    }
}
Ejemplo n.º 2
0
bool GrSurface::savePixels(const char* filename) {
    SkBitmap bm;
    if (!bm.allocPixels(SkImageInfo::MakeN32Premul(this->width(),
                        this->height()))) {
        return false;
    }

    bool result = readPixels(0, 0, this->width(), this->height(), kSkia8888_GrPixelConfig,
                             bm.getPixels());
    if (!result) {
        SkDebugf("------ failed to read pixels for %s\n", filename);
        return false;
    }

    // remove any previous version of this file
    remove(filename);

    if (!SkImageEncoder::EncodeFile(filename, bm, SkImageEncoder::kPNG_Type, 100)) {
        SkDebugf("------ failed to encode %s\n", filename);
        remove(filename);   // remove any partial file
        return false;
    }

    return true;
}
Ejemplo n.º 3
0
void Framebuffer::readPixelsToBuffer(const std::array<GLint, 4> & rect, GLenum format, GLenum type, Buffer * pbo) const
{
    assert(pbo != nullptr);

    pbo->bind(GL_PIXEL_PACK_BUFFER);
    readPixels(rect, format, type, nullptr);
    pbo->unbind(GL_PIXEL_PACK_BUFFER);
}
Ejemplo n.º 4
0
std::vector<unsigned char> Framebuffer::readPixelsToByteArray(const std::array<GLint, 4> & rect, const GLenum format, const GLenum type) const
{
    int size = imageSizeInBytes(rect[2], rect[3], 1, format, type);
    std::vector<unsigned char> data(size);

    readPixels(rect, format, type, data.data());

    return data;
}
Ejemplo n.º 5
0
//************************************************************
//write jpeg file
//************************************************************
void writeJpegFile(char *filename,double jpeg_quality)
{
	int image_width;
	int image_height;
	GLubyte *rgb=readPixels(image_width, image_height);
	if(rgb){
		write_JPEG_file (filename, rgb, image_width,image_height,jpeg_quality);
		FREE(rgb);
	}
}
Ejemplo n.º 6
0
int main(void) {

	setvbuf(stdout, NULL, _IONBF, 0);

	FILE *input_file1 = fopen("in1.bmp", "rb");
	FILE *input_file2 = fopen("in2.bmp", "rb");
	FILE *blend = fopen("blend.bmp", "wb");
	FILE *checker = fopen("checker.bmp", "wb");

	char headerA_1[2], headerA_2[12], headerA_3[8], headerA_4[16];
	char headerB_1[2], headerB_2[12], headerB_3[8], headerB_4[16];

	int width1 = 0, height1 = 0, width2 = 0, height2 = 0;
	int file_size1 = 0, file_size2 = 0, image_size1 = 0, image_size2 = 0;

	readInputFile(input_file1, headerA_1, headerA_2, headerA_3, headerA_4,
			&file_size1, &image_size1, &width1, &height1);
	readInputFile(input_file2, headerB_1, headerB_2, headerB_3, headerB_4,
			&file_size2, &image_size2, &width2, &height2);

	unsigned char pixels1[height1][width1 * 3], pixels2[height2][width2 * 3];

	unsigned char checkerData[height1][width1 * 3];
	unsigned char blendData[height1][width1 * 3];

	readPixels(input_file1, &width1, &height1, pixels1);
	readPixels(input_file2, &width2, &height2, pixels2);

	blender(&width1, &height1, pixels1, pixels2, blendData);

	transformCheckerBoard(&width1, &height1, pixels1, pixels2, checkerData);

	printOutput(blend, headerA_1, headerA_2, headerA_3, headerA_4,
			&file_size1, &image_size1, &width1, &height1, blendData);

	printOutput(checker, headerB_1, headerB_2, headerB_3, headerB_4,
			&file_size2, &image_size2, &width2, &height2, checkerData);

	fclose(blend);
	fclose(checker);
	return 0;
}
Ejemplo n.º 7
0
// Just snap a rectangle
FXbool ShutterBug::grabRectangle(FXColor*& pixels,const FXRectangle& r){
  pixels=NULL;
  if(1<r.w && 1<r.h){
    if(callocElms(pixels,r.w*r.h)){
      FXImage image(getApp(),pixels,IMAGE_KEEP,r.w,r.h);
      image.create();
      readPixels(&image,r);
      image.restore();
      return true;
      }
    }
  return false;
  }
Ejemplo n.º 8
0
/** Read image in @e filename into memory.
 * 
 * @throw ImageException from open()
 * @throw ImageException from readFileHeader()
 * @throw ImageException from readInfoHeader()
 * @throw ImageException from readPixels()
 * 
 * @see getFormat()
 * @see getPixels()
 * @see getSize()
 * @see getWidth()
 * @see getHeight()
 */
void BmpImageReader::read(const string &filename) {
	
	try {
		open(filename);
		readFileHeader();
		readInfoHeader();
		readPixels();
		close();
	} catch (BasicException &e) {
		close();
		throw e;
	}
}
Ejemplo n.º 9
0
int ImageV1::read(fstream* file, I3C_Frame* frame)
{
    if(frame != NULL){
        frame->clear();
    }

    //Make sure we're at the begining
    file->clear();
    file->seekg (0, ios::beg);

    //Read Side Size
    int error = this->readSideSize(file);
    frame->resolution = m_i_sideSize;
    if(error != I3C_SUCCESS){
        return error;
    }

    //Levels
    m_i_totalMaps = 0;
    m_i_numberOfLevels = firstHighBit(m_i_sideSize);
    frame->numberOfLevels = m_i_numberOfLevels;
    frame->mapAtLevel = new int[m_i_numberOfLevels];
    for(int i = 0; i < m_i_numberOfLevels; i++)
    {
        *file >> m_i_buffer;
        frame->mapAtLevel[i] = m_i_buffer;
        m_i_totalMaps += m_i_buffer;
    }
    frame->cubeMapArraySize = m_i_totalMaps;

    //Allocate memory for map & childId
    frame->childCubeId = new unsigned int[frame->cubeMapArraySize];
    frame->cubeMap = new unsigned char[frame->cubeMapArraySize];

    //Read pixels values
    error = readPixels(file, frame);
    if(error != I3C_SUCCESS){
        return error;
    }

    //Read maps
    error = readParents(file, frame);
    if(error != I3C_SUCCESS){
        return error;
    }

    return I3C_SUCCESS;
}
Ejemplo n.º 10
0
gl::Error FramebufferD3D::readPixels(const gl::State &state, const gl::Rectangle &area, GLenum format, GLenum type, GLvoid *pixels) const
{
    const gl::PixelPackState &packState = state.getPackState();

    if (packState.rowLength != 0 || packState.skipRows != 0 || packState.skipPixels != 0)
    {
        UNIMPLEMENTED();
        return gl::Error(GL_INVALID_OPERATION, "invalid pixel store parameters in readPixels");
    }

    GLenum sizedInternalFormat = gl::GetSizedInternalFormat(format, type);
    const gl::InternalFormat &sizedFormatInfo = gl::GetInternalFormatInfo(sizedInternalFormat);
    GLuint outputPitch = sizedFormatInfo.computeRowPitch(type, area.width, packState.alignment, 0);

    return readPixels(area, format, type, outputPitch, packState, reinterpret_cast<uint8_t*>(pixels));
}
Ejemplo n.º 11
0
// https://bugs.chromium.org/p/skia/issues/detail?id=5023
// We should still shade pixels for which the radius is exactly 0.
static void test_two_point_conical_zero_radius(skiatest::Reporter* reporter) {
    auto surface(SkSurface::MakeRasterN32Premul(5, 5));
    surface->getCanvas()->clear(SK_ColorRED);

    const SkColor colors[] = { SK_ColorGREEN, SK_ColorBLUE };
    SkPaint p;
    p.setShader(SkGradientShader::MakeTwoPointConical(
        SkPoint::Make(2.5f, 2.5f), 0,
        SkPoint::Make(3.0f, 3.0f), 10,
        colors, nullptr, SK_ARRAY_COUNT(colors), SkTileMode::kClamp));
    surface->getCanvas()->drawPaint(p);

    // r == 0 for the center pixel.
    // verify that we draw it (no red bleed)
    SkPMColor centerPMColor;
    surface->readPixels(SkImageInfo::MakeN32Premul(1, 1), &centerPMColor, sizeof(SkPMColor), 2, 2);
    REPORTER_ASSERT(reporter, SkGetPackedR32(centerPMColor) == 0);
}
Ejemplo n.º 12
0
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReimportImageTextureWithMipLevels, reporter, ctxInfo) {
    auto* ctx = ctxInfo.grContext();
    if (!ctx->priv().caps()->mipMapSupport()) {
        return;
    }
    static constexpr auto kCreateWithMipMaps = true;
    auto surf = SkSurface::MakeRenderTarget(
            ctx, SkBudgeted::kYes,
            SkImageInfo::Make(100, 100, kRGBA_8888_SkColorType, kPremul_SkAlphaType), 1,
            kTopLeft_GrSurfaceOrigin, nullptr, kCreateWithMipMaps);
    if (!surf) {
        return;
    }
    surf->getCanvas()->drawColor(SK_ColorDKGRAY);
    auto img = surf->makeImageSnapshot();
    if (!img) {
        return;
    }
    surf.reset();
    GrBackendTexture btex;
    SkImage::BackendTextureReleaseProc texRelease;
    if (!SkImage::MakeBackendTextureFromSkImage(ctx, std::move(img), &btex, &texRelease)) {
        // Not all backends support stealing textures yet.
        // ERRORF(reporter, "Could not turn image into texture");
        return;
    }
    REPORTER_ASSERT(reporter, btex.hasMipMaps());
    // Reimport the texture as an image and perform a downsampling draw with medium quality which
    // should use the upper MIP levels.
    img = SkImage::MakeFromTexture(ctx, btex, kTopLeft_GrSurfaceOrigin, kRGBA_8888_SkColorType,
                                   kPremul_SkAlphaType, nullptr);
    const auto singlePixelInfo =
            SkImageInfo::Make(1, 1, kRGBA_8888_SkColorType, kPremul_SkAlphaType, nullptr);
    surf = SkSurface::MakeRenderTarget(ctx, SkBudgeted::kYes, singlePixelInfo, 1,
                                       kTopLeft_GrSurfaceOrigin, nullptr);
    SkPaint paint;
    paint.setFilterQuality(kMedium_SkFilterQuality);
    surf->getCanvas()->drawImageRect(img, SkRect::MakeWH(1, 1), &paint);
    uint32_t pixel;
    surf->readPixels(singlePixelInfo, &pixel, sizeof(uint32_t), 0, 0);
    REPORTER_ASSERT(reporter, pixel == SkPreMultiplyColor(SK_ColorDKGRAY));
    img.reset();
    texRelease(btex);
}
Ejemplo n.º 13
0
        void read()
        {
            osg::BufferObject::Extensions* ext = osg::BufferObject::getExtensions(_gc->getState()->getContextID(),true);

            if (ext->isPBOSupported() && !_pboBuffer.empty())
            {
                if (_pboBuffer.size()==1)
                {
                    singlePBO(ext);
                }
                else
                {
                    multiPBO(ext);
                }
            }
            else
            {
                readPixels();
            }
        }
Ejemplo n.º 14
0
void		
AcesInputFile::readPixels (int scanLine)
{
    readPixels (scanLine, scanLine);
}
Ejemplo n.º 15
0
void Framebuffer::readPixels(const GLenum readBuffer, const std::array<GLint, 4> & rect, const GLenum format, const GLenum type, GLvoid * data) const
{
    setReadBuffer(readBuffer);
    readPixels(rect, format, type, data);
}
Ejemplo n.º 16
0
void Framebuffer::readPixels(const std::array<GLint, 4> & rect, const GLenum format, const GLenum type, GLvoid * data) const
{
    readPixels(rect[0], rect[1], rect[2], rect[3], format, type, data);
}
Ejemplo n.º 17
0
void FacemarkKazemiImpl :: loadModel(String filename){
    if(filename.empty()){
        String error_message = "No filename found.Aborting....";
        CV_Error(Error::StsBadArg, error_message);
        return ;
    }
    ifstream f(filename.c_str(),ios::binary);
    if(!f.is_open()){
        String error_message = "No file with given name found.Aborting....";
        CV_Error(Error::StsBadArg, error_message);
        return ;
    }
    uint64_t len;
    f.read((char*)&len, sizeof(len));
    char* temp = new char[(size_t)len+1];
    f.read(temp, len);
    temp[len] = '\0';
    string s(temp);
    delete [] temp;
    if(s.compare("cascade_depth")!=0){
        String error_message = "Data not saved properly.Aborting.....";
        CV_Error(Error::StsBadArg, error_message);
        return ;
    }
    uint64_t cascade_size;
    f.read((char*)&cascade_size,sizeof(cascade_size));
    loaded_forests.resize((unsigned long)cascade_size);
    f.read((char*)&len, sizeof(len));
    temp = new char[(unsigned long)len+1];
    f.read(temp, len);
    temp[len] = '\0';
    s = string(temp);
    delete [] temp;
    if(s.compare("pixel_coordinates")!=0){
        String error_message = "Data not saved properly.Aborting.....";
        CV_Error(Error::StsBadArg, error_message);
        return ;
    }
    loaded_pixel_coordinates.resize((unsigned long)cascade_size);
    uint64_t num_pixels;
    f.read((char*)&num_pixels,sizeof(num_pixels));
    for(unsigned long i=0 ; i < cascade_size ; i++){
        loaded_pixel_coordinates[i].resize((unsigned long)num_pixels);
        readPixels(f,i);
    }
    f.read((char*)&len, sizeof(len));
    temp = new char[(unsigned long)len+1];
    f.read(temp, len);
    temp[len] = '\0';
    s = string(temp);
    delete [] temp;
    if(s.compare("mean_shape")!=0){
        String error_message = "Data not saved properly.Aborting.....";
        CV_Error(Error::StsBadArg, error_message);
        return ;
    }
    uint64_t mean_shape_size;
    f.read((char*)&mean_shape_size,sizeof(mean_shape_size));
    meanshape.resize((unsigned long)mean_shape_size);
    f.read((char*)&meanshape[0], meanshape.size() * sizeof(Point2f));
    if(!setMeanExtreme())
        exit(0);
    f.read((char*)&len, sizeof(len));
    temp = new char[(unsigned long)len+1];
    f.read(temp, len);
    temp[len] = '\0';
    s = string(temp);
    delete [] temp;
    if(s.compare("num_trees")!=0){
        String error_message = "Data not saved properly.Aborting.....";
        CV_Error(Error::StsBadArg, error_message);
        return ;
    }
    uint64_t num_trees;
    f.read((char*)&num_trees,sizeof(num_trees));
    for(unsigned long i=0;i<cascade_size;i++){
        for(unsigned long j=0;j<num_trees;j++){
            regtree tree;
            f.read((char*)&len, sizeof(len));
            char* temp2 = new char[(unsigned long)len+1];
            f.read(temp2, len);
            temp2[len] = '\0';
            s =string(temp2);
            delete [] temp2;
            if(s.compare("num_nodes")!=0){
                String error_message = "Data not saved properly.Aborting.....";
                CV_Error(Error::StsBadArg, error_message);
                return ;
            }
            uint64_t num_nodes;
            f.read((char*)&num_nodes,sizeof(num_nodes));
            tree.nodes.resize((unsigned long)num_nodes+1);
            for(unsigned long k=0; k < num_nodes ; k++){
                f.read((char*)&len, sizeof(len));
                char* temp3 = new char[(unsigned long)len+1];
                f.read(temp3, len);
                temp3[len] = '\0';
                s =string(temp3);
                delete [] temp3;
                tree_node node;
                if(s.compare("split")==0){
                    splitr split;
                    readSplit(f,split);
                    node.split = split;
                    node.leaf.clear();
                }
                else if(s.compare("leaf")==0){
                    vector<Point2f> leaf;
                    readLeaf(f,leaf);
                    node.leaf = leaf;
                }
                else{
                    String error_message = "Data not saved properly.Aborting.....";
                    CV_Error(Error::StsBadArg, error_message);
                    return ;
                }
                tree.nodes[k]=node;
            }
            loaded_forests[i].push_back(tree);
        }
    }
    f.close();
    isModelLoaded = true;
}
Ejemplo n.º 18
0
// Ultra fast bitmap drawing
// Only downside is that height must be a multiple of 8, otherwise it gets rounded down to the nearest multiple of 8
// Drawing bitmaps that are completely on-screen and have a Y co-ordinate that is a multiple of 8 results in best performance
// PS - Sorry about the poorly named variables ;_;
// Optimize: Use a local variable temp buffer then apply to global variable OLED buffer?
void draw_bitmap_s2(s_image* image)
{
	byte x = image->x;
	byte yy = image->y;
	const byte* bitmap = image->bitmap;
	byte w = image->width;
	byte h = image->height;
//	byte colour = image->foreColour;
	bool invert = image->invert;
	byte offsetY = image->offsetY;

	// Apply animation offset
	yy += animation_offsetY();

	// 
	byte y = yy - offsetY;

	// 
	byte h2 = h / 8;
	
	// 
	byte pixelOffset = (y % 8);

	byte thing3 = (yy+h);

	// 
	for(byte hh=0;hh<h2;hh++)
	{
		// 
		byte hhh = (hh*8) + y;
		byte hhhh = hhh + 8;

		// 
		if(offsetY && (hhhh < yy || hhhh > FRAME_HEIGHT || hhh > thing3))
			continue;

		// 
		byte offsetMask = 0xFF;
		if(offsetY)
		{
			if(hhh < yy)
				offsetMask = (0xFF<<(yy-hhh));
			else if(hhhh > thing3)
				offsetMask = (0xFF>>(hhhh-thing3));
		}

		uint aa = ((hhh / 8) * FRAME_WIDTH);

		// If() outside of loop makes it faster (doesn't have to kee re-evaluating it)
		// Downside is code duplication
		if(!pixelOffset && hhh < FRAME_HEIGHT)
		{
			// 
			for(byte ww=0;ww<w;ww++)
			{
				// Workout X co-ordinate in frame buffer to place next 8 pixels
				byte xx = ww + x;

				// Stop if X co-ordinate is outside the frame
				if(xx >= FRAME_WIDTH)
					continue;

				// Read pixels
				byte pixels = readPixels((bitmap + (hh*w)) + ww, invert) & offsetMask;

				oledBuffer[xx + aa] |= pixels;

				//setBuffByte(buff, xx, hhh, pixels, colour);
			}
		}
		else
		{
			uint aaa = ((hhhh / 8) * FRAME_WIDTH);
			
			// 
			for(byte ww=0;ww<w;ww++)
			{
				// Workout X co-ordinate in frame buffer to place next 8 pixels
				byte xx = ww + x;

				// Stop if X co-ordinate is outside the frame
				if(xx >= FRAME_WIDTH)
					continue;

				// Read pixels
				byte pixels = readPixels((bitmap + (hh*w)) + ww, invert) & offsetMask;

				// 
				if(hhh < FRAME_HEIGHT)
					oledBuffer[xx + aa] |= pixels << pixelOffset;
					//setBuffByte(buff, xx, hhh, pixels << pixelOffset, colour);				

				// 
				if(hhhh < FRAME_HEIGHT)
					oledBuffer[xx + aaa] |= pixels >> (8 - pixelOffset);
					//setBuffByte(buff, xx, hhhh, pixels >> (8 - pixelOffset), colour);			
			}
		}		
	}
}