Exemplo n.º 1
0
static void writeMipMap(Common::WriteStream &stream, const ImageDecoder::MipMap &mipMap, PixelFormat format) {
	const byte *data = mipMap.data.get();

	uint32 count = mipMap.width * mipMap.height;
	while (count-- > 0)
		writePixel(stream, data, format);
}
Exemplo n.º 2
0
void Image::write(string filepath) throw(ExceptionTP1) {
    
    // Création d'un fichier (mode out)
    ofstream ofs;
    ofs.open(filepath);
    
    if (ofs.is_open()) {
        
        // Ecriture du header
        ofs << CODE_PPM;
        ofs << '\n';
        ofs << m_largeur;
        ofs << " ";
        ofs << m_hauteur;
        ofs << '\n';
        ofs << NB_COULEURS;
        ofs << '\n';
        
        // Boucle d'écriture des pixels
        int lineSize = 0;
        for (int i = 0; i < (int)m_pixels.size(); i++) {
            lineSize = writePixel(m_pixels[i], ofs, lineSize);
        }
    
    }
    else {
        throw ExceptionTP1(ERREUR_ECRITURE);
    }
    
    ofs.close();
}
Exemplo n.º 3
0
void dumpTGA(const Common::UString &fileName, const byte *data, int width, int height, PixelFormat format) {
	if ((width <= 0) || (height <= 0) || !data)
		throw Common::Exception("Invalid image data (%dx%d %d)", width, height, data != 0);

	Common::WriteFile file;

	if (!file.open(fileName))
		throw Common::Exception(Common::kOpenError);

	file.writeByte(0); // ID Length
	file.writeByte(0); // Palette size
	file.writeByte(2); // Unmapped RGB
	file.writeUint32LE(0); // Color map
	file.writeByte(0);     // Color map
	file.writeUint16LE(0); // X
	file.writeUint16LE(0); // Y

	file.writeUint16LE(width);
	file.writeUint16LE(height);

	file.writeByte(32); // Pixel depths

	file.writeByte(0);

	uint32 count = width * height;
	for (uint32 i = 0; i < count; i++)
		writePixel(file, data, format);

	file.close();
}
Exemplo n.º 4
0
void trans_accum_save_4x4(int width, int pixelsNum, uint32_t *src,
                          int src_stride, uint16_t *dst, int dst_stride,
                          int bd) {
  __m128i u[4], v[4];
  const __m128i ones = _mm_set1_epi16(1);

  transClipPixel(src, src_stride, u, bd);

  v[0] = _mm_loadl_epi64((__m128i const *)dst);
  v[1] = _mm_loadl_epi64((__m128i const *)(dst + dst_stride));
  v[2] = _mm_loadl_epi64((__m128i const *)(dst + 2 * dst_stride));
  v[3] = _mm_loadl_epi64((__m128i const *)(dst + 3 * dst_stride));

  u[0] = _mm_add_epi16(u[0], v[0]);
  u[1] = _mm_add_epi16(u[1], v[1]);
  u[2] = _mm_add_epi16(u[2], v[2]);
  u[3] = _mm_add_epi16(u[3], v[3]);

  u[0] = _mm_add_epi16(u[0], ones);
  u[1] = _mm_add_epi16(u[1], ones);
  u[2] = _mm_add_epi16(u[2], ones);
  u[3] = _mm_add_epi16(u[3], ones);

  u[0] = _mm_srai_epi16(u[0], 1);
  u[1] = _mm_srai_epi16(u[1], 1);
  u[2] = _mm_srai_epi16(u[2], 1);
  u[3] = _mm_srai_epi16(u[3], 1);

  writePixel(u, width, pixelsNum, dst, dst_stride);
}
Exemplo n.º 5
0
/* write whole image to file */
void Image::writeImage(Pixel* Pixels) {

	int size = this->width*this->height;

	for(int i=size-1; i >=0 ; i --) {
		writePixel(Pixels[i]);
	}

}
Exemplo n.º 6
0
//LCD Unbuffered Functions
drawToB(int x0, int y0, int x1, int y1) {
	uint8_t steep = abs(y1 - y0) > abs(x1 - x0);
	uint8_t dx, dy;
	int8_t err;
	int8_t ystep;

	if (steep) {
		swap(x0, y0);
		swap(x1, y1);
	}

	if (x0 > x1) {
		swap(x0, x1);
		swap(y0, y1);
	}

	dx = x1 - x0;
	dy = abs(y1 - y0);

	err = dx / 2;

	if (y0 < y1) {
		ystep = 1;
	} else {
		ystep = -1;
	}

	for (; x0<=x1; x0++) {
		if (steep) {
			writePixel(y0, x0);
		} else {
			writePixel(x0, y0);
		}
		err -= dy;
		if (err < 0) {
			y0 += ystep;
			err += dx;
		}
	}
}
Exemplo n.º 7
0
//--------Delivers BMP Image---------//
void serveBMP (int socket, char request[]) {
    int row = -SIZE/2;    //Defines where each row should start
    int col = -SIZE/2;    //Defines where first column should start

    int iterations = 0;   //Count the amount of iterations needed
                          //to escape the set
    
    complex current;      //The current coodinates of the point
                          //being tested

    int colCounter = 0;   //Current collum
    int rowCounter = 0;   //Current row
    
    int zoom = 0;         //The zoom level of the image
    double xMiddle = 0;   //The x (real) component of the 
                          //center of the image
    double yMiddle = 0;   //The y (imaginary) component of the 
                          //center of the image

    bits8 byte = 0;       //Intensity of color from each sub-pixel
    
    writeHTTPHeader(socket);
    writeBMPHeader(socket);

    //get coordinates from URL
    sscanf (request, "GET /tile_x%lf_y%lf_z%d.bmp",
            &xMiddle,&yMiddle,&zoom);

    //print each pixel out
    while (rowCounter < SIZE){
        current.y = yMiddle + row*exp2(-1*zoom) + exp2(-1*zoom)/2;
        while (colCounter < SIZE){
            current.x = xMiddle + col*exp2(-1*zoom) + exp2(-1*zoom)/2;

            iterations = escapeSteps(current.x,current.y);

            writePixel (socket,iterations, byte);

            col++;
            colCounter++;
        }
        col = -SIZE/2;
        colCounter = 0;

        row++;
        rowCounter++;
    }

}
Exemplo n.º 8
0
void BitmapWriter::writeBitmap(Bitmap & bitmap, const char * filePath)
{
    FILE * file = fopen(filePath, "wb");

    writeFileHeader(bitmap.fileheader, file);
    writeInfoHeader(bitmap.infoheader, file);
    
    byte zero = 0;
    
    for (int i = 0; i < bitmap.height; i++) {
        for (int j = 0; j < bitmap.width; j++)
            writePixel(bitmap.get(j, i), file);
        
        for (int j = 0; j < bitmap.paddingZeros; j++)
            fwrite(&zero, sizeof(byte), 1, file);
    }
    
    fclose(file);
}
Exemplo n.º 9
0
drawTo(int x1, int y1, int x2, int y2) {

	int dx;
	int dy;

	int yax = 0;
	int xax = 0;

	dx = x2 - x1;
	dy = y2 - y1;

	for (xax = x1; xax >= x1 && xax <= x2; xax++) {
		xax++;
		yax = y1 + (dy) * (xax - x1)/(dx);

		writePixel(xax,yax);

		if (xax > x2) {
			break;
		}
	}
}
Exemplo n.º 10
0
Arquivo: tga.c Projeto: Starlink/tkimg
static Boln tgaWriteScan (Tcl_Interp *interp, tkimg_MFile *handle,
			  TGAFILE *tf, Int y)
{
    UByte *stop, *red_end, *green_end, *blue_end, *matte_end;
    Int nchan;

    tf->red = tf->redScan;
    tf->green = tf->greenScan;
    tf->blue = tf->blueScan;
    tf->matte = tf->matteScan;
    stop = tf->red + tf->th.xsize;
    nchan = NCHAN (tf->th.pixsize);

    /* Write the scanline data to the file. */
    if (! IS_COMPRESSED (tf->th.imgtyp)) {
	while (tf->red < stop)
	{
	    if (!writePixel (handle, *tf->blue, *tf->green, *tf->red, *tf->matte, nchan))
		return FALSE;
	    tf->blue++;
	    tf->green++;
	    tf->red++;
	    tf->matte++;
	}
    }
    else	/* Run-length Compression */
    {
	red_end = tf->red + 1;
	green_end = tf->green + 1;
	blue_end = tf->blue + 1;
	matte_end = tf->matte + 1;
	while (tf->red < stop)
	{
	    while (red_end < stop &&
		   *tf->red == *red_end &&
		   *tf->green == *green_end &&
		   *tf->blue == *blue_end &&
		   red_end - tf->red - 1 < MAXRUN)
	    {
		if (nchan == 4)
		{
		    if (*tf->matte != *matte_end)
			break;
		}
		red_end++;
		green_end++;
		blue_end++;
		matte_end++;
	    }
	    if (red_end - tf->red >= MINRUN)
	    {	/* Found a run of compressable data */
		if (!writeByte (handle, (Byte)(((red_end - tf->red)-1)|0x80)) ||
		    !writePixel (handle, *tf->blue, *tf->green, *tf->red, *tf->matte, nchan))
		    return FALSE;
		tf->red = red_end;
		tf->green = green_end;
		tf->blue = blue_end;
		tf->matte = matte_end;
	    }
	    else
	    {	/* Found a run of uncompressable data */
		while (red_end < stop &&
		       ((red_end + 1 >= stop ||
			*red_end != *(red_end + 1)) ||
			(red_end + 2 >= stop ||
			*(red_end + 1) != *(red_end + 2))) &&
		       ((green_end + 1 >= stop ||
			*green_end != *(green_end + 1)) ||
			(green_end + 2 >= stop ||
			*(green_end + 1) != *(green_end + 2))) &&
		       ((blue_end + 1 >= stop ||
			*blue_end != *(blue_end + 1)) ||
			(blue_end + 2 >= stop ||
			*(blue_end + 1) != *(blue_end + 2))) &&
			red_end - tf->red < MAXRUN)
		{
		    if (nchan == 4)
		    {
		        if (! ((matte_end + 1 >= stop ||
			       *matte_end != *(matte_end + 1)) ||
			       (matte_end + 2 >= stop ||
			       *(matte_end + 1) != *(matte_end + 2))))
			    break;
		    }
		    red_end++;
		    green_end++;
		    blue_end++;
		    matte_end++;
		}
		if (!writeByte (handle, (Byte)((red_end - tf->red) - 1)))
		    return FALSE;
		while (tf->red < red_end)
		{
		    if (!writePixel (handle, *tf->blue, *tf->green, *tf->red, *tf->matte, nchan))
			return FALSE;
		    tf->red++;
		    tf->green++;
		    tf->blue++;
		    tf->matte++;
		}
	    }
	    red_end++;
	    green_end++;
	    blue_end++;
	    matte_end++;
	}
    }
    return TRUE;
}
Exemplo n.º 11
0
	void writePixel(int x,int y,int r,int g,int b)
	{
		writePixel(x,y,pixel(r,g,b));
	}
Exemplo n.º 12
0
// pixelsNum = 0     : all 4 rows of pixels will be saved.
// pixelsNum = 1/2/3 : residual 1/2/4 rows of pixels will be saved.
void trans_save_4x4(int width, int pixelsNum, uint32_t *src, int src_stride,
                    uint16_t *dst, int dst_stride, int bd) {
  __m128i u[4];
  transClipPixel(src, src_stride, u, bd);
  writePixel(u, width, pixelsNum, dst, dst_stride);
}
Exemplo n.º 13
0
Arquivo: Fe65p2.cpp Projeto: Yarr/Yarr
void Fe65p2::configurePixels() {
    // Set threshold high
    uint16_t tmp1 = getValue(&Fe65p2::Vthin1Dac);
    uint16_t tmp2 = getValue(&Fe65p2::Vthin2Dac);
    uint16_t tmp3 = getValue(&Fe65p2::PreCompVbnDac);
    uint16_t tmp4 = getValue(&Fe65p2::CompVbnDac);
    uint16_t tmp5 = getValue(&Fe65p2::VffDac);
    uint16_t tmp6 = getValue(&Fe65p2::PrmpVbpDac);
    uint16_t tmp7 = getValue(&Fe65p2::PrmpVbnFolDac);
    setValue(&Fe65p2::Vthin1Dac, 255);
    setValue(&Fe65p2::Vthin2Dac, 0);
    //setValue(&Fe65p2::PreCompVbnDac, 0);
    //setValue(&Fe65p2::CompVbnDac, 0);
    setValue(&Fe65p2::VffDac, 10);
    //setValue(&Fe65p2::PrmpVbpDac, 50);
    setValue(&Fe65p2::PrmpVbnFolDac, 0);
    
   
    uint16_t colEn = getValue(&Fe65p2::ColEn);
    uint16_t colSrEn = getValue(&Fe65p2::ColSrEn);
    // Turn all off
    setValue(&Fe65p2::ColSrEn, 0xFFFF);
    setValue(&Fe65p2::ColEn, 0xFFFF);
    configureGlobal();
    writePixel((uint16_t) 0x0);
    setValue(&Fe65p2::PixConfLd, 0x3);
    configureGlobal();
    setValue(&Fe65p2::PixConfLd, 0x0);
    configureGlobal();
    
    // Configure global regs
    //configureGlobal();
    // Configure pixel regs
    for(unsigned i=0; i<Fe65p2Cfg::n_QC; i++) {
        setValue(&Fe65p2::ColSrEn, (0x1<<i));
        setValue(&Fe65p2::OneSr, 0);
        configureGlobal();
        for(unsigned bit=0; bit<Fe65p2Cfg::n_Bits; bit++) {
            writePixel(getCfg(bit, i));
            
            switch (bit) {
                case 0:
                    setValue(&Fe65p2::SignLd, 0x1);
                    break;
                case 1:
                    setValue(&Fe65p2::InjEnLd, 0x1);
                    break;
                case 2:
                    setValue(&Fe65p2::TDacLd, 0x1);
                    break;
                case 3:
                    setValue(&Fe65p2::TDacLd, 0x2);
                    break;
                case 4:
                    setValue(&Fe65p2::TDacLd, 0x4);
                    break;
                case 5:
                    setValue(&Fe65p2::TDacLd, 0x8);
                    break;
                case 6:
                    setValue(&Fe65p2::PixConfLd, 0x1);
                    break;
                case 7:
                    setValue(&Fe65p2::PixConfLd, 0x2);
                    break;
                default:
                    break;
            }

            configureGlobal();

            // Unset Shadow registers
            setValue(&Fe65p2::SignLd, 0x0);
            setValue(&Fe65p2::InjEnLd, 0x0);
            setValue(&Fe65p2::TDacLd, 0x0);
            setValue(&Fe65p2::PixConfLd, 0x0);
            configureGlobal();

            writePixel((uint16_t) 0x0);
        }
    }
    // Reset SR
    writePixel((uint16_t) 0x0);
    // Reset threshold
    setValue(&Fe65p2::Vthin1Dac, tmp1);
    setValue(&Fe65p2::Vthin2Dac, tmp2);
    setValue(&Fe65p2::PreCompVbnDac, tmp3);
    setValue(&Fe65p2::CompVbnDac, tmp4);
    setValue(&Fe65p2::VffDac, tmp5);
    setValue(&Fe65p2::PrmpVbpDac, tmp6);
    setValue(&Fe65p2::PrmpVbnFolDac, tmp7);

    setValue(&Fe65p2::ColSrEn, colSrEn);
    setValue(&Fe65p2::ColEn, colEn);
    configureGlobal();

}
Exemplo n.º 14
0
int cropImage(FILE* inFile, struct bmpFileHeader* fileHead, 
	struct bmpInfoHeader* infoHead, char* outFileName, int cropWidth, 
	int cropHeight, int cropStart[])
{
	// check that cropping parameters make sense
	if (((cropWidth + cropStart[0]) > infoHead->width) || 
		((cropHeight + cropStart[1]) > infoHead->height))
	{
		fprintf(stderr, "Cropping parameters incorrect.\n");
		return EXIT_FAILURE;
	}

	// open file for writing
	FILE *outFile = fopen(outFileName, "w+");

	// check that file opened okay
	if (outFile == NULL)
	{
		fprintf(stderr, "Unable to open file: %s for writing.\n", outFileName);
		return EXIT_FAILURE;
	}

	// store old width/height for use in loop
	LONG oldWidth = infoHead->width;
	LONG oldHeight = infoHead->height;

	// calculate padding used in old image
	int oldPadding = (4 - (oldWidth*sizeof(struct pixel) % 4)) % 4;

	// calculate padding to be used in new image
	int newPadding = (4 - (cropWidth*sizeof(struct pixel) % 4)) % 4;

	// new image size
	infoHead->imageSize = (cropWidth*sizeof(struct pixel) + 
		newPadding)*cropHeight;

	// file size
	fileHead->fileSize = sizeof(struct bmpFileHeader) + 
		sizeof(struct bmpInfoHeader) + infoHead->imageSize;

	// new dimensions
	infoHead->width = cropWidth;
	infoHead->height = cropHeight;

	// write the headers to the output file, checking for errors
	if (writeFileHeader(fileHead, outFile) != 0)
	{
		fprintf(stderr, "Unable to write file header.\n");
		return EXIT_FAILURE;
	}

	if (writeInfoHeader(infoHead, outFile) != 0)
	{
		fprintf(stderr, "Unable to write info header.\n");
		return EXIT_FAILURE;
	}

	// to store pixel being worked on
	struct pixel* curPixel = NULL;

	// run through old pixels, discarding those which are to be cropped
	// and writing the rest to file
	for (int i = 0; i < oldHeight; i++)
	{
		// only run through line if we're out of region to be cropped
		if (!(i < (oldHeight - cropStart[1] - cropHeight) || 
			i > (oldHeight - cropStart[1]))) 
		{
			for (int j = 0; j < oldWidth; j++)
			{
				// only write to file if not in cropped region
				if (!(j < cropStart[0] || j > cropStart[0] + cropWidth))
				{
					// read in the current pixel
					curPixel = getPixel(inFile);

					// make sure read worked
					if (curPixel == NULL)
					{
						fprintf(stderr, "Unable to read pixel.\n");
						return EXIT_FAILURE;
					}

					// write current pixel, checking for error
					if (writePixel(curPixel, outFile) != EXIT_SUCCESS)
					{
						fprintf(stderr, "Unable to write pixel.\n");
						return EXIT_FAILURE;
					}
				}
				else
				{
					// move old file on by a pixel
					fseek(inFile, sizeof(struct pixel), SEEK_CUR);
				}
			}
		}
		else
		{
			// move old file on by width + padding
			fseek(inFile, oldWidth*sizeof(struct pixel) + oldPadding, SEEK_CUR);
		}

		// move old file on by padding
		fseek(inFile, oldPadding, SEEK_CUR);

		// add padding to new file
		for (int k = 0; k < newPadding; k++)
		{
			fputc(0x00, outFile);
		}
	}

	// free memory allocated to current pixel storage
	free(curPixel);

	// close the output file, checking for error
	if (fclose(outFile) != 0)
	{
		fprintf(stderr, "Unable to close output file: %s.\n", outFileName);
		return EXIT_FAILURE;
	}

	// if program gets to here, everything is okay
	return EXIT_SUCCESS;
}