Example #1
0
void Ts206::writeMem(uint8_t address, uint8_t data)
{
	TAKE_CS();
	writeBits(WRITE_MODE, 3);
	writeBits(address, 6);
	writeBits(data, 4);
	RELEASE_CS();
}
Example #2
0
void putParen(uchar b, BITOUT *bitout) {
  if (b == OP) {
    writeBits(bitout, OP, 1);
  }
  else {
    writeBits(bitout, CP, 1);
  }
}
Example #3
0
void Ts206::write(uint8_t address, uint8_t * data, uint8_t cnt)
{
	TAKE_CS();
	writeBits(WRITE_MODE, 3);
	writeBits(address, 6);
	for (uint8_t i = 0; i < cnt; i++) writeBits(data[i], 4);
	RELEASE_CS();
}
Example #4
0
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    maxLevel = 0;
    maxLevel_2 = 0;
    this->setWindowTitle(tr("Kazaryan Paint"));
    scene = new QGraphicsScene(this);
    pixmapItem = scene->addPixmap(QPixmap());
    ui->graphicsView->setScene(scene);
    scene_2 = new QGraphicsScene(this);
    pixmapItem_2 = scene_2->addPixmap(QPixmap());
    ui->graphicsView_2->setScene(scene_2);
    ui->graphicsView->installEventFilter(this);
    ui->graphicsView_2->installEventFilter(this);
    ui->graphicsView_3->installEventFilter(this);
    ui->graphicsView_4->installEventFilter(this);
    //
    sceneHist = new QGraphicsScene(this);
    pixmapItem_3 = sceneHist->addPixmap(QPixmap());
    ui->graphicsView_3->setScene(sceneHist);
    sceneHist_2 = new QGraphicsScene(this);
    pixmapItem_4 = sceneHist_2->addPixmap(QPixmap());
    ui->graphicsView_4->setScene(sceneHist_2);

    mA.assign(64, std::vector<double>(64, 0));
    for (int i = 0; i < 64; ++i)
        for (int j = 0; j < 64; ++j)
        {
            QBitArray b1(8);
            writeBits(i, b1, 0, 7);
            QBitArray b2(8);
            writeBits(j, b2, 0, 7);
            int r = 0;
            for (int k = 0; k < b1.size(); ++k)
                r += (int) (b1[k] ^ b2[k]);
            mA[i][j] = r / 8.0;
        }

    // Connections
    connect(ui->graphicsView->horizontalScrollBar(),
            SIGNAL(valueChanged(int)),
            ui->graphicsView_2->horizontalScrollBar(),
            SLOT(setValue(int)));
    connect(ui->graphicsView_2->horizontalScrollBar(),
            SIGNAL(valueChanged(int)),
            ui->graphicsView->horizontalScrollBar(),
            SLOT(setValue(int)));
    connect(ui->graphicsView->verticalScrollBar(),
            SIGNAL(valueChanged(int)),
            ui->graphicsView_2->verticalScrollBar(),
            SLOT(setValue(int)));
    connect(ui->graphicsView_2->verticalScrollBar(),
            SIGNAL(valueChanged(int)),
            ui->graphicsView->verticalScrollBar(),
            SLOT(setValue(int)));
}
Example #5
0
void Ts206::sendCommand(uint8_t cmd, bool first, bool last)
{
	if (first)
	{
		TAKE_CS();
		writeBits(COMMAND_MODE, 3);
	}
	writeBits(cmd, 8);
	writeBits(0, 1);
	if (last) RELEASE_CS();
}
Example #6
0
void uninitRepair (PROG_INFO *prog_struct, BLOCK_INFO *block_struct) {
  /*
  **  If output was sent to a file, then put an end of file marker
  **  on the prelude file and close both the seq and prel files.
  */
  if (prog_struct -> prel_file != NULL) {
    writeBits (prog_struct -> prel_file, 1, 1, R_FALSE);
    writeBits (prog_struct -> prel_file, 0, 0, R_FALSE);
    writeBits (prog_struct -> prel_file, 0, 0, R_FALSE);
    writeBits (prog_struct -> prel_file, 0, 0, R_TRUE);

    FCLOSE (prog_struct -> seq_file);
    FCLOSE (prog_struct -> prel_file);
    if (prog_struct -> prel_text_file != NULL) {
      FCLOSE (prog_struct -> prel_text_file);
    }

  }
  
#ifdef DEBUG
    fprintf (stderr, "\nOverall Statistics:\n\n");
    fprintf (stderr, "Input filename:  %s\n", prog_struct -> base_filename != NULL ? prog_struct -> base_filename : "N/A");
    fprintf (stderr, "Input file size:  %d\n", prog_struct -> base_filename != NULL ? prog_struct -> in_file_size : 0);
    fprintf (stderr, "Total number of phrases:  %d\n", prog_struct -> total_num_phrases);
    fprintf (stderr, "Total number of blocks:  %d\n", prog_struct -> total_blocks);
    fprintf (stderr, "Total sequence length:  %d\n", prog_struct -> total_num_symbols);
    if (prog_struct -> prel_text_file != NULL) {
      fprintf (stderr, "Average length of phrases:  %f per phrase\n", (R_DOUBLE) prog_struct -> total_sum_phrase_length / (R_DOUBLE) prog_struct -> total_num_phrases);
      fprintf (stderr, "The longest phrases was:\n");
      fprintf (stderr, "\tphrase number:  %d\n", prog_struct -> max_longest_phrase_num);
      fprintf (stderr, "\tblock number:  %d\n", prog_struct -> max_longest_phrase_block);
      fprintf (stderr, "\tphrase length:  %d\n", prog_struct -> max_longest_phrase_length);
    }

    fprintf (stderr, "\nMaximum for one phrase hierarchy:\n");
    fprintf (stderr, "\tNumber of primitives and phrases:  %d\n", prog_struct -> maximum_total_num_phrases);
    fprintf (stderr, "\tGeneration:  %d\n", prog_struct -> maximum_generations + 1);
                                   /*  Add 1 since generation is 0-based  */
    fprintf (stderr, "\tNumber of primitives:  %d\n", prog_struct -> maximum_primitives);
#endif

  /*  Must add 1 to maximum_generations since it is 0-based  */
  if (prog_struct -> verbose_level == R_TRUE) {
    fprintf (stderr, "-------------------------------------------------------------------------\n");
    fprintf (stderr, "%5u\t%5u\t%7u\t  %15u\t%11u\t%7u\n", prog_struct -> total_blocks, prog_struct -> total_num_prims, prog_struct -> total_num_phrases, prog_struct -> total_num_prims + prog_struct -> total_num_phrases, prog_struct -> maximum_generations + 1, prog_struct -> total_num_symbols);
  }

  wfree (prog_struct -> seq_nodelist);
  wfree (prog_struct -> progname);
  wfree (prog_struct -> base_filename);

  return;
}
Example #7
0
static void send(uint8_t value, uint8_t mode) {
	GPIO_WriteBit(Lcd_Conf.gpio, Lcd_Conf.rs, mode);

    if(Lcd_Conf.rw != 255)
        GPIO_ResetBits(Lcd_Conf.gpio, Lcd_Conf.rw);

    if(Lcd_Conf.dispFunc & LCD_8BITMODE) {
        writeBits(value, 8);
    } else {
        writeBits(value >> 4, 4);
        writeBits(value, 4);
    }
}
Example #8
0
int _colenc(struct BITSTREAM *bs, int n, const double *store, int col, double scale, int Ml2)
{
#if 0
  double h[2];
  double emax = 0.0;
#endif
  int i;
  int nbits = bufferSize(bs);
  struct DELTACODE dc;

  writeManyBits(bs, (int)scale, 32);
  writeBits(bs, Ml2, 8);

#if 1
  initDeltaCode(&dc, scale, Ml2);
  for (i=0; i<n; i++) {
    deltaEncode(&dc, bs, store[6*i+col]);
  }
#else
  h[0] = h[1] = 0 ;
  for (i=0; i<n; i++) {
    double p = 2.0*h[0]-h[1];
    double d = floor(0.5+scale*(store[6*i+col]-p));
    double e = fabs(p+d/scale-store[6*i+col]);
    printf("p = %1.16lf, writ d=%1.0lf, Ml2=%d\n",p,d,Ml2);
    grsCode(bs, d, Ml2);
    h[1] = h[0];
    h[0] = p+d/scale;
    if (e>emax) emax = e;
  }
  printf("emax = %le\n",emax);
#endif
  return bufferSize(bs) - nbits;
}
int writeEXIHeader(bitstream_t* stream) {
	/* init stream */
	stream->buffer = 0;
	stream->capacity = 8;

	return writeBits(stream, 8, 128);
}
Example #10
0
I2C_RESULT I2CDev::writeBit(uint8_t devAddr, uint8_t regAddr, uint8_t bitPos, uint8_t level)
{
	uint8_t bitMask = 0;
	if (level)
		bitMask = 1<<bitPos;
	
	return writeBits(devAddr, regAddr, bitMask);
}
Example #11
0
void LCD_Begin(uint8_t rows, uint8_t cols, uint8_t dotSize) {
    if(rows > 1)
        Lcd_Conf.dispFunc |= LCD_2LINE;

    if((dotSize != 0) && (rows == 1))
        Lcd_Conf.dispFunc |= LCD_5x10DOTS;

    delayMicroseconds(50000);

    GPIO_ResetBits(Lcd_Conf.gpio, Lcd_Conf.rs);
    GPIO_ResetBits(Lcd_Conf.gpio, Lcd_Conf.enable);

    if(Lcd_Conf.rw != 255)
        GPIO_ResetBits(Lcd_Conf.gpio, Lcd_Conf.rw);

    if(!(Lcd_Conf.dispFunc & LCD_8BITMODE)) {
        writeBits(0x03, 4);
        delayMicroseconds(4500);

        writeBits(0x03, 4);
        delayMicroseconds(4500);

        writeBits(0x03, 4);
        delayMicroseconds(150);

        writeBits(0x02, 4);
    } else {
        send(LCD_FUNCTIONSET | Lcd_Conf.dispFunc, LOW);
        delayMicroseconds(4500);

        send(LCD_FUNCTIONSET | Lcd_Conf.dispFunc, LOW);
        delayMicroseconds(150);

        send(LCD_FUNCTIONSET | Lcd_Conf.dispFunc, LOW);
    }

    send(LCD_FUNCTIONSET | Lcd_Conf.dispFunc, LOW);

    Lcd_Conf.dispCtrl = LCD_DISPLAYON | LCD_CURSOROFF | LCD_BLINKOFF;
    LCD_display();
    LCD_clear();

    Lcd_Conf.dispMode = LCD_ENTRYLEFT | LCD_ENTRYSHIFTDECREMENT;

    send(LCD_ENTRYMODESET | Lcd_Conf.dispMode, LOW);
}
Example #12
0
I2C_RESULT I2CDev::writeBits(uint8_t devAddr, uint8_t regAddr, uint8_t bitStart, uint8_t bitLengh, uint8_t data)
{
	uint8_t bitMask = 1<<bitStart;
	uint8_t i = 0;
	while(i < bitLengh - bitStart + 1)
	{
		bitMask |= ((bitStart << i++) | data);
	}
	
	return writeBits(devAddr, regAddr, bitMask);
}
Example #13
0
static
void outputCompTxtVar(DICT *dict, FILE *output) 
{
  uint i, j;
  RULE *rule;
  BITOUT *bitout;

  bitout = createBitout(output);
  for (i = 0; i < dict->num_contexts; i++) {
    rule = dict->rule[i];
    for (j = dict->char_size; j < rule->num_rules; j++) {
      writeBits(bitout, rule->left[j],  dict->code_len);
      writeBits(bitout, rule->right[j], dict->code_len);
    }
  }
  for (i = 0; i < dict->seq_len; i++) {
    writeBits(bitout, dict->comp_seq[i], dict->code_len);
  }
  flushBitout(bitout);
  destructBitout(bitout);
}
Example #14
0
std::vector<int> MainWindow::colHist(QPixmap &pixmap)
{
    std::vector<int> res(64, 0);
    QImage img = pixmap.toImage();

    for (int y = 0; y < img.height(); ++y)
    {
        for (int x = 0; x < img.width(); ++x)
        {
            QRgb pixel = img.pixel(x, y);
            QBitArray bArr(3 * 8);
            writeBits(qRed(pixel), bArr, 0, 7);
            writeBits(qGreen(pixel), bArr, 8, 15);
            writeBits(qBlue(pixel), bArr, 16, 23);
            int i = (int) bArr[6] + (int) bArr[7] * 2 + (int) bArr[14] * 4
                  + (int) bArr[15] * 8 + (int) bArr[22] * 16 + (int) bArr[23] * 32;
            ++res[i];
        }
    }

    return res;
}
Example #15
0
int salvarArbolHuffman(struct nodo *raiz, BYTE *mem)
{
	static int pos_mem, pos_pos;


	if (raiz != NULL)
	{
		if (raiz->hizq == NULL)   // Hoja
		{
			writeBits(mem, &pos_mem, &pos_pos, UNO, 1);
			writeBits(mem, &pos_mem, &pos_pos, raiz->c, 8);
		}
		else	// NO hoja
		{
			writeBits(mem, &pos_mem, &pos_pos, 0, 1);
			salvarArbolHuffman(raiz->hizq, mem);
			salvarArbolHuffman(raiz->hdch, mem);
		}
	}

	return pos_mem;
}
Example #16
0
int main(int ac, char *av[])
{
  //  int i;
  int bits ;
  int totbits = 0 ;
  int n = readfile(av[1]);
  //  int Ml2 = atoi(av[3]);
  struct BITSTREAM bs ; 

  printf("%d values\n",n);

  resetBits(&bs);
  // encode header

  // NEMC
  writeBits(&bs, 'N',8);writeBits(&bs, 'M',8);writeBits(&bs, 'E',8);writeBits(&bs, 'C',8);
  writeBits(&bs, '0',8); // version 0

  // number of lines
  writeBits(&bs, n,32);

  // encode time

//	bits = timeenc(&bs, n, store);
  bits = colenc(&bs, n, store, 0, 1); // ,1
  printf("%d bits for time/date encoding (%f per line)\n",bits,(float)bits/n);

  bits =  colenc(&bs, n, store, 1, 1E7); // , Ml2);
  bits += colenc(&bs, n, store, 2, 1E7);//, Ml2);
  bits += colenc(&bs, n, store, 3, 1E7);//, Ml2);
  
  printf("%d bits for position encoding (%f per line)\n",bits,(float)bits/n);
  
  bits = colenc(&bs, n, store, 5, 5);//, Ml2);
  printf("%d bits for depth encoding (%f per line)\n",bits,(float)bits/n);
  
  flushBits(&bs);
  
  totbits = (bs.bp - bs.bitstream)*8;
  printf("real  size: %d bytes (%1.1f bits per line)\n",totbits/8,(float)totbits/n);
  
  {
    FILE *f = fopen(av[2],"wb");
    if (!f) {fprintf(stderr,"could not open file %s\n",av[2]);exit(20);}
    
    fwrite(bs.bitstream,bs.bp - bs.bitstream,1,f);
    fclose(f);
  }
  return 0;
}
Example #17
0
int writeFile (char* filename, int rows, int cols, PIXEL* bitmap) 
{
  int fd, ret;
  unsigned int start = DEFAULT_BITMAP_OFFSET;

  if(filename) {
    if((fd = open(filename, O_RDWR|O_CREAT|O_TRUNC, 0666)) < 0) {
      perror("Can't open bmp file to write");
      return -1;
    }
  } else fd = STDOUT_FILENO;

  ret = writeHeader (fd, rows, cols, start);
  if(ret) return ret;

  ret = writeBits(fd, rows, cols, bitmap, start);
  if(ret) return ret;

  if(filename) close(fd);

  return 0;
}
Example #18
0
int main( void )
{
   int const fd = open( "/dev/usb/lp0", O_RDWR );
   if( 0 <= fd )
   {
      printf( "printer port opened\n" );
      SENDCOMMAND( initPrinter );
      SENDCOMMAND( rasterMode );
      SENDCOMMAND( letterQuality );

      // set page height
      pprintf( fd, "\x01b*rP%d", PAGEHEIGHT );
      write( fd, "\x00", 1 );

      SENDCOMMAND( clearImage );

      SENDCOMMAND( leftMargin );
      SENDCOMMAND( rightMargin );
      
      unsigned char rasterData[WIDTHBYTES];

      for( unsigned i = 0 ; i < PAGEHEIGHT ; i++ )
      {
         memset( rasterData, i, sizeof( rasterData ) );
         writeBits( fd, rasterData, sizeof( rasterData ) );
      }

      SENDCOMMAND( formFeed );
      SENDCOMMAND( exitRaster );

      // 
      // read response (status)
      //
      char prevIn[80];
      int  numPrev = 0 ;
      char inBuf[80];
      int  numRead ;
      unsigned sameCount = 0 ;

      while( 0 < ( numRead = read( fd, inBuf, sizeof( inBuf )-1 ) ) )
      {
         if( ( numRead != numPrev ) || ( 0 != memcmp( inBuf, prevIn, numRead ) ) )
         {
            printf( "read %u bytes\n", numRead );
            for( unsigned i = 0 ; i < numRead ; i++ )
               printf( "%02x ", inBuf[i] );
            printf( "\n" );
            numPrev = numRead ;
            memcpy( prevIn, inBuf, numRead );
            sameCount = 0 ;
         } // change in status
         else
         {
            printf( "%u\r", ++sameCount );    // same data as before
            if( 7 == ( sameCount & 7 ) )
               write( fd, "\x04", 1 ); // EOT command
         }
      }

      perror( "read" );

      close( fd );
      printf( "printer port closed\n" );
   }
   else
      perror( "/dev/usb/lp0" );
   
   return 0 ;
}
Example #19
0
BYTE comprimir(FILE *fpin, FILE *fpout, struct tablaCod *tabla, int verbose)
/*
 * Codifica cada caracter del fichero usando la
 * tabla de codificacion creada a partir del
 * arbol de Huffman
 */
{
	BYTE buf_lec[BUF_SZ], buf_esc[BUF_SZ+1], padding;
	int pos_buf_esc=0, pos_pos=0, i, j, nbytes;
	struct tablaCod *entry;
	float completado=0.0F, inc;
	struct stat statbuf;


	if (verbose)
	{
		fstat(fileno(fpin), &statbuf);
		inc = (BUF_SZ*100.0F) / statbuf.st_size;
		if (inc > 100.0F)
			inc=100.0F;

		printf("Compressing... 0%%");
	}

	rewind(fpin);
	memset(buf_esc, 0, BUF_SZ+1);

	for (;;)
	{
		nbytes=fread(buf_lec, 1, BUF_SZ, fpin);
		if (ferror(fpin))
		{
			perror("fread: comprimir()");
			exit(1);
		}

		for (i=0; i < nbytes; i++)
		{
			entry=getEntry(tabla, buf_lec[i]);
			for (j=0; j < entry->len; j++)
			{
				writeBits(buf_esc, &pos_buf_esc, &pos_pos, entry->cod[j], 1);
				if (pos_buf_esc == BUF_SZ)
				{
					fwrite(buf_esc, 1, BUF_SZ, fpout);
					if (ferror(fpout))
					{
						perror("fwrite: comprimir()");
						exit(1);
					}

					buf_esc[0]=buf_esc[BUF_SZ];
					memset(buf_esc+1, 0, BUF_SZ);
					pos_buf_esc=0;
				}
			}
		}

		if (verbose)
		{
			if ((int)completado == 100)
				printf("\b\b");
			else if ((int)completado >= 10)
				printf("\b");

			completado+=inc;
			if ((int)completado > 100)
				completado=100.0F;
			printf("\b\b%d%%", (int)completado);
		}

		if (feof(fpin))
		{
			padding=(8-pos_pos) % 8;
			if (padding != 0 || pos_buf_esc != 0)
			{
				fwrite(buf_esc, 1, padding == 0 ? pos_buf_esc : pos_buf_esc+1, fpout);
				if (ferror(fpout))
				{
					perror("fwrite: comprimir()");
					exit(1);
				}
			}

			if (verbose && (int)completado < 100)
				printf("\b\b\b100%%");

			break;	// Salimos del for(;;)
		}
	}

	return padding;
}
Example #20
0
/** Set full-scale accelerometer range.
 * @param range New full-scale accelerometer range setting
 * @see getFullScaleAccelRange()
 */
PUBLIC void setFullScaleAccelRange(uint8 range) {
	writeBits(LSM6DS0_ADDRESS, CTRL_REG6_XL, LSM6DS0_ACCEL_FS_SEL_BIT, LSM6DS0_ACCEL_FS_SEL_LENGTH, range);
	vWaitMicroseconds(500);
}
Example #21
0
/** Set full-scale gyroscope range.
 * @param range New full-scale gyroscope range value
 * @see getFullScaleRange()
 * @see MPU6050_GYRO_FS_250
 * @see MPU6050_RA_GYRO_CONFIG
 * @see MPU6050_GCONFIG_FS_SEL_BIT
 * @see MPU6050_GCONFIG_FS_SEL_LENGTH
 */
PUBLIC void setFullScaleGyroRange(uint8 range) {
	writeBits(LSM6DS0_ADDRESS, CTRL_REG1_G, LSM6DS0_GYRO_FS_SEL_BIT, LSM6DS0_GYRO_FS_SEL_LENGTH, range);
	vWaitMicroseconds(500);
}
Example #22
0
PUBLIC void setGyroODR(uint8 rate) {
	writeBits(LSM6DS0_ADDRESS, CTRL_REG1_G, LSM6DS0_GYRO_ODR_SEL_BIT, LSM6DS0_GYRO_ODR_SEL_LENGTH, rate);
	vWaitMicroseconds(500);
}
Example #23
0
int main(int argc, char **argv)
{
    mpc_reader reader;
    mpc_demux* demux;
    mpc_streaminfo si;
    mpc_encoder_t e;
    unsigned char buffer[16];
    mpc_bits_reader r;
    mpc_block b;
    mpc_uint64_t size;
    mpc_status err;
    mpc_int64_t start_sample = 0, end_sample = 0;
    mpc_uint32_t beg_silence, start_block, block_num, i;
    int c;
    FILE * in_file;

    printf(About);

    while ((c = getopt(argc , argv, "s:e:")) != -1) {
        switch (c) {
        case 's':
            start_sample = atoll(optarg);
            break;
        case 'e':
            end_sample = atoll(optarg);
            break;
        }
    }

    if(argc - optind != 2)
    {
        usage(argv[0]);
        return 0;
    }

    err = mpc_reader_init_stdio(&reader, argv[optind]);
    if(err < 0) return !MPC_STATUS_OK;

    demux = mpc_demux_init(&reader);
    if(!demux) return !MPC_STATUS_OK;
    mpc_demux_get_info(demux,  &si);

    if (si.stream_version < 8) {
        fprintf(stderr, "this file cannot be edited, please convert it first to sv8 using mpc2sv8\n");
        exit(!MPC_STATUS_OK);
    }

    if (end_sample == 0)
        end_sample = si.samples;
    else
        end_sample += si.beg_silence;
    start_sample += si.beg_silence;

    if (start_sample < 0 || end_sample > si.samples || end_sample <= start_sample) {
        fprintf(stderr, "specified samples bounds out of stream bounds\n");
        exit(!MPC_STATUS_OK);
    }

    beg_silence = start_sample % (MPC_FRAME_LENGTH << si.block_pwr);
    start_block = start_sample / (MPC_FRAME_LENGTH << si.block_pwr);
    block_num = (end_sample + (MPC_FRAME_LENGTH << si.block_pwr) - 1) /
                (MPC_FRAME_LENGTH << si.block_pwr) - start_block;
    end_sample -= start_block * (MPC_FRAME_LENGTH << si.block_pwr);

    mpc_encoder_init(&e, end_sample, si.block_pwr, 1);
    e.outputFile = fopen( argv[optind + 1], "rb" );
    if ( e.outputFile != 0 ) {
        fprintf(stderr, "Error : output file \"%s\" already exists\n", argv[optind + 1]);
        exit(MPC_STATUS_FAIL);
    }
    e.outputFile = fopen( argv[optind + 1], "w+b" );

    e.seek_ref = 0;
    writeMagic(&e);
    writeStreamInfo( &e, si.max_band, si.ms > 0, end_sample, beg_silence,
                     si.sample_freq, si.channels);
    writeBlock(&e, "SH", MPC_TRUE, 0);
    writeGainInfo(&e, 0, 0, 0, 0);
    writeBlock(&e, "RG", MPC_FALSE, 0);


    in_file = fopen(argv[optind], "rb");
    i = si.header_position + 4;
    fseek(in_file, i, SEEK_SET);
    fread(buffer, 1, 16, in_file);
    r.buff = buffer;
    r.count = 8;
    size = mpc_bits_get_block(&r, &b);

    while( memcmp(b.key, "AP", 2) != 0 ) {
        if ((err = mpc_check_key(b.key)) != MPC_STATUS_OK) {
            fprintf(stderr, "Error : invalid input stream\n");
            goto error;
        }
        if (memcmp(b.key, "EI", 2) == 0)
            copy_data(in_file, i, e.outputFile, b.size + size);
        i += b.size + size;
        fseek(in_file, i, SEEK_SET);
        fread(buffer, 1, 16, in_file);
        r.buff = buffer;
        r.count = 8;
        size = mpc_bits_get_block(&r, &b);
    }

    e.seek_ptr = ftell(e.outputFile);
    writeBits (&e, 0, 16);
    writeBits (&e, 0, 24); // jump 40 bits for seek table pointer
    writeBlock(&e, "SO", MPC_FALSE, 0); // reserve space for seek offset


    while( start_block != 0 ) {
        if ((err = mpc_check_key(b.key)) != MPC_STATUS_OK) {
            fprintf(stderr, "Error : invalid input stream\n");
            goto error;
        }
        if (memcmp(b.key, "AP", 2) == 0)
            start_block--;
        i += b.size + size;
        fseek(in_file, i, SEEK_SET);
        fread(buffer, 1, 16, in_file);
        r.buff = buffer;
        r.count = 8;
        size = mpc_bits_get_block(&r, &b);
    }

    while( block_num != 0 ) {
        if ((err = mpc_check_key(b.key)) != MPC_STATUS_OK) {
            fprintf(stderr, "Error : invalid input stream\n");
            goto error;
        }
        if (memcmp(b.key, "AP", 2) == 0) {
            if ((e.block_cnt & ((1 << e.seek_pwr) - 1)) == 0) {
                e.seek_table[e.seek_pos] = ftell(e.outputFile);
                e.seek_pos++;
            }
            e.block_cnt++;
            copy_data(in_file, i, e.outputFile, b.size + size);
            block_num--;
        }
        i += b.size + size;
        fseek(in_file, i, SEEK_SET);
        fread(buffer, 1, 16, in_file);
        r.buff = buffer;
        r.count = 8;
        size = mpc_bits_get_block(&r, &b);
    }

    writeSeekTable(&e);
    writeBlock(&e, "ST", MPC_FALSE, 0); // write seek table block
    writeBlock(&e, "SE", MPC_FALSE, 0); // write end of stream block

error:
    fclose ( e.outputFile );
    fclose ( in_file );
    mpc_demux_exit(demux);
    mpc_reader_exit_stdio(&reader);
    mpc_encoder_exit(&e);
    if (err != MPC_STATUS_OK)
        remove(argv[optind + 1]);

    return err;
}
Example #24
0
void putLeaf(uint numcode, uint lvcode, BITOUT *bitout) {
  uint bitslen = bits(numcode);
  writeBits(bitout, lvcode, bitslen);
}