コード例 #1
0
ファイル: test_IT.c プロジェクト: KyOChiang/ImageCompressor
void test_release_compression_logic(){
CEXCEPTION_T error;
  Stream *inStream = NULL;
  Stream *outStream = NULL;
  State yProgress = {.state = 0, .index = 0};
  State cbProgress = {.state = 0, .index = 0};
  State crProgress = {.state = 0, .index = 0};
  float inputMatrixA[8][8], inputMatrixB[8][8], inputMatrixC[8][8];
  short int outMatrixA[8][8], outMatrixB[8][8], outMatrixC[8][8];
  int size = 8; uint32 bytesToWrite;
  RGB colorRGB; YCbCr lumaChrom;

  uint8 R[8][8], G[8][8], B[8][8];
	uint8 Y[8][8], Cb[8][8], Cr[8][8];
  
  colorRGB.red = &R; colorRGB.green = &G; colorRGB.blue = &B;
  lumaChrom.Y = &Y; lumaChrom.Cb = &Cb; lumaChrom.Cr = &Cr;
	
	Try{
    inStream = openStream("test/Data/Water lilies.7z.010", "rb");
    outStream = openStream("test/Data/outputData.7z.010", "wb");
  }Catch(error){
    TEST_ASSERT_EQUAL(ERR_FILE_NOT_EXIST, error);
  }
  
  readFileToRGB(inStream,R,G,B);
  
  convertToLuma(&colorRGB, &lumaChrom);
  convertToChromaB(&colorRGB, &lumaChrom);
  convertToChromaR(&colorRGB, &lumaChrom);
  
  convertUINT8ToFloat(Y, inputMatrixA);
  convertUINT8ToFloat(Cb, inputMatrixB);
  convertUINT8ToFloat(Cr, inputMatrixC);
  
  normalizeMatrix(8,inputMatrixA);
  normalizeMatrix(8,inputMatrixB);
  normalizeMatrix(8,inputMatrixC);
  
  twoD_DCT(8,inputMatrixA);
  twoD_DCT(8,inputMatrixB);
  twoD_DCT(8,inputMatrixC);
  
  quantizationFunction50(8,inputMatrixA); //Y array
  quantizationFunction50(8,inputMatrixB); //Cb array
  quantizationFunction50(8,inputMatrixC); //Cr array
  
  convertToUINT16(inputMatrixA, outMatrixA);
  convertToUINT16(inputMatrixB, outMatrixB);
  convertToUINT16(inputMatrixC, outMatrixC);
  bytesToWrite = huffmanEncodePull(&yProgress, outMatrixA, dcLuminanceTable);
  write4Bytes(outStream, bytesToWrite);
  
  while(yProgress.index != 64){
    bytesToWrite = huffmanEncodePull(&yProgress, outMatrixA, acLuminanceTable);
    write4Bytes(outStream, bytesToWrite);
  }
  
  bytesToWrite = huffmanEncodePull(&cbProgress, outMatrixB, dcChrominanceTable);
  write4Bytes(outStream, bytesToWrite);
  
  while(cbProgress.index != 64){
    bytesToWrite = huffmanEncodePull(&cbProgress, outMatrixB, acChrominanceTable);
    write4Bytes(outStream, bytesToWrite);
  }
  
  bytesToWrite = huffmanEncodePull(&crProgress, outMatrixC, dcChrominanceTable);
  write4Bytes(outStream, bytesToWrite);
  
  while(crProgress.index != 64){
    bytesToWrite = huffmanEncodePull(&crProgress, outMatrixC, acChrominanceTable);
    write4Bytes(outStream, bytesToWrite);
  }
  
  //To Encoder..... can only detect state.index to stop when it is 64
  //To Byte Stuff, output to file in Y, Cb, Cr
  //Repeat process until (!feof(inStream))
  
  closeStream(inStream);
  closeStream(outStream);
}

// convertToLuma(&colorRGB, &lumaChrom); convertToChromaB(&colorRGB, &lumaChrom); convertToChromaR(&colorRGB, &lumaChrom);
// dumpMatrixUINT8(8,Y); dumpMatrixUINT8(8,Cb); dumpMatrixUINT8(8,Cr);
// dumpMatrixUINT8(8,R); dumpMatrixUINT8(8,G); dumpMatrixUINT8(8,B);

// printf("\n");
// convertToRed(&colorRGB, &lumaChrom); convertToBlue(&colorRGB, &lumaChrom); convertToGreen(&colorRGB, &lumaChrom);
// dumpMatrixUINT8(8,R); dumpMatrixUINT8(8,G); dumpMatrixUINT8(8,B);

// dumpMatrix(8, inputMatrixA);
// dumpMatrix(8, inputMatrixB);
// dumpMatrix(8, inputMatrixC);

void xtest_release_decompression_logic(){
  //Huffman decoder
  //To Run Length Decode
  //Loop 3 times to get Y Cb Cr arrays
  //De-Q - IDCT - Denormalization - Color Conversion back to RGB
  //Output to file again
}
コード例 #2
0
ファイル: test_IT.c プロジェクト: soofatt/ImageCompressor
void test_release_compression_logic(){
CEXCEPTION_T error;
  Stream *inStream = NULL;
  Stream *outStream = NULL;
  State yProgress = {.state = 0, .index = 0};
  State cbProgress = {.state = 0, .index = 0};
  State crProgress = {.state = 0, .index = 0};
  float inputMatrixA[8][8], inputMatrixB[8][8], inputMatrixC[8][8];
  short int outMatrixA[8][8], outMatrixB[8][8], outMatrixC[8][8];
  int size = 8; uint32 bytesToWrite;
  RGB colorRGB; YCbCr lumaChrom;

  uint8 R[8][8], G[8][8], B[8][8];
	uint8 Y[8][8], Cb[8][8], Cr[8][8];
  
  colorRGB.red = &R; colorRGB.green = &G; colorRGB.blue = &B;
  lumaChrom.Y = &Y; lumaChrom.Cb = &Cb; lumaChrom.Cr = &Cr;
	
	Try{
    inStream = openStream("test/Data/Water lilies.7z.010", "rb");
    outStream = openStream("test/Data/outputData.7z.010", "wb");
  }Catch(error){
    TEST_ASSERT_EQUAL(ERR_FILE_NOT_EXIST, error);
  }
  
  readFileToRGB(inStream,R,G,B);
  
  convertToLuma(&colorRGB, &lumaChrom);
  convertToChromaB(&colorRGB, &lumaChrom);
  convertToChromaR(&colorRGB, &lumaChrom);
  
  convertUINT8ToFloat(Y, inputMatrixA);
  convertUINT8ToFloat(Cb, inputMatrixB);
  convertUINT8ToFloat(Cr, inputMatrixC);
  
  normalizeMatrix(8,inputMatrixA);
  normalizeMatrix(8,inputMatrixB);
  normalizeMatrix(8,inputMatrixC);
  
  twoD_DCT(8,inputMatrixA);
  twoD_DCT(8,inputMatrixB);
  twoD_DCT(8,inputMatrixC);
  
  quantizationFunction50(8,inputMatrixA); //Y array
  quantizationFunction50(8,inputMatrixB); //Cb array
  quantizationFunction50(8,inputMatrixC); //Cr array
  
  convertToUINT16(inputMatrixA, outMatrixA);
  convertToUINT16(inputMatrixB, outMatrixB);
  convertToUINT16(inputMatrixC, outMatrixC);
  bytesToWrite = huffmanEncodePull(&yProgress, outMatrixA, dcLuminanceTable);
  write4Bytes(outStream, bytesToWrite);
  
  while(yProgress.index != 64){
    bytesToWrite = huffmanEncodePull(&yProgress, outMatrixA, acLuminanceTable);
    write4Bytes(outStream, bytesToWrite);
  }
  
  bytesToWrite = huffmanEncodePull(&cbProgress, outMatrixB, dcChrominanceTable);
  write4Bytes(outStream, bytesToWrite);
  
  while(cbProgress.index != 64){
    bytesToWrite = huffmanEncodePull(&cbProgress, outMatrixB, acChrominanceTable);
    write4Bytes(outStream, bytesToWrite);
  }
  
  bytesToWrite = huffmanEncodePull(&crProgress, outMatrixC, dcChrominanceTable);
  write4Bytes(outStream, bytesToWrite);
  
  while(crProgress.index != 64){
    bytesToWrite = huffmanEncodePull(&crProgress, outMatrixC, acChrominanceTable);
    write4Bytes(outStream, bytesToWrite);
  }
  
  //To Encoder..... can only detect state.index to stop when it is 64
  //To Byte Stuff, output to file in Y, Cb, Cr
  //Repeat process until (!feof(inStream))
  
  closeStream(inStream);
  closeStream(outStream);
}

// convertToLuma(&colorRGB, &lumaChrom); convertToChromaB(&colorRGB, &lumaChrom); convertToChromaR(&colorRGB, &lumaChrom);
// dumpMatrixUINT8(8,Y); dumpMatrixUINT8(8,Cb); dumpMatrixUINT8(8,Cr);
// dumpMatrixUINT8(8,R); dumpMatrixUINT8(8,G); dumpMatrixUINT8(8,B);

// printf("\n");
// convertToRed(&colorRGB, &lumaChrom); convertToBlue(&colorRGB, &lumaChrom); convertToGreen(&colorRGB, &lumaChrom);
// dumpMatrixUINT8(8,R); dumpMatrixUINT8(8,G); dumpMatrixUINT8(8,B);

// dumpMatrix(8, inputMatrixA);
// dumpMatrix(8, inputMatrixB);
// dumpMatrix(8, inputMatrixC);

void xtest_release_decompression_logic(){
  CEXCEPTION_T error;
  Stream *inStream = NULL;
  Stream *outStream = NULL;
  CodeTable *dcDecodeLumTable = createTable(DCLumTable, 0, sizeof(DCLumTable)/sizeof(RunSizeCode));
  CodeTable *dcDecodeChromTable = createTable(DCChromTable, 0, sizeof(DCChromTable)/sizeof(RunSizeCode));
  CodeTable *acDecodeLumTable = createTable(ACLumTable, 0, sizeof(ACLumTable)/sizeof(RunSizeCode));
  CodeTable *acDecodeChromTable = createTable(ACChromTable, 0, sizeof(ACChromTable)/sizeof(RunSizeCode));
  uint32 bytesToRead, catAndSymbol, runAndDecodedSymbol;
  uint16 codeWord, symbol, runLength, category;
  uint8 runAndSize;
  int16 valueDecodedSymbol;
  int count = 0;
  
  Try{
    inStream = openStream("test/Data/outputData.7z.010", "rb");
    outStream = openStream("test/Data/outputDataDecompress.7z.010", "wb");
  }Catch(error){
    TEST_ASSERT_EQUAL(ERR_FILE_NOT_EXIST, error);
  }
  
  /*bytesToRead = read4Bytes(inStream);
  
  codeWord = bytesToRead >> 16;
  symbol = bytesToRead & 0xffff;
  
  runAndSize = huffmanDecode(codeWord, dcDecodeLumTable);
  runLength = runAndSize >> 4;
  category = runAndSize & 0xf;
  
  catAndSymbol = category;
  catAndSymbol = (catAndSymbol << 16) | symbol;
  
  valueDecodedSymbol = valueDecoding(catAndSymbol);
  
  runAndDecodedSymbol = runLength;
  runAndDecodedSymbol = (runAndDecodedSymbol << 16) | valueDecodedSymbol;
  
  //runAndDecodedSymbol to run-length decode
  while(count < 63){
    bytesToRead = read4Bytes(inStream);
  
    codeWord = bytesToRead >> 16;
    symbol = bytesToRead & 0xffff;
    
    runAndSize = huffmanDecode(codeWord, acDecodeLumTable);
    runLength = runAndSize >> 4;
    category = runAndSize & 0xf;
    
    catAndSymbol = category;
    catAndSymbol = (catAndSymbol << 16) | symbol;
    
    valueDecodedSymbol = valueDecoding(catAndSymbol);
    
    runAndDecodedSymbol = runLength;
    runAndDecodedSymbol = (runAndDecodedSymbol << 16) | valueDecodedSymbol;
    //runAndDecodedSymbol to run-length decode
    
    count++;
  }
  
  bytesToRead = read4Bytes(inStream);
  
  codeWord = bytesToRead >> 16;
  symbol = bytesToRead & 0xffff;
  
  runAndSize = huffmanDecode(codeWord, dcDecodeChromTable);
  runLength = runAndSize >> 4;
  category = runAndSize & 0xf;
  
  catAndSymbol = category;
  catAndSymbol = (catAndSymbol << 16) | symbol;
  
  valueDecodedSymbol = valueDecoding(catAndSymbol);
  
  runAndDecodedSymbol = runLength;
  runAndDecodedSymbol = (runAndDecodedSymbol << 16) | valueDecodedSymbol;
  
  //runAndDecodedSymbol to run-length decode
  while(count < 63){
    bytesToRead = read4Bytes(inStream);
  
    codeWord = bytesToRead >> 16;
    symbol = bytesToRead & 0xffff;
    
    runAndSize = huffmanDecode(codeWord, acDecodeChromTable);
    runLength = runAndSize >> 4;
    category = runAndSize & 0xf;
    
    catAndSymbol = category;
    catAndSymbol = (catAndSymbol << 16) | symbol;
    
    valueDecodedSymbol = valueDecoding(catAndSymbol);
    
    runAndDecodedSymbol = runLength;
    runAndDecodedSymbol = (runAndDecodedSymbol << 16) | valueDecodedSymbol;
    //runAndDecodedSymbol to run-length decode
    
    count++;
  }
  
  bytesToRead = read4Bytes(inStream);
  
  codeWord = bytesToRead >> 16;
  symbol = bytesToRead & 0xffff;
  
  runAndSize = huffmanDecode(codeWord, dcDecodeChromTable);
  runLength = runAndSize >> 4;
  category = runAndSize & 0xf;
  
  catAndSymbol = category;
  catAndSymbol = (catAndSymbol << 16) | symbol;
  
  valueDecodedSymbol = valueDecoding(catAndSymbol);
  
  runAndDecodedSymbol = runLength;
  runAndDecodedSymbol = (runAndDecodedSymbol << 16) | valueDecodedSymbol;
  
  //runAndDecodedSymbol to run-length decode
  while(count < 63){
    bytesToRead = read4Bytes(inStream);
  
    codeWord = bytesToRead >> 16;
    symbol = bytesToRead & 0xffff;
    
    runAndSize = huffmanDecode(codeWord, acDecodeChromTable);
    runLength = runAndSize >> 4;
    category = runAndSize & 0xf;
    
    catAndSymbol = category;
    catAndSymbol = (catAndSymbol << 16) | symbol;
    
    valueDecodedSymbol = valueDecoding(catAndSymbol);
    
    runAndDecodedSymbol = runLength;
    runAndDecodedSymbol = (runAndDecodedSymbol << 16) | valueDecodedSymbol;
    //runAndDecodedSymbol to run-length decode

    
    count++;
  }*/
  
  closeStream(inStream);
  closeStream(outStream);
  //Huffman decoder
  //To Run Length Decode
  //Loop 3 times to get Y Cb Cr arrays
  //De-Q - IDCT - Denormalization - Color Conversion back to RGB
  //Output to file again
}