Пример #1
0
// ****************************************************************************
//  Method: avtImgCommunicator::rleEncodeAll
//
//  Purpose:
//    Encodes an image using RLE: Runlength, R, G, B, A
//
//  Arguments:
//    dimsX & dimsY : width & height of the image
//    imgArray    : array containing all the division composited by this processor
//    numDivs     : number of Z divisions
//
//    encoding      : the image compressed using RLE; it's a float so that it can be sent directly using MPI
//    sizeOfEncoding  : the compressed size of each image
//
//
//  Programmer: Pascal Grosset
//  Creation: August 23, 2013
//
//  Modifications:
//
// ****************************************************************************
int avtImgCommunicator::rleEncodeAll(int dimsX, int dimsY, int numDivs, float *imgArray,  float *& encoding, int *& sizeOfEncoding){
  std::vector<code> encodingVec;
  encodingVec.clear();
  code tempCode;
  sizeOfEncoding = new int[numDivs];
  int prev = 0;

  // Compress the data
  for (int j=0; j<numDivs; j++){
    int offset = dimsX*dimsY*4  *  j; // to get the next image in the array of images

    int i=0;
    tempCode = initCode(1, imgArray[offset + (i*4+0)],imgArray[offset + (i*4+1)],imgArray[offset + (i*4+2)],  imgArray[offset + (i*4+3)]);
    for (i=1; i<dimsX*dimsY; i++){
      if ( compareColor(tempCode, imgArray[offset + (i*4+0)],imgArray[offset + (i*4+1)],imgArray[offset + (i*4+2)],imgArray[offset + (i*4+3)]) )
        tempCode = incrCode(tempCode);
      else{
        encodingVec.push_back(tempCode);
        tempCode = initCode(1, imgArray[offset + (i*4+0)],imgArray[offset + (i*4+1)],imgArray[offset + (i*4+2)],imgArray[offset + (i*4+3)]);
      }
    }
    encodingVec.push_back(tempCode);

    if (j == 0)
      prev = sizeOfEncoding[j] = encodingVec.size();
    else{
      sizeOfEncoding[j] = encodingVec.size() - prev;
      prev = encodingVec.size();
    }

    debug5 <<  my_id << "  ~  encoding.size(): " << sizeOfEncoding[j] << "   offset: " << offset << "    original size: " << (dimsX * dimsY * 4) << "   size: " << encodingVec.size() << std::endl;
  }


  // Transfer the data to the encoding array
  int encSize = encodingVec.size();
  encoding = new float[encSize*5];
  
  int index = 0;
  for (int j=0; j<encSize; j++){
    encoding[index] = encodingVec[j].count; index++;
    encoding[index] = encodingVec[j].color[0];  index++;
    encoding[index] = encodingVec[j].color[1];  index++;
    encoding[index] = encodingVec[j].color[2];  index++;
    encoding[index] = encodingVec[j].color[3];  index++;  
  }
  encodingVec.clear();

  return encSize;   // size of the array
}
Пример #2
0
RussianKeyboardLayout::RussianKeyboardLayout()
: KeyboardLayout()
{
    initCode();
    initShiftMap();
    initSpecialMaps();
    initKeys();
}
Пример #3
0
int main(int n, char **argv){

	stamp codes[256];

	unsigned long int total_chars = 0, octets_ecrits = 0;
	unsigned char buff[3];
	
	FILE* file_input, *file_output;

	int ver = 0, ver_pos2 = 8; 

	if(n >= 2){ 
//////////////////////////////////////////////////////////////////////////////////////////////////////////// DECODAGE
			printf("\n\nBienvenue au Huffman Code v.%d.%d\n\nInitialisation du mode DEcodage.\n\n\n", ver, ver_pos2);
			
			if(file_input = fopen(argv[1], "r")){
	
				initCode(codes, 256);
				
				// calcule la taille du fichier...
				while(fread(buff, sizeof(char), 1, file_input) > 0){ total_chars++; }; rewind(file_input);
				
				printf("\nInitialisation des codes.... ");
				lireHeader(file_input, codes);
				printTCodes(codes);
				
				printf("\nDecodage....\n"); fflush(stdout);
				
				if(n>=3){
					
					if(file_output = fopen(argv[2], "w")){
					
						octets_ecrits += decode(file_input, file_output, codes, total_chars, 0);
						printf("\nOK\n\nTaille de fichier decode (%s): %d bytes (%f %%)\n\n", argv[2], (int)octets_ecrits, (octets_ecrits/(float)total_chars)*100);
						fclose(file_output);
					}else{
						printf("On n'a pas pu creer un fichier '%s'\n", argv[2]);
					}
				}else{
				
					octets_ecrits += decode(file_input, file_output, codes, total_chars, 1);
					printf("\nOK\n\nTaille de output: %d bytes (%f %%)\n\n", (int)octets_ecrits, (octets_ecrits/(float)total_chars)*100);
				}
			}else{
				printf("\nError. Le fichier '%s' ne peut pas etre ouvert.\n", argv[1]);
			}
//////////////////////////////////////////////////////////////////////////////////////////////////////////// DECODAGE - FIN
	}else{
		
		printf("Utilisation: %s <fichier source> [<fichier destination>]\n\n", argv[0]);
	}
	return 0;
}
Пример #4
0
/* *************************************************************** */
int main(int argc, char * argv[]) {  
	initCode();
	int i=1;   
	int isEncode = 1;   
	PBLOC pbloc, pPrevLINK;   
	PNOEUD  pNoeud,pNext;  
	srcFile = fopen(argv[1],"r"); 
	if (srcFile==NULL) {   
		printf("Il faut entrer le nom de fichier source ! \n");   
		exit(1);   
	}
    srcFileNO = fileno(srcFile);   
    rewind(srcFile);   /* mettre le pointeur au debut du fichier */
    
    strcpy(nomS,"CODE_SORTIE_DECOMP_");
    strcat(nomS,argv[1]);
    if ((destFile = fopen(nomS,"w"))==NULL) {   
        printf("Erreur : fopen destFile ! \n");   
        exit(1);   
    }   
    destFileNO = fileno(destFile);   

    /* init arbre huffman - racine */
	while(pow(2,(E+1))<=256) E++;   
	R = 256 - (int)pow(2,E);   
	racine.numNo = 2*256-1;   
	racine.pPere = NULL;   
	pNYT = &racine;   
   
	decompression();   
	
    if(destFile) fclose(destFile);   
    if(srcFile) fclose(srcFile);  
    
    if(pNYT && pNYT != &racine) free(pNYT);   
    pbloc = racine.pbloc;   
    while(pbloc) {   
        pNoeud = pbloc->pPrem;   
        while(pNoeud) {   
            pNext = pNoeud->pPrev;   
            if(pNoeud != &racine)   
            free(pNoeud);   
            pNoeud = pNext;   
        }   
        pPrevLINK = pbloc->pPrev;   
        free(pbloc);   
        pbloc = pPrevLINK;   
    }   
	printf("\n\n%s est compresse dans le fichier '%s' par methode huffman diynamique\n",argv[1],nomS);    
	return EXIT_SUCCESS;
}  
Пример #5
0
void PrefsDialog::initLayout(QFileInfoList & languages, QList<Platform *> platforms)
{
	m_tabWidget = new QTabWidget();
	m_general = new QWidget();
	m_breadboard = new QWidget();
	m_schematic = new QWidget();
	m_pcb = new QWidget();
    m_code = new QWidget();
    m_tabWidget->setObjectName("preDia_tabs");

	m_tabWidget->addTab(m_general, tr("General"));
	m_tabWidget->addTab(m_breadboard, m_viewInfoThings[0].viewName);
	m_tabWidget->addTab(m_schematic, m_viewInfoThings[1].viewName);
	m_tabWidget->addTab(m_pcb, m_viewInfoThings[2].viewName);
    m_tabWidget->addTab(m_code, tr("Code View"));

	QVBoxLayout * vLayout = new QVBoxLayout();
	vLayout->addWidget(m_tabWidget);

    initGeneral(m_general, languages);

	initBreadboard(m_breadboard, &m_viewInfoThings[0]);
	initSchematic(m_schematic, &m_viewInfoThings[1]);
	initPCB(m_pcb, &m_viewInfoThings[2]);

    initCode(m_code, platforms);
    m_platforms = platforms;

    QDialogButtonBox * buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
	buttonBox->button(QDialogButtonBox::Cancel)->setText(tr("Cancel"));
	buttonBox->button(QDialogButtonBox::Ok)->setText(tr("OK"));

    connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
    connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));

	vLayout->addWidget(buttonBox);

    this->setLayout(vLayout);

}
Пример #6
0
int main(int n, char **argv){

	// variables
	noeud arbre[512];	// tableau des noeds
	stamp codes[256];	// tableau des codes binaires pour des caracteres

	unsigned long int total_chars = 0, octets_ecrits = 0;
	
	FILE* file_input, *file_output;
	
	unsigned char buff[3], glob_buff = 0;
	int racine, glob_counter = 0;

	int ver = 0, ver_pos2 = 8; // pour faire jolie.
	
	if(n >= 3){
//////////////////////////////////////////////////////////////////////////////////////////////////////////// ENCODAGE

		printf("\n\nBienvenue au Huffman Code v.%d.%d\n\nInitialisation du mode ENcodage.\n\n\n", ver, ver_pos2);
		
		if(file_input = fopen(argv[1], "r")){
			
			// INITIALISATION DES STRUCTURES
			initArbre(arbre, 512);
			initCode(codes, 256);

			// lire des chars & compter nbs d'occurences
			while(fread(buff, sizeof(char), 1, file_input) > 0){
				arbre[(int)buff[0]].freq++;
				total_chars++;
			}
			
			// calculer la frequences a partir des nombres d'occurences
			occur2Freq(arbre, total_chars); 
			
			// CONTRUCTION DE L'ARBRE
			racine = consArbre(arbre, 256);
			
			
			// GENERATION DES CODES
			genereCodes(arbre, codes, racine, 0);

			printTArbre(arbre, racine); 
			printTCodes(codes);

			printf("\n\nLongeur moyenne de codage: %f\n", moyCodes(codes));
			printf("Encodage.... "); fflush(stdout);
			
			if(file_output = fopen(argv[2], "w")){
				
				octets_ecrits += sauvegardeHeader(file_output, codes, &glob_buff, &glob_counter);
				octets_ecrits += encode(file_input, file_output, codes, &glob_buff, &glob_counter);
				
					printf("\nTaille originelle : %d (%s); taille compressee : %d (%s); gain : %f%% !\n\n", (int)total_chars, argv[1], (int)octets_ecrits, argv[2], 100 - (octets_ecrits/(float)total_chars)*100);

				fclose(file_output);
			}else{
				printf("On n'a pas pu creer un fichier '%s'\n", argv[2]);
			}
			
			fclose(file_input);
		}else{
		
			printf("\nError. Le fichier '%s' ne peut pas etre ouvert.\n", argv[1]);
		}

//////////////////////////////////////////////////////////////////////////////////////////////////////////// ENCODAGE - FIN
	}else{
		
		printf("Utilisation: %s <fichier source> <fichier destination>\n\n", argv[0]);
	}
	return 0;
}
Пример #7
0
int main(void)
{
  // FILE pointer 
  // read from file and write to file
	FILE* fin = NULL;
	FILE* fout = NULL;
 
	// Instruction type 
	R_Type R = {0, 0, 0, 0, 0, 0};
	I_Type I = {0, 0, 0, 0};
	J_Type J = {0, 0};
	
	// buffer string 
	// read assembly code 
	// and write machine code
	char* InstPtr = NULL;
	char buffer[512] = {0, };
	char Instruction[128] = {0, };
	char machineCode[44] = {0, };
	char machineCode_out[44] = {0, };
 
	// confirm I-type format
	int i_type_ = 0;
 
	// open file assemblycode.txt and machinecode.txt
	if((fin = fopen("assemblycode.txt", "rt")) == NULL)
	{
		puts("fopen('assemblycode.txt') error!!");
		return 0;
	}
	if((fout = fopen("machinecode.txt", "wt")) == NULL)
	{
		puts("fopen('machinecode.txt') error!!");
		return 0;
	}
 
	// init machine code and printout to file
	initCode(machineCode_out, machineCode);
	fputs(machineCode_out, fout);
	fputs("\n", fout);
 
	// read file line from "assemblycode.txt"
	while(fgets(buffer, 512, fin) )
	{
		// initialize machineCode buffer string 
		// and Instruction buffer string to zero
 
		memset(machineCode, 0, 36);
		memset(Instruction, 0, 128);
		strcpy(Instruction, buffer);			// copy instruction to buffer
		InstPtr = getInstruction(Instruction);	// and get operation code
 
		fputs(buffer,stdout);
 
		// check Instruction type
		// and read instruction and
		// write to structure
		if(IsR_Type(InstPtr))
		{
			R = ReadR_Type(buffer);
			R_TypeToBinaryCode(machineCode, R);
		}
		else if(i_type_ = IsI_Type(InstPtr))
		{
			switch (i_type_)
			{
			case 1:
				I = ReadI_Type_I(buffer);
				break;
			case 2:
				I = ReadI_Type_II(buffer);
				break;
			case 3:
				I = ReadI_Type_II(buffer);
				break;
			case 4:
				I = ReadI_Type_IV(buffer);
				break;
			}
			I_TypeToBinaryCode(machineCode, I);
		}
		else if(IsJ_Type(InstPtr))
		{
			J = ReadJ_Type(buffer);
			J_TypeToBinaryCode(machineCode, J);
		}
		// if instruction is inaccurate 
		// print error message
		else
		{
			puts("Incorrect istruction!!");
			fputs("Incorrect instruction!!", fout);
		}
		
		// divide 32bit machine code to four part
		// and print machine code to "machinecode.txt"
		divide_8bit(machineCode_out, machineCode);
		puts(machineCode_out);
		fputs(machineCode_out, fout);
		fputs("\n", fout);
	}
 
	fclose(fin);
	fclose(fout);
 
	return 0;
}
Пример #8
0
void QgsEditFormConfig::writeXml( QDomNode& node ) const
{
  QDomDocument doc( node.ownerDocument() );

  QDomElement efField  = doc.createElement( "editform" );
  QDomText efText = doc.createTextNode( QgsProject::instance()->writePath( uiForm() ) );
  efField.appendChild( efText );
  node.appendChild( efField );

  QDomElement efiField  = doc.createElement( "editforminit" );
  if ( !initFunction().isEmpty() )
    efiField.appendChild( doc.createTextNode( initFunction() ) );
  node.appendChild( efiField );

  QDomElement eficsField  = doc.createElement( "editforminitcodesource" );
  eficsField.appendChild( doc.createTextNode( QString::number( initCodeSource() ) ) );
  node.appendChild( eficsField );

  QDomElement efifpField  = doc.createElement( "editforminitfilepath" );
  efifpField.appendChild( doc.createTextNode( QgsProject::instance()->writePath( initFilePath() ) ) );
  node.appendChild( efifpField );


  QDomElement eficField  = doc.createElement( "editforminitcode" );
  eficField.appendChild( doc.createCDATASection( initCode() ) );
  node.appendChild( eficField );

  QDomElement fFSuppElem  = doc.createElement( "featformsuppress" );
  QDomText fFSuppText = doc.createTextNode( QString::number( suppress() ) );
  fFSuppElem.appendChild( fFSuppText );
  node.appendChild( fFSuppElem );

  // tab display
  QDomElement editorLayoutElem  = doc.createElement( "editorlayout" );
  switch ( layout() )
  {
    case QgsEditFormConfig::UiFileLayout:
      editorLayoutElem.appendChild( doc.createTextNode( "uifilelayout" ) );
      break;

    case QgsEditFormConfig::TabLayout:
      editorLayoutElem.appendChild( doc.createTextNode( "tablayout" ) );
      break;

    case QgsEditFormConfig::GeneratedLayout:
    default:
      editorLayoutElem.appendChild( doc.createTextNode( "generatedlayout" ) );
      break;
  }

  node.appendChild( editorLayoutElem );

  // tabs and groups of edit form
  if ( tabs().size() > 0 )
  {
    QDomElement tabsElem = doc.createElement( "attributeEditorForm" );

    for ( QList< QgsAttributeEditorElement* >::const_iterator it = mAttributeEditorElements.constBegin(); it != mAttributeEditorElements.constEnd(); ++it )
    {
      QDomElement attributeEditorWidgetElem = ( *it )->toDomElement( doc );
      tabsElem.appendChild( attributeEditorWidgetElem );
    }

    node.appendChild( tabsElem );
  }

  //// TODO: MAKE THIS MORE GENERIC, SO INDIVIDUALL WIDGETS CAN NOT ONLY SAVE STRINGS
  /// SEE QgsEditorWidgetFactory::writeConfig

  QDomElement widgetsElem = doc.createElement( "widgets" );

  QMap<QString, QgsEditorWidgetConfig >::ConstIterator configIt( mWidgetConfigs.constBegin() );

  while ( configIt != mWidgetConfigs.constEnd() )
  {
    if ( mFields.indexFromName( configIt.key() ) == -1 )
    {
      QDomElement widgetElem = doc.createElement( "widget" );
      widgetElem.setAttribute( "name", configIt.key() );

      QDomElement configElem = doc.createElement( "config" );
      widgetElem.appendChild( configElem );

      QgsEditorWidgetConfig::ConstIterator cfgIt( configIt.value().constBegin() );

      while ( cfgIt != configIt.value().constEnd() )
      {
        QDomElement optionElem = doc.createElement( "option" );
        optionElem.setAttribute( "key", cfgIt.key() );
        optionElem.setAttribute( "value", cfgIt.value().toString() );
        configElem.appendChild( optionElem );
        ++cfgIt;
      }

      widgetsElem.appendChild( widgetElem );
    }
    ++configIt;
  }

  node.appendChild( widgetsElem );

  //// END TODO
}