Ejemplo n.º 1
0
static void
copy_pixel_row(const JSAMPROW jpegbuffer, const int width, 
               const unsigned int samples_per_pixel, 
               const enum colorspace color_space,
               const unsigned int maxval,
               FILE * const output_file, const int output_type) {
  JSAMPLE *ptr;
  unsigned int output_cursor;     /* Cursor into output buffer 'pnmbuffer' */

  ptr = jpegbuffer;  /* Start at beginning of input row */

  for (output_cursor = 0; output_cursor < width; output_cursor++) {
      xel current_pixel;
      if (samples_per_pixel >= 3) {
          const rgb_type * const rgb_p = read_rgb(ptr, color_space, maxval);
          PPM_ASSIGN(current_pixel, rgb_p->r, rgb_p->g, rgb_p->b);
      } else {
          PNM_ASSIGN1(current_pixel, GETJSAMPLE(*ptr));
      }
      ptr += samples_per_pixel;  /* move to next pixel of input */
      pnmbuffer[output_cursor] = current_pixel;
  }
  pnm_writepnmrow(output_file, pnmbuffer, width,
                  maxval, output_type, FALSE);
}
Ejemplo n.º 2
0
static void
copyPixelRow(JSAMPROW        const jpegbuffer,
             unsigned int    const width, 
             unsigned int    const samplesPerPixel, 
             enum colorspace const colorSpace,
             FILE *          const ofP,
             int             const format,
             xelval          const maxval) {

    JSAMPLE * ptr;
    unsigned int outputCursor;     /* Cursor into output buffer 'pnmbuffer' */

    ptr = &jpegbuffer[0];  /* Start at beginning of input row */
    
    for (outputCursor = 0; outputCursor < width; ++outputCursor) {
        xel currentPixel;
        if (samplesPerPixel >= 3) {
            const rgb_type * const rgb_p = read_rgb(ptr, colorSpace, maxval);
            PPM_ASSIGN(currentPixel, rgb_p->r, rgb_p->g, rgb_p->b);
        } else {
            PNM_ASSIGN1(currentPixel, GETJSAMPLE(*ptr));
        }
        ptr += samplesPerPixel;  /* move to next pixel of input */
        pnmbuffer[outputCursor] = currentPixel;
    }
    pnm_writepnmrow(ofP, pnmbuffer, width, maxval, format, FALSE);
}
Ejemplo n.º 3
0
bool Image_TIFF::load_tiff(char * fname)
{
  tiff_handle = TIFFOpen(fname, "r");
  TIFFGetField(tiff_handle, TIFFTAG_IMAGEWIDTH, &_width);
  TIFFGetField(tiff_handle, TIFFTAG_IMAGELENGTH, &_height);
  _size = _width * _height;
  TIFFGetField(tiff_handle, TIFFTAG_BITSPERSAMPLE, &_depth);
  TIFFGetField(tiff_handle, TIFFTAG_SAMPLESPERPIXEL, &_comps);  
  TIFFGetField(tiff_handle, TIFFTAG_FILLORDER, &_order);
  TIFFGetField(tiff_handle, TIFFTAG_PLANARCONFIG, &_config);
  if (_comps <= 0 || _comps > 4) return false;
  if (_comps == 1) // gray scale data
    {
      init_gs();
      read_gs();
    }
  else if (_comps == 3)
    {
      init_rgb();
      read_rgb();
    }
  else
    {
      printf("..tiff found %d-samples per pixel (not supported) abort.\n", _comps);
      clear_gs();
      clear_rgb();
      return false;
    }
  printf("..libtiff loaded [%dx%d], depth(%d), comps(%d) image\n",_width, _height, _depth, _comps);
  return true;
}
Ejemplo n.º 4
0
static void		bmpload_pixel(t_bmpfile *bmp, unsigned char *oct)
{
	unsigned int i;

	i = -1;
	while (++i < bmp->bmp.width * bmp->bmp.height)
	{
		bmp->pixels[i] = read_rgb(oct + bmp->header.offset + i * 3);
	}
}
Ejemplo n.º 5
0
	void	rgba::read(stream* in, int tag_type)
	{
		if (tag_type <= 22)
		{
			read_rgb(in);
		}
		else
		{
			read_rgba(in);
		}
	}
Ejemplo n.º 6
0
int main(void)
{
    int result = -1;
	int Red=0,Green=0,Blue=0;
    result = init_rgb();
    if (result > 0)
    {
      while (1)
      {
      int value = -1;
      value = read_rgb(&Red,&Green,&Blue);
      printf(" Red : %d , Green = %d , Blue = %d\n",Red,Green,Blue);
      usleep( 100 * 1000 ); 
      }
    }
}
Ejemplo n.º 7
0
	void	rgba::read_rgba(stream* in)
	{
		read_rgb(in);
		m_a = in->read_u8();
	}
Ejemplo n.º 8
0
// read one stroke from file stream
// if successed,return the file position after reading one stroke
// else return -1
// pay attention to call this function,
// we should guarantee file position should stop at the beginning of stroke 
long read_stroke (FILE * file, PtrStroke stroke)
{
    int i;
    PtrInkPoint point;

    if (file == NULL || stroke == NULL)
    {
        SB_INKERRPRINTF("failed:incorrect arguments\n");
        return -1;
    }

    if ( !read_integer(&(stroke->iPenSize), file) )
    {
        SB_INKPRINTF("failed getting stroke->iPenSize\n");
        return -1;
    }
  //read rgb
    if ( !read_rgb(&stroke->gdkColor,file) )
    {
        SB_INKERRPRINTF("failed write rgb\n");
        return 0;
    }

    if ( !read_integer(&(stroke->nPoints), file) )
    {
        SB_INKERRPRINTF("failed getting stroke->nPoints\n");
        return -1;
    }

    SB_INKPRINTF("npoints=%d,ipensize=%d\n",
            stroke->nPoints,stroke->iPenSize);

    if ( stroke->nPoints == 0)
    {
        SB_INKPRINTF("returned because of stroke->nPoints=0\n");
        return ftell (file);//lPos
    }

    //stroke->nPoints will be changed in iteration,so we should keep it.
    int nTotalPoints=stroke->nPoints;
    for (i = 0; i < nTotalPoints; i++)
    {
        point = construct_point ();
        if ( NULL==point )
        { 
            SB_INKERRPRINTF("construct point error\n");
            return -1;
        }
        if ( !read_integer (&(point->x), file) )
        {
            SB_INKERRPRINTF("failed getting (point%d->x)\n",i);
            return -1;
        }
        if ( !read_integer (&(point->y), file) )
        {
            SB_INKERRPRINTF("failed getting (point%d->y)\n",i);
            return -1;
        }
	    //SB_INKPRINTF("point(%d,%d) \n", point->x, point->y);
        ink_add_point(stroke, point);
    }
    return ftell (file);//current file pointer position
}
Ejemplo n.º 9
0
      void read( string fn, tImgLinear& rimg ) {


         std::vector<uint8_t> buf;

         bin_read::t_bin_read reader;
         reader( fn, buf );


         FILEHEADER const* fileheader = referenceToFILEHEADER( buf );
         uint16_t sig = fileheader->signature;


         if( sig != BMP_signature ) {
            return ;
         }

         if( buf.size() == fileheader->size ) {
            try {
               INFO const* bitmapinfoheader = referenceToINFO( buf );
               uint32_t w = info_width( bitmapinfoheader );
               uint32_t h = info_height( bitmapinfoheader );
               // copy data to tImgLinear
               rimg.size() = tSize( w, h );

               uint8_t const* pbuf = &buf[0];
               uint8_t const* dataptr = pbuf + fileheader->offset_bits;


               // 8 bit
               if( bitmapinfoheader->bit_count == 8 ) {
                  // LUT is not supported, convert to rgb, if lut is not an gray ramp lut
                  tBGRA const* lut = referenceToLUT( buf );

                  if( is_ramp( lut ) ) {
                     rimg.set_mono8();
                     rimg.alloc_data_buffer();
                     read_8bit( dataptr, rimg.size(), rimg.rows() );
                     return;
                  }

                  if( is_zero( lut ) ) {
                     rimg.set_mono8();
                     rimg.alloc_data_buffer();
                     read_8bit( dataptr, rimg.size(), rimg.rows() );
                     return;
                  }

                  rimg.set_rgb();
                  rimg.alloc_data_buffer();
                  read_8bit_as_rgb( lut, dataptr, rimg.size(), rimg.rows() );
                  return;
               }

               // 24 bit
               if( bitmapinfoheader->bit_count == 24 ) {
                  rimg.set_rgb();
                  rimg.alloc_data_buffer();
                  read_rgb( dataptr, rimg.size(), rimg.rows() );
               }

               if( bitmapinfoheader->bit_count == 32 ) {
                  // read an rgba image, write an rgb image, alpha is lost
                  rimg.set_rgba();
                  rimg.alloc_data_buffer();
                  read_rgba( dataptr, rimg.size(), rimg.rows() );
               }



            } catch( tImgAllocEx& ex ) {
               throw tImgReadEx( ex.what() );
            }

         }
      }