void test_DCT_and_IDCT_with_quantization_and_dequantization(){ float imageMatrix[8][8] = {{139, 144, 149, 153, 155, 155, 155, 155}, {144, 151, 153, 156, 159, 156, 156, 156}, {150, 155, 160, 163, 158, 156, 156, 156}, {159, 161, 162, 160, 160, 159, 159, 159}, {159, 160, 161, 162, 162, 155, 155, 155}, {161, 161, 161, 161, 160, 157, 157, 157}, {162, 162, 161, 163, 162, 157, 157, 157}, {162, 162, 161, 161, 163, 158, 158, 158}}; int size = 8; int i, j; normalizeMatrix(size, imageMatrix); twoD_DCT(size, imageMatrix); // dumpMatrix(size,imageMatrix); quantizationFunction50(size, imageMatrix); // dumpMatrix(size,imageMatrix); // printf("\n"); dequantizationFunction50(size, imageMatrix); // dumpMatrix(size,imageMatrix); twoD_IDCT(size, imageMatrix); // dumpMatrix(size,imageMatrix); denormalizeMatrix(size, imageMatrix); // dumpMatrix(size, imageMatrix); }
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 }
/* * Raw file DCT output * ----- ----- * | | read+chop write | | * | | ----> DCT ----> Quantization ----> | | * | | | | * ----- ----- * DCT output IDCT result * ----- ----- * | | read+chop write | | * | | ----> Dequantization ----> IDCT ----> | | * | | | | * ----- ----- */ void test_release2(){ CEXCEPTION_T error; Stream *inStream = NULL; Stream *outStream = NULL; float inputMatrix[8][8]; int size = 8, count = 0; Try{ inStream = openStream("test/Data/Water lilies.7z.010", "rb"); outStream = openStream("test/Data/Water lilies_RE2.7z.010", "wb"); }Catch(error){ TEST_ASSERT_EQUAL(ERR_END_OF_FILE, error); } Try{ while(1){ readBlock(inStream, size, inputMatrix); //printf("%.3f", inputMatrix[0][0]); normalizeMatrix(size, inputMatrix); // dumpMatrix(size, inputMatrix); twoD_DCT(size, inputMatrix); // printf("%.3f", inputMatrix[0][0]); // dumpMatrix(size, inputMatrix); quantizationFunction50(size, inputMatrix); // dumpMatrix(size, inputMatrix); writeBlock11Bit(outStream, size, inputMatrix); if( feof(inStream->file) ) { break ; } } }Catch(error){ TEST_ASSERT_EQUAL(ERR_END_OF_FILE, error); } closeStream(inStream); closeStream(outStream); // printf("\n"); Stream *inStream2 = NULL; Stream *outStream2 = NULL; count = 0; short int inputMatrixIDCT[8][8]; Try{ inStream2 = openStream("test/Data/Water lilies_RE2.7z.010", "rb"); outStream2 = openStream("test/Data/Water lilies_RE2Out.7z.010", "wb"); }Catch(error){ TEST_ASSERT_EQUAL(ERR_END_OF_FILE, error); } Try{ while(1){ readBlock11Bit(inStream2, size, inputMatrixIDCT); // dumpMatrixInt(size, inputMatrixIDCT); convertToFloat(inputMatrixIDCT, inputMatrix); dequantizationFunction50(size, inputMatrix); //dumpMatrix(size, inputMatrix); twoD_IDCT(size, inputMatrix); denormalizeMatrix(size, inputMatrix); // dumpMatrix(size, inputMatrix); writeBlock(outStream2, size, inputMatrix); if( feof(inStream2->file) ) { break ; } } }Catch(error){ TEST_ASSERT_EQUAL(ERR_END_OF_FILE, error); } closeStream(inStream2); closeStream(outStream2); }
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 }