URL
https://opencores.org/ocsvn/mb-jpeg/mb-jpeg/trunk
Subversion Repositories mb-jpeg
Compare Revisions
- This comparison shows the changes necessary to convert path
/mb-jpeg/tags/Step2_2/encoder
- from Rev 44 to Rev 66
- ↔ Reverse comparison
Rev 44 → Rev 66
/.cdtproject
0,0 → 1,20
<?xml version="1.0" encoding="UTF-8"?> |
<?eclipse-cdt version="2.0"?> |
|
<cdtproject id="org.eclipse.cdt.managedbuilder.core.managedMake"> |
<extension point="org.eclipse.cdt.core.ScannerInfoProvider" id="org.eclipse.cdt.managedbuilder.core.ManagedBuildManager"/> |
<extension point="org.eclipse.cdt.core.ScannerInfoProvider" id="org.eclipse.cdt.managedbuilder.core.ManagedBuildManager"/> |
<extension point="org.eclipse.cdt.core.BinaryParser" id="org.eclipse.cdt.core.ELF"/> |
<extension point="org.eclipse.cdt.core.BinaryParser" id="org.eclipse.cdt.core.ELF"/> |
<data> |
<item id="cdt_indexer"> |
<indexEnabled indexValue="true"/> |
<indexerProblemsEnabled indexProblemsValue="0"/> |
</item> |
<item id="org.eclipse.cdt.core.pathentry"> |
<pathentry kind="src" path=""/> |
<pathentry kind="out" path=""/> |
<pathentry kind="con" path="org.eclipse.cdt.managedbuilder.MANAGED_CONTAINER"/> |
</item> |
</data> |
</cdtproject> |
/.project
0,0 → 1,18
<?xml version="1.0" encoding="UTF-8"?> |
<projectDescription> |
<name>Encoder</name> |
<comment></comment> |
<projects> |
</projects> |
<buildSpec> |
<buildCommand> |
<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name> |
<arguments> |
</arguments> |
</buildCommand> |
</buildSpec> |
<natures> |
<nature>org.eclipse.cdt.core.cnature</nature> |
<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature> |
</natures> |
</projectDescription> |
/.cdtbuild
0,0 → 1,84
<?xml version="1.0" encoding="UTF-8"?> |
<?fileVersion 2.1.0?> |
|
<ManagedProjectBuildInfo> |
<project id="Encoder.xygwin.mb.exec.1194899657" name="Xilinx MicroBlaze Executable" projectType="xygwin.mb.exec"> |
<configuration id="mb.xygwin.exec.debug.602245745" name="Debug" parent="mb.xygwin.exec.debug" artifactName="Encoder" artifactExtension="elf" cleanCommand="rm -rf"> |
<toolChain superClass="mb.xygwin.exec.debug.toolchain" id="mb.xygwin.exec.debug.toolchain.1559671636" name="Debug.toolchain"> |
<tool superClass="mb.xygwin.exec.debug.com.xilinx.mdt.edk.build.tool.xygwin.mb.c.compiler" id="mb.xygwin.exec.debug.com.xilinx.mdt.edk.build.tool.xygwin.mb.c.compiler.679472982" name="MicroBlaze C Compiler" command="mb-gcc"> |
<option superClass="xygwin.mb.c.compiler.general.include.paths" id="xygwin.mb.c.compiler.general.include.paths.383846128" valueType="includePath"> |
<listOptionValue value="D:/mb-jpeg/microblaze_0/include" builtIn="false"/> |
</option> |
<option superClass="xygwin.mb.c.compiler.general.optimization.level" id="xygwin.mb.c.compiler.general.optimization.level.1245871413" value="xygwin.mb.c.optimization.level.none" valueType="enumerated"/> |
<option superClass="xygwin.mb.c.compiler.debugging.level" id="xygwin.mb.c.compiler.debugging.level.1990705473" value="xygwin.mb.c.debugging.level.default" valueType="enumerated"/> |
<option superClass="xygwin.mb.c.preprocessor.def.symbols" id="xygwin.mb.c.preprocessor.def.symbols.709054186" valueType="definedSymbols"> |
<listOptionValue value="__MICROBLAZE" builtIn="false"/> |
</option> |
</tool> |
<tool superClass="mb.xygwin.exec.debug.com.xilinx.mdt.edk.build.tool.xygwin.mb.cpp.compiler" id="mb.xygwin.exec.debug.com.xilinx.mdt.edk.build.tool.xygwin.mb.cpp.compiler.1740230400" name="MicroBlaze C++ Compiler"> |
<option superClass="xygwin.mb.compiler.general.include.paths" id="xygwin.mb.compiler.general.include.paths.37743093" valueType="includePath"> |
<listOptionValue value="D:/mb-jpeg/microblaze_0/include" builtIn="false"/> |
</option> |
</tool> |
<tool superClass="com.xilinx.mdt.edk.build.tool.xygwin.mb.c.link" id="com.xilinx.mdt.edk.build.tool.xygwin.mb.c.link.1616284189" name="MicroBlaze C Linker"> |
<option superClass="xygwin.mb.c.link.paths" id="xygwin.mb.c.link.paths.975548319" valueType="stringList"> |
<listOptionValue value="D:/mb-jpeg/microblaze_0/lib" builtIn="false"/> |
</option> |
</tool> |
<tool superClass="com.xilinx.mdt.edk.build.tool.xygwin.mb.cpp.link" id="com.xilinx.mdt.edk.build.tool.xygwin.mb.cpp.link.303108100" name="MicroBlaze C++ Linker"> |
<option superClass="xygwin.mb.link.ld.paths" id="xygwin.mb.link.ld.paths.270664798" valueType="stringList"> |
<listOptionValue value="D:/mb-jpeg/microblaze_0/lib" builtIn="false"/> |
</option> |
</tool> |
</toolChain> |
</configuration> |
<configuration id="mb.xygwin.exec.release.1153498697" name="Release" parent="mb.xygwin.exec.release" artifactName="Encoder" artifactExtension="elf" cleanCommand="rm -rf"> |
<toolChain superClass="mb.xygwin.exec.release.toolchain" id="mb.xygwin.exec.release.toolchain.957873867" name="Release.toolchain"> |
<tool superClass="mb.xygwin.exec.release.com.xilinx.mdt.edk.build.tool.xygwin.mb.c.compiler" id="mb.xygwin.exec.release.com.xilinx.mdt.edk.build.tool.xygwin.mb.c.compiler.322049332" name="MicroBlaze C Compiler"> |
<option superClass="xygwin.mb.c.compiler.general.include.paths" id="xygwin.mb.c.compiler.general.include.paths.822770430" valueType="includePath"> |
<listOptionValue value="D:/mb-jpeg/microblaze_0/include" builtIn="false"/> |
</option> |
</tool> |
<tool superClass="mb.xygwin.exec.release.com.xilinx.mdt.edk.build.tool.xygwin.mb.cpp.compiler" id="mb.xygwin.exec.release.com.xilinx.mdt.edk.build.tool.xygwin.mb.cpp.compiler.587962361" name="MicroBlaze C++ Compiler"> |
<option superClass="xygwin.mb.compiler.general.include.paths" id="xygwin.mb.compiler.general.include.paths.1634647658" valueType="includePath"> |
<listOptionValue value="D:/mb-jpeg/microblaze_0/include" builtIn="false"/> |
</option> |
</tool> |
<tool superClass="com.xilinx.mdt.edk.build.tool.xygwin.mb.c.link" id="com.xilinx.mdt.edk.build.tool.xygwin.mb.c.link.615171707" name="MicroBlaze C Linker"> |
<option superClass="xygwin.mb.c.link.paths" id="xygwin.mb.c.link.paths.1123873005" valueType="stringList"> |
<listOptionValue value="D:/mb-jpeg/microblaze_0/lib" builtIn="false"/> |
</option> |
</tool> |
<tool superClass="com.xilinx.mdt.edk.build.tool.xygwin.mb.cpp.link" id="com.xilinx.mdt.edk.build.tool.xygwin.mb.cpp.link.214633272" name="MicroBlaze C++ Linker"> |
<option superClass="xygwin.mb.link.ld.paths" id="xygwin.mb.link.ld.paths.971635136" valueType="stringList"> |
<listOptionValue value="D:/mb-jpeg/microblaze_0/lib" builtIn="false"/> |
</option> |
</tool> |
</toolChain> |
</configuration> |
<configuration id="mb.xygwin.exec.profile.154444796" name="Profile" parent="mb.xygwin.exec.profile" artifactName="Encoder" artifactExtension="elf" cleanCommand="rm -rf"> |
<toolChain superClass="mb.xygwin.exec.profile.toolchain" id="mb.xygwin.exec.profile.toolchain.2042964595" name="Profile.toolchain"> |
<tool superClass="mb.xygwin.exec.profile.com.xilinx.mdt.edk.build.tool.xygwin.mb.c.compiler" id="mb.xygwin.exec.profile.com.xilinx.mdt.edk.build.tool.xygwin.mb.c.compiler.651809076" name="MicroBlaze C Compiler"> |
<option superClass="xygwin.mb.c.compiler.general.include.paths" id="xygwin.mb.c.compiler.general.include.paths.698177397" valueType="includePath"> |
<listOptionValue value="D:/mb-jpeg/microblaze_0/include" builtIn="false"/> |
</option> |
</tool> |
<tool superClass="mb.xygwin.exec.profile.com.xilinx.mdt.edk.build.tool.xygwin.mb.c.link" id="mb.xygwin.exec.profile.com.xilinx.mdt.edk.build.tool.xygwin.mb.c.link.1528638620" name="MicroBlaze C Linker"> |
<option superClass="xygwin.mb.c.link.paths" id="xygwin.mb.c.link.paths.1474010054" valueType="stringList"> |
<listOptionValue value="D:/mb-jpeg/microblaze_0/lib" builtIn="false"/> |
</option> |
</tool> |
<tool superClass="mb.xygwin.exec.profile.com.xilinx.mdt.edk.build.tool.xygwin.mb.cpp.compiler" id="mb.xygwin.exec.profile.com.xilinx.mdt.edk.build.tool.xygwin.mb.cpp.compiler.1896844227" name="MicroBlaze C++ Compiler"> |
<option superClass="xygwin.mb.compiler.general.include.paths" id="xygwin.mb.compiler.general.include.paths.759784069" valueType="includePath"> |
<listOptionValue value="D:/mb-jpeg/microblaze_0/include" builtIn="false"/> |
</option> |
</tool> |
<tool superClass="mb.xygwin.exec.profile.com.xilinx.mdt.edk.build.tool.xygwin.mb.cpp.link" id="mb.xygwin.exec.profile.com.xilinx.mdt.edk.build.tool.xygwin.mb.cpp.link.722042511" name="MicroBlaze C++ Linker"> |
<option superClass="xygwin.mb.link.ld.paths" id="xygwin.mb.link.ld.paths.1759556686" valueType="stringList"> |
<listOptionValue value="D:/mb-jpeg/microblaze_0/lib" builtIn="false"/> |
</option> |
</tool> |
</toolChain> |
</configuration> |
</project> |
</ManagedProjectBuildInfo> |
/image01.bmp
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
image01.bmp
Property changes :
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: dct.h
===================================================================
--- dct.h (nonexistent)
+++ dct.h (revision 66)
@@ -0,0 +1,21 @@
+
+#include
+#include
+
+/*
+ Function Name: dct
+
+ Operation: Find the 8x8 DCT of an array using separable DCT
+ First, finds 1-d DCT along rows, storing the result in inter[][]
+ Then, 1-d DCT along columns of inter[][] is found
+
+ Input: pixels is the 8x8 input array
+
+ Output: dct is the 8x8 output array
+*/
+
+
+
+void dct(signed char pixels[8][8], signed short dct[8][8]);
+
+void IDCT(short input[8][8], signed char output[8][8]);
Index: weights.h
===================================================================
--- weights.h (nonexistent)
+++ weights.h (revision 66)
@@ -0,0 +1,514 @@
+signed int weights[512] = {
+16384,
+16384,
+16384,
+16384,
+16384,
+16384,
+16384,
+16384,
+16069,
+13623,
+9102,
+3196,
+-3196,
+-9102,
+-13623,
+-16069,
+15137,
+6270,
+-6270,
+-15137,
+-15137,
+-6270,
+6270,
+15137,
+13623,
+-3196,
+-16069,
+-9103,
+9102,
+16069,
+3196,
+-13623,
+11585,
+-11585,
+-11585,
+11585,
+11585,
+-11585,
+-11585,
+11585,
+9102,
+-16069,
+3196,
+13623,
+-13623,
+-3197,
+16069,
+-9102,
+6270,
+-15137,
+15137,
+-6270,
+-6270,
+15137,
+-15137,
+6270,
+3196,
+-9103,
+13623,
+-16069,
+16069,
+-13623,
+9102,
+-3196,
+16384,
+16384,
+16384,
+16384,
+16384,
+16384,
+16384,
+16384,
+16069,
+13623,
+9102,
+3196,
+-3196,
+-9102,
+-13623,
+-16069,
+15137,
+6270,
+-6270,
+-15137,
+-15137,
+-6270,
+6270,
+15137,
+13623,
+-3196,
+-16069,
+-9103,
+9102,
+16069,
+3196,
+-13623,
+11585,
+-11585,
+-11585,
+11585,
+11585,
+-11585,
+-11585,
+11585,
+9102,
+-16069,
+3196,
+13623,
+-13623,
+-3197,
+16069,
+-9102,
+6270,
+-15137,
+15137,
+-6270,
+-6270,
+15137,
+-15137,
+6270,
+3196,
+-9103,
+13623,
+-16069,
+16069,
+-13623,
+9102,
+-3196,
+16384,
+16384,
+16384,
+16384,
+16384,
+16384,
+16384,
+16384,
+16069,
+13623,
+9102,
+3196,
+-3196,
+-9102,
+-13623,
+-16069,
+15137,
+6270,
+-6270,
+-15137,
+-15137,
+-6270,
+6270,
+15137,
+13623,
+-3196,
+-16069,
+-9103,
+9102,
+16069,
+3196,
+-13623,
+11585,
+-11585,
+-11585,
+11585,
+11585,
+-11585,
+-11585,
+11585,
+9102,
+-16069,
+3196,
+13623,
+-13623,
+-3197,
+16069,
+-9102,
+6270,
+-15137,
+15137,
+-6270,
+-6270,
+15137,
+-15137,
+6270,
+3196,
+-9103,
+13623,
+-16069,
+16069,
+-13623,
+9102,
+-3196,
+16384,
+16384,
+16384,
+16384,
+16384,
+16384,
+16384,
+16384,
+16069,
+13623,
+9102,
+3196,
+-3196,
+-9102,
+-13623,
+-16069,
+15137,
+6270,
+-6270,
+-15137,
+-15137,
+-6270,
+6270,
+15137,
+13623,
+-3196,
+-16069,
+-9103,
+9102,
+16069,
+3196,
+-13623,
+11585,
+-11585,
+-11585,
+11585,
+11585,
+-11585,
+-11585,
+11585,
+9102,
+-16069,
+3196,
+13623,
+-13623,
+-3197,
+16069,
+-9102,
+6270,
+-15137,
+15137,
+-6270,
+-6270,
+15137,
+-15137,
+6270,
+3196,
+-9103,
+13623,
+-16069,
+16069,
+-13623,
+9102,
+-3196,
+16384,
+16384,
+16384,
+16384,
+16384,
+16384,
+16384,
+16384,
+16069,
+13623,
+9102,
+3196,
+-3196,
+-9102,
+-13623,
+-16069,
+15137,
+6270,
+-6270,
+-15137,
+-15137,
+-6270,
+6270,
+15137,
+13623,
+-3196,
+-16069,
+-9103,
+9102,
+16069,
+3196,
+-13623,
+11585,
+-11585,
+-11585,
+11585,
+11585,
+-11585,
+-11585,
+11585,
+9102,
+-16069,
+3196,
+13623,
+-13623,
+-3197,
+16069,
+-9102,
+6270,
+-15137,
+15137,
+-6270,
+-6270,
+15137,
+-15137,
+6270,
+3196,
+-9103,
+13623,
+-16069,
+16069,
+-13623,
+9102,
+-3196,
+16384,
+16384,
+16384,
+16384,
+16384,
+16384,
+16384,
+16384,
+16069,
+13623,
+9102,
+3196,
+-3196,
+-9102,
+-13623,
+-16069,
+15137,
+6270,
+-6270,
+-15137,
+-15137,
+-6270,
+6270,
+15137,
+13623,
+-3196,
+-16069,
+-9103,
+9102,
+16069,
+3196,
+-13623,
+11585,
+-11585,
+-11585,
+11585,
+11585,
+-11585,
+-11585,
+11585,
+9102,
+-16069,
+3196,
+13623,
+-13623,
+-3197,
+16069,
+-9102,
+6270,
+-15137,
+15137,
+-6270,
+-6270,
+15137,
+-15137,
+6270,
+3196,
+-9103,
+13623,
+-16069,
+16069,
+-13623,
+9102,
+-3196,
+16384,
+16384,
+16384,
+16384,
+16384,
+16384,
+16384,
+16384,
+16069,
+13623,
+9102,
+3196,
+-3196,
+-9102,
+-13623,
+-16069,
+15137,
+6270,
+-6270,
+-15137,
+-15137,
+-6270,
+6270,
+15137,
+13623,
+-3196,
+-16069,
+-9103,
+9102,
+16069,
+3196,
+-13623,
+11585,
+-11585,
+-11585,
+11585,
+11585,
+-11585,
+-11585,
+11585,
+9102,
+-16069,
+3196,
+13623,
+-13623,
+-3197,
+16069,
+-9102,
+6270,
+-15137,
+15137,
+-6270,
+-6270,
+15137,
+-15137,
+6270,
+3196,
+-9103,
+13623,
+-16069,
+16069,
+-13623,
+9102,
+-3196,
+16384,
+16384,
+16384,
+16384,
+16384,
+16384,
+16384,
+16384,
+16069,
+13623,
+9102,
+3196,
+-3196,
+-9102,
+-13623,
+-16069,
+15137,
+6270,
+-6270,
+-15137,
+-15137,
+-6270,
+6270,
+15137,
+13623,
+-3196,
+-16069,
+-9103,
+9102,
+16069,
+3196,
+-13623,
+11585,
+-11585,
+-11585,
+11585,
+11585,
+-11585,
+-11585,
+11585,
+9102,
+-16069,
+3196,
+13623,
+-13623,
+-3197,
+16069,
+-9102,
+6270,
+-15137,
+15137,
+-6270,
+-6270,
+15137,
+-15137,
+6270,
+3196,
+-9103,
+13623,
+-16069,
+16069,
+-13623,
+9102,
+-3196
+};
Index: huffman.c
===================================================================
--- huffman.c (nonexistent)
+++ huffman.c (revision 66)
@@ -0,0 +1,718 @@
+#pragma argsused
+/*
+Only encoder
+This version works correctly, it is tested with testcase.jpg
+The translation into real huffman codes works.
+Changed: If huffman wants to send 0xFFxx (FF in one byte) than there must be 0x00 inserted between FF and xx
+possible fault in finish send:
+-must it be filled up with zeros? YES
+-must it be filled up to one bye? or 2 byte? --> in this code there is filled up to 2 bytes, but I (joris) thinks this must be filled up to 1 byte.
+ still dont know
+- 24-11-05 code clean up
+- 24-11-05 tables added for color
+
+
+
+Block numbers:
+Y = 0
+cb =1
+cr= 2
+*/
+//---------------------------------------------------------------------------
+#pragma hdrstop
+#include
+#ifdef __MICROBLAZE
+#include "xup2pro.h"
+#endif
+//===========================================================================
+void PrintMatrix(char* pixelmatrix)
+{
+int i;
+// printf("MATRIX= \n");
+// for (i=0;i<64;i++) printf("%d |",pixelmatrix[i]);
+// printf("\n");
+}
+//===========================================================================
+void FillMatrix( char* pixelmatrix,int select)
+{
+ int i;
+ if (select== 0)
+ {
+ for (i=0;i<64;i++) pixelmatrix[i]=0;
+ pixelmatrix[0]=6;
+ pixelmatrix[1]=-4;
+ pixelmatrix[2]=15;
+ pixelmatrix[3]=4;
+ pixelmatrix[7]=-1;
+ pixelmatrix[11]=2;
+ pixelmatrix[12]=2;
+ pixelmatrix[20]=-1;
+
+ }
+ else if (select == 1 )
+ {
+ for (i=0;i<64;i++) pixelmatrix[i]=0;
+ pixelmatrix[0]=36;
+ pixelmatrix[1]=-1;
+ pixelmatrix[2]=1;
+ pixelmatrix[3]=-2;
+ pixelmatrix[4]=3;
+ pixelmatrix[5]=-5;
+ pixelmatrix[6]=0;
+ pixelmatrix[7]=7;
+ pixelmatrix[8]=4;
+ pixelmatrix[9]=-10;
+ pixelmatrix[12]=8;
+ pixelmatrix[13]=-16;
+ pixelmatrix[14]=17;
+ pixelmatrix[33]=30;
+ pixelmatrix[34]=-63;
+ pixelmatrix[35]=-32;
+ pixelmatrix[36]=50;
+ pixelmatrix[40]=-100;
+ pixelmatrix[41]=121;
+ pixelmatrix[42]=100;
+ pixelmatrix[47]=-3;
+ pixelmatrix[48]=-2;
+ pixelmatrix[49]=-7;
+ pixelmatrix[50]=-15;
+ pixelmatrix[51]=3;
+ pixelmatrix[52]=7;
+ }
+}
+//===========================================================================
+void ConvertDCMagnitudeC(unsigned char magnitude,unsigned short int *out, unsigned short int *lenght)
+{
+ switch (magnitude) {
+ case 0x00 : *out=0x0000; *lenght=2; break;
+ case 0x01 : *out=0x0001; *lenght=2; break;
+ case 0x02 : *out=0x0002; *lenght=2; break;
+ case 0x03 : *out=0x0006; *lenght=3; break;
+ case 0x04 : *out=0x000e; *lenght=4; break;
+ case 0x05 : *out=0x001e; *lenght=5; break;
+ case 0x06 : *out=0x003e; *lenght=6; break;
+ case 0x07 : *out=0x007e; *lenght=7; break;
+ case 0x08 : *out=0x00fe; *lenght=8; break;
+ case 0x09 : *out=0x01fe; *lenght=9; break;
+ case 0x0a : *out=0x03fe; *lenght=10; break;
+ case 0x0b : *out=0x07fe; *lenght=11; break;
+ }
+}
+//===========================================================================
+void ConvertACMagnitudeC(unsigned char magnitude,unsigned short int *out, unsigned short int *lenght)
+{
+ switch (magnitude) {
+case 0x00 : *lenght=0x02; *out=0x0000; break; //1010
+case 0x01 : *lenght=0x02; *out=0x0001; break; //00
+case 0x02 : *lenght=0x03; *out=0x0004; break; //01
+case 0x03 : *lenght=0x04; *out=0x000a; break; //100
+case 0x04 : *lenght=0x05; *out=0x0018; break; //1011
+case 0x05 : *lenght=0x05; *out=0x0019; break; //11010
+case 0x06 : *lenght=0x06; *out=0x0038; break; //1111000
+case 0x07 : *lenght=0x07; *out=0x0078; break; //11111000
+case 0x08 : *lenght=0x09; *out=0x01f4; break; //1111110110
+case 0x09 : *lenght=0x0a; *out=0x03f6; break; //1111111110000010
+case 0x0A : *lenght=0x0c; *out=0x0ff4; break; //1111111110000011
+case 0x11 : *lenght=0x04; *out=0x000b; break; //1100
+case 0x12 : *lenght=0x06; *out=0x0039; break; //11011
+case 0x13 : *lenght=0x08; *out=0x00f6; break; //1111001
+case 0x14 : *lenght=0x09; *out=0x01f5; break; //111110110
+case 0x15 : *lenght=0x0b; *out=0x07f6; break; //11111110110
+case 0x16 : *lenght=0x0c; *out=0x0ff5; break; //1111111110000100
+case 0x17 : *lenght=0x10; *out=0xff88; break; //1111111110000101
+case 0x18 : *lenght=0x10; *out=0xff89; break; //1111111110000110
+case 0x19 : *lenght=0x10; *out=0xff8a; break; //1111111110000111
+case 0x1A : *lenght=0x10; *out=0xff8b; break; //1111111110001000
+case 0x21 : *lenght=0x05; *out=0x001a; break; //11100
+case 0x22 : *lenght=0x08; *out=0x00f7; break; //11111001
+case 0x23 : *lenght=0x0a; *out=0x03f7; break; //1111110111
+case 0x24 : *lenght=0x0c; *out=0x0ff6; break; //111111110100
+case 0x25 : *lenght=0x0f; *out=0x7fc2; break; //1111111110001001
+case 0x26 : *lenght=0x10; *out=0xff8c; break; //1111111110001010
+case 0x27 : *lenght=0x10; *out=0xff8d; break; //1111111110001011
+case 0x28 : *lenght=0x10; *out=0xff8e; break; //1111111110001100
+case 0x29 : *lenght=0x10; *out=0xff8f; break; //1111111110001101
+case 0x2A : *lenght=0x10; *out=0xff90; break; //1111111110001110
+case 0x31 : *lenght=0x05; *out=0x001b; break; //111010
+case 0x32 : *lenght=0x08; *out=0x00f8; break; //111110111
+case 0x33 : *lenght=0x0a; *out=0x03f8; break; //111111110101
+case 0x34 : *lenght=0x0c; *out=0x0ff7; break; //1111111110001111
+case 0x35 : *lenght=0x10; *out=0xff91; break; //1111111110010000
+case 0x36 : *lenght=0x10; *out=0xff92; break; //1111111110010001
+case 0x37 : *lenght=0x10; *out=0xff93; break; //1111111110010010
+case 0x38 : *lenght=0x10; *out=0xff94; break; //1111111110010011
+case 0x39 : *lenght=0x10; *out=0xff95; break; //1111111110010100
+case 0x3A : *lenght=0x10; *out=0xff96; break; //1111111110010101
+case 0x41 : *lenght=0x06; *out=0x003a; break; //111011
+case 0x42 : *lenght=0x09; *out=0x01f6; break; //1111111000
+case 0x43 : *lenght=0x10; *out=0xff97; break; //1111111110010110
+case 0x44 : *lenght=0x10; *out=0xff98; break; //1111111110010111
+case 0x45 : *lenght=0x10; *out=0xff99; break; //1111111110011000
+case 0x46 : *lenght=0x10; *out=0xff9a; break; //1111111110011001
+case 0x47 : *lenght=0x10; *out=0xff9b; break; //1111111110011010
+case 0x48 : *lenght=0x10; *out=0xff9c; break; //1111111110011011
+case 0x49 : *lenght=0x10; *out=0xff9d; break; //1111111110011100
+case 0x4A : *lenght=0x10; *out=0xff9e; break; //1111111110011101
+case 0x51 : *lenght=0x06; *out=0x003b; break; //1111010
+case 0x52 : *lenght=0x0a; *out=0x03f9; break; //11111110111
+case 0x53 : *lenght=0x10; *out=0xff9f; break; //1111111110011110
+case 0x54 : *lenght=0x10; *out=0xffa0; break; //1111111110011111
+case 0x55 : *lenght=0x10; *out=0xffa1; break; //1111111110100000
+case 0x56 : *lenght=0x10; *out=0xFFA2; break; //1111111110100001
+case 0x57 : *lenght=0x10; *out=0xFFA3; break; //1111111110100010
+case 0x58 : *lenght=0x10; *out=0xFFA4; break; //1111111110100011
+case 0x59 : *lenght=0x10; *out=0xFFA5; break; //1111111110100100
+case 0x5A : *lenght=0x10; *out=0xFFA6; break; //1111111110100101
+case 0x61 : *lenght=0x07; *out=0x0079; break; //1111011
+case 0x62 : *lenght=0x0b; *out=0x07f7; break; //111111110110
+case 0x63 : *lenght=0x10; *out=0xffa7; break; //1111111110100110
+case 0x64 : *lenght=0x10; *out=0xffa8; break; //1111111110100111
+case 0x65 : *lenght=0x10; *out=0xffa9; break; //1111111110101000
+case 0x66 : *lenght=0x10; *out=0xffaa; break; //1111111110101001
+case 0x67 : *lenght=0x10; *out=0xffab; break; //1111111110101010
+case 0x68 : *lenght=0x10; *out=0xFFAc; break; //1111111110101011
+case 0x69 : *lenght=0x10; *out=0xFFAf; break; //1111111110101100
+case 0x6A : *lenght=0x10; *out=0xFFAe; break; //1111111110101101
+case 0x71 : *lenght=0x07; *out=0x007a; break; //11111010
+case 0x72 : *lenght=0x0b; *out=0x07f8; break; //111111110111
+case 0x73 : *lenght=0x10; *out=0xffaf; break; //1111111110101110
+case 0x74 : *lenght=0x10; *out=0xffb0; break; //1111111110101111
+case 0x75 : *lenght=0x10; *out=0xFFB1; break; //1111111110110000
+case 0x76 : *lenght=0x10; *out=0xFFB2; break; //111111110110001
+case 0x77 : *lenght=0x10; *out=0xFFB3; break; //111111110110010
+case 0x78 : *lenght=0x10; *out=0xFFB4; break; //111111110110011
+case 0x79 : *lenght=0x10; *out=0xFFB5; break; //1111111110110100
+case 0x7A : *lenght=0x10; *out=0xFFB6; break; //1111111110110101
+case 0x81 : *lenght=0x08; *out=0x00f9; break; //111111000
+case 0x82 : *lenght=0x10; *out=0xffb7; break; //111111111000000
+case 0x83 : *lenght=0x10; *out=0xFFB8; break; //1111111110110110
+case 0x84 : *lenght=0x10; *out=0xFFB9; break; //1111111110110111
+case 0x85 : *lenght=0x10; *out=0xFFBa; break; //1111111110111000
+case 0x86 : *lenght=0x10; *out=0xFFBb; break; //1111111110111001
+case 0x87 : *lenght=0x10; *out=0xFFBc; break; //1111111110111010
+case 0x88 : *lenght=0x10; *out=0xFFBd; break; //1111111110111011
+case 0x89 : *lenght=0x10; *out=0xFFBe; break; //1111111110111100
+case 0x8A : *lenght=0x10; *out=0xFFBf; break; //1111111110111101
+case 0x91 : *lenght=0x09; *out=0x01f7; break; //111111001
+case 0x92 : *lenght=0x10; *out=0xffc0; break; //1111111110111110
+case 0x93 : *lenght=0x10; *out=0xffc1; break; //1111111110111111
+case 0x94 : *lenght=0x10; *out=0xFFC2; break; //1111111111000000
+case 0x95 : *lenght=0x10; *out=0xFFC3; break; //1111111111000001
+case 0x96 : *lenght=0x10; *out=0xFFC4; break; //1111111111000010
+case 0x97 : *lenght=0x10; *out=0xFFC5; break; //1111111111000011
+case 0x98 : *lenght=0x10; *out=0xFFC6; break; //1111111111000100
+case 0x99 : *lenght=0x10; *out=0xFFC7; break; //1111111111000101
+case 0x9A : *lenght=0x10; *out=0xFFC8; break; //1111111111000110
+case 0xA1 : *lenght=0x09; *out=0x01f8; break; //111111010
+case 0xA2 : *lenght=0x10; *out=0xffc9; break; //1111111111000111
+case 0xA3 : *lenght=0x10; *out=0xFFCa; break; //1111111111001000
+case 0xA4 : *lenght=0x10; *out=0xFFCb; break; //1111111111001001
+case 0xA5 : *lenght=0x10; *out=0xFFCc; break; //1111111111001010
+case 0xA6 : *lenght=0x10; *out=0xFFCd; break; //1111111111001011
+case 0xA7 : *lenght=0x10; *out=0xFFCe; break; //1111111111001100
+case 0xA8 : *lenght=0x10; *out=0xFFCf; break; //1111111111001101
+case 0xA9 : *lenght=0x10; *out=0xFFd0; break; //1111111111001110
+case 0xAA : *lenght=0x10; *out=0xFFd1; break; //1111111111001111
+case 0xB1 : *lenght=0x09; *out=0x01f9; break; //1111111001
+case 0xB2 : *lenght=0x10; *out=0xFFD2; break; //1111111111010000
+case 0xB3 : *lenght=0x10; *out=0xFFD3; break; //1111111111010001
+case 0xB4 : *lenght=0x10; *out=0xFFD4; break; //1111111111010010
+case 0xB5 : *lenght=0x10; *out=0xFFD5; break; //1111111111010011
+case 0xB6 : *lenght=0x10; *out=0xFFD6; break; //1111111111010100
+case 0xB7 : *lenght=0x10; *out=0xFFD7; break; //1111111111010101
+case 0xB8 : *lenght=0x10; *out=0xFFD8; break; //1111111111010110
+case 0xB9 : *lenght=0x10; *out=0xFFD9; break; //1111111111010111
+case 0xBA : *lenght=0x10; *out=0xFFDa; break; //1111111111011000
+case 0xC1 : *lenght=0x09; *out=0x01fa; break; //1111111010
+case 0xC2 : *lenght=0x10; *out=0xFFDb; break; //1111111111011001
+case 0xC3 : *lenght=0x10; *out=0xFFDc; break; //1111111111011010
+case 0xC4 : *lenght=0x10; *out=0xFFDd; break; //1111111111011011
+case 0xC5 : *lenght=0x10; *out=0xFFDe; break; //1111111111011100
+case 0xC6 : *lenght=0x10; *out=0xFFDf; break; //1111111111011101
+case 0xC7 : *lenght=0x10; *out=0xFFe0; break; //1111111111011110
+case 0xC8 : *lenght=0x10; *out=0xFFe1; break; //1111111111011111
+case 0xC9 : *lenght=0x10; *out=0xFFe2; break; //1111111111100000
+case 0xCA : *lenght=0x10; *out=0xFFe3; break; //1111111111100001
+case 0xD1 : *lenght=0x0b; *out=0x07f9; break; //11111111000
+case 0xD2 : *lenght=0x10; *out=0xFFE4; break; //1111111111100010
+case 0xD3 : *lenght=0x10; *out=0xFFE5; break; //1111111111100011
+case 0xD4 : *lenght=0x10; *out=0xFFE6; break; //1111111111100100
+case 0xD5 : *lenght=0x10; *out=0xFFE7; break; //1111111111100101
+case 0xD6 : *lenght=0x10; *out=0xFFE8; break; //1111111111100110
+case 0xD7 : *lenght=0x10; *out=0xFFE9; break; //1111111111100111
+case 0xD8 : *lenght=0x10; *out=0xFFEa; break; //1111111111101000
+case 0xD9 : *lenght=0x10; *out=0xFFEb; break; //1111111111101001
+case 0xDA : *lenght=0x10; *out=0xFFEc; break; //1111111111101010
+case 0xE1 : *lenght=0x0e; *out=0x3fe0; break; //1111111111101011
+case 0xE2 : *lenght=0x10; *out=0xffed; break; //1111111111101100
+case 0xE3 : *lenght=0x10; *out=0xFFEe; break; //1111111111101101
+case 0xE4 : *lenght=0x10; *out=0xFFEf; break; //1111111111101110
+case 0xE5 : *lenght=0x10; *out=0xFFf0; break; //1111111111101111
+case 0xE6 : *lenght=0x10; *out=0xFFF1; break; //1111111111110000
+case 0xE7 : *lenght=0x10; *out=0xFFF2; break; //1111111111110001
+case 0xE8 : *lenght=0x10; *out=0xFFF3; break; //1111111111110010
+case 0xE9 : *lenght=0x10; *out=0xFFF4; break; //1111111111110011
+case 0xEA : *lenght=0x10; *out=0xFFF5; break; //1111111111110100
+case 0xF0 : *lenght=0x0a; *out=0x03fa; break; //11111111001
+case 0xF1 : *lenght=0x0f; *out=0x7fc3; break; //1111111111110101
+case 0xF2 : *lenght=0x10; *out=0xFFF6; break; //1111111111110110
+case 0xF3 : *lenght=0x10; *out=0xFFF7; break; //1111111111110111
+case 0xF4 : *lenght=0x10; *out=0xFFF8; break; //1111111111111000
+case 0xF5 : *lenght=0x10; *out=0xFFF9; break; //1111111111111001
+case 0xF6 : *lenght=0x10; *out=0xFFFA; break; //1111111111111010
+case 0xF7 : *lenght=0x10; *out=0xFFFB; break; //1111111111111011
+case 0xF8 : *lenght=0x10; *out=0xFFFC; break; //1111111111111100
+case 0xF9 : *lenght=0x10; *out=0xFFFD; break; //1111111111111101
+case 0xFA : *lenght=0x10; *out=0xFFFE; break; //1111111111111110
+#ifndef __MICROBLAZE
+default : printf("WAARDE STAAT NIET IN TABEL!!!!!!!!!!!!!!!!!!!!\n");break;
+#endif
+ }
+ // printf("magnitude= %x out= %x lenght= %d \n",magnitude,*out,*lenght);
+ return;
+}
+//===========================================================================
+void ConvertDCMagnitudeY(unsigned char magnitude,unsigned short int *out, unsigned short int *lenght)
+{
+ switch (magnitude) {
+ case 0x00 : *out=0x0000; *lenght=2; break;
+ case 0x01 : *out=0x0002; *lenght=3; break;
+ case 0x02 : *out=0x0003; *lenght=3; break;
+ case 0x03 : *out=0x0004; *lenght=3; break;
+ case 0x04 : *out=0x0005; *lenght=3; break;
+ case 0x05 : *out=0x0006; *lenght=3; break;
+ case 0x06 : *out=0x000e; *lenght=4; break;
+ case 0x07 : *out=0x001e; *lenght=5; break;
+ case 0x08 : *out=0x003e; *lenght=6; break;
+ case 0x09 : *out=0x007e; *lenght=7; break;
+ case 0x0a : *out=0x00fe; *lenght=8; break;
+ case 0x0b : *out=0x01fe; *lenght=9; break;
+ }
+}
+//===========================================================================
+void ConvertACMagnitudeY(unsigned char magnitude,unsigned short int *out, unsigned short int *lenght)
+{
+ switch (magnitude) {
+case 0x00 : *lenght=4; *out=0xFFFA; break; //1010
+case 0x01 : *lenght=2; *out=0xFFF0; break; //00
+case 0x02 : *lenght=2; *out=0xFFF1; break; //01
+case 0x03 : *lenght=3; *out=0xFFF4; break; //100
+case 0x04 : *lenght=4; *out=0xFFFB; break; //1011
+case 0x05 : *lenght=5; *out=0xFFFA; break; //11010
+case 0x06 : *lenght=7; *out=0xFFF8; break; //1111000
+case 0x07 : *lenght=8; *out=0xFFF8; break; //11111000
+case 0x08 : *lenght=10; *out=0xFFF6; break; //1111110110
+case 0x09 : *lenght=16; *out=0xFF82; break; //1111111110000010
+case 0x0A : *lenght=16; *out=0xFF83; break; //1111111110000011
+case 0x11 : *lenght=4; *out=0xFFFC; break; //1100
+case 0x12 : *lenght=5; *out=0xFFFB; break; //11011
+case 0x13 : *lenght=7; *out=0xFFF9; break; //1111001
+case 0x14 : *lenght=9; *out=0xFFF6; break; //111110110
+case 0x15 : *lenght=11; *out=0xFFF6; break; //11111110110
+case 0x16 : *lenght=16; *out=0xFF84; break; //1111111110000100
+case 0x17 : *lenght=16; *out=0xFF85; break; //1111111110000101
+case 0x18 : *lenght=16; *out=0xFF86; break; //1111111110000110
+case 0x19 : *lenght=16; *out=0xFF87; break; //1111111110000111
+case 0x1A : *lenght=16; *out=0xFF88; break; //1111111110001000
+case 0x21 : *lenght=5; *out=0xFFFC; break; //11100
+case 0x22 : *lenght=8; *out=0xFFF9; break; //11111001
+case 0x23 : *lenght=10; *out=0xFFF7; break; //1111110111
+case 0x24 : *lenght=12; *out=0xFFF4; break; //111111110100
+case 0x25 : *lenght=16; *out=0xFF89; break; //1111111110001001
+case 0x26 : *lenght=16; *out=0xFF8A; break; //1111111110001010
+case 0x27 : *lenght=16; *out=0xFF8B; break; //1111111110001011
+case 0x28 : *lenght=16; *out=0xFF8C; break; //1111111110001100
+case 0x29 : *lenght=16; *out=0xFF8D; break; //1111111110001101
+case 0x2A : *lenght=16; *out=0xFF8E; break; //1111111110001110
+case 0x31 : *lenght=6; *out=0xFFFA; break; //111010
+case 0x32 : *lenght=9; *out=0xFFF7; break; //111110111
+case 0x33 : *lenght=12; *out=0xFFF5; break; //111111110101
+case 0x34 : *lenght=16; *out=0xFF8F; break; //1111111110001111
+case 0x35 : *lenght=16; *out=0xFF90; break; //1111111110010000
+case 0x36 : *lenght=16; *out=0xFF91; break; //1111111110010001
+case 0x37 : *lenght=16; *out=0xFF92; break; //1111111110010010
+case 0x38 : *lenght=16; *out=0xFF93; break; //1111111110010011
+case 0x39 : *lenght=16; *out=0xFF94; break; //1111111110010100
+case 0x3A : *lenght=16; *out=0xFF95; break; //1111111110010101
+case 0x41 : *lenght=6; *out=0xFFFB; break; //111011
+case 0x42 : *lenght=10; *out=0xFFF8; break; //1111111000
+case 0x43 : *lenght=16; *out=0xFF96; break; //1111111110010110
+case 0x44 : *lenght=16; *out=0xFF97; break; //1111111110010111
+case 0x45 : *lenght=16; *out=0xFF98; break; //1111111110011000
+case 0x46 : *lenght=16; *out=0xFF99; break; //1111111110011001
+case 0x47 : *lenght=16; *out=0xFF9A; break; //1111111110011010
+case 0x48 : *lenght=16; *out=0xFF9B; break; //1111111110011011
+case 0x49 : *lenght=16; *out=0xFF9C; break; //1111111110011100
+case 0x4A : *lenght=16; *out=0xFF9D; break; //1111111110011101
+case 0x51 : *lenght=7; *out=0xFFFA; break; //1111010
+case 0x52 : *lenght=11; *out=0xFFF7; break; //11111110111
+case 0x53 : *lenght=16; *out=0xFF9E; break; //1111111110011110
+case 0x54 : *lenght=16; *out=0xFF9F; break; //1111111110011111
+case 0x55 : *lenght=16; *out=0xFFA0; break; //1111111110100000
+case 0x56 : *lenght=16; *out=0xFFA1; break; //1111111110100001
+case 0x57 : *lenght=16; *out=0xFFA2; break; //1111111110100010
+case 0x58 : *lenght=16; *out=0xFFA3; break; //1111111110100011
+case 0x59 : *lenght=16; *out=0xFFA4; break; //1111111110100100
+case 0x5A : *lenght=16; *out=0xFFA5; break; //1111111110100101
+case 0x61 : *lenght=7; *out=0xFFFB; break; //1111011
+case 0x62 : *lenght=12; *out=0xFFF6; break; //111111110110
+case 0x63 : *lenght=16; *out=0xFFA6; break; //1111111110100110
+case 0x64 : *lenght=16; *out=0xFFA7; break; //1111111110100111
+case 0x65 : *lenght=16; *out=0xFFA8; break; //1111111110101000
+case 0x66 : *lenght=16; *out=0xFFA9; break; //1111111110101001
+case 0x67 : *lenght=16; *out=0xFFAA; break; //1111111110101010
+case 0x68 : *lenght=16; *out=0xFFAB; break; //1111111110101011
+case 0x69 : *lenght=16; *out=0xFFAC; break; //1111111110101100
+case 0x6A : *lenght=16; *out=0xFFAD; break; //1111111110101101
+case 0x71 : *lenght=8; *out=0xFFFA; break; //11111010
+case 0x72 : *lenght=12; *out=0xFFF7; break; //111111110111
+case 0x73 : *lenght=16; *out=0xFFAE; break; //1111111110101110
+case 0x74 : *lenght=16; *out=0xFFAF; break; //1111111110101111
+case 0x75 : *lenght=16; *out=0xFFB0; break; //1111111110110000
+case 0x76 : *lenght=16; *out=0xFFB1; break; //111111110110001
+case 0x77 : *lenght=16; *out=0xFFB2; break; //111111110110010
+case 0x78 : *lenght=16; *out=0xFFB3; break; //111111110110011
+case 0x79 : *lenght=16; *out=0xFFB4; break; //1111111110110100
+case 0x7A : *lenght=16; *out=0xFFB5; break; //1111111110110101
+case 0x81 : *lenght=9; *out=0xFFF8; break; //111111000
+case 0x82 : *lenght=15; *out=0xFFC0; break; //111111111000000
+case 0x83 : *lenght=16; *out=0xFFB6; break; //1111111110110110
+case 0x84 : *lenght=16; *out=0xFFB7; break; //1111111110110111
+case 0x85 : *lenght=16; *out=0xFFB8; break; //1111111110111000
+case 0x86 : *lenght=16; *out=0xFFB9; break; //1111111110111001
+case 0x87 : *lenght=16; *out=0xFFBA; break; //1111111110111010
+case 0x88 : *lenght=16; *out=0xFFBB; break; //1111111110111011
+case 0x89 : *lenght=16; *out=0xFFBC; break; //1111111110111100
+case 0x8A : *lenght=16; *out=0xFFBD; break; //1111111110111101
+case 0x91 : *lenght=9; *out=0xFFF9; break; //111111001
+case 0x92 : *lenght=16; *out=0xFFBE; break; //1111111110111110
+case 0x93 : *lenght=16; *out=0xFFBF; break; //1111111110111111
+case 0x94 : *lenght=16; *out=0xFFC0; break; //1111111111000000
+case 0x95 : *lenght=16; *out=0xFFC1; break; //1111111111000001
+case 0x96 : *lenght=16; *out=0xFFC2; break; //1111111111000010
+case 0x97 : *lenght=16; *out=0xFFC3; break; //1111111111000011
+case 0x98 : *lenght=16; *out=0xFFC4; break; //1111111111000100
+case 0x99 : *lenght=16; *out=0xFFC5; break; //1111111111000101
+case 0x9A : *lenght=16; *out=0xFFC6; break; //1111111111000110
+case 0xA1 : *lenght=9; *out=0xFFFA; break; //111111010
+case 0xA2 : *lenght=16; *out=0xFFC7; break; //1111111111000111
+case 0xA3 : *lenght=16; *out=0xFFC8; break; //1111111111001000
+case 0xA4 : *lenght=16; *out=0xFFC9; break; //1111111111001001
+case 0xA5 : *lenght=16; *out=0xFFCA; break; //1111111111001010
+case 0xA6 : *lenght=16; *out=0xFFCB; break; //1111111111001011
+case 0xA7 : *lenght=16; *out=0xFFCC; break; //1111111111001100
+case 0xA8 : *lenght=16; *out=0xFFCD; break; //1111111111001101
+case 0xA9 : *lenght=16; *out=0xFFCE; break; //1111111111001110
+case 0xAA : *lenght=16; *out=0xFFCF; break; //1111111111001111
+case 0xB1 : *lenght=10; *out=0xFFF9; break; //1111111001
+case 0xB2 : *lenght=16; *out=0xFFD0; break; //1111111111010000
+case 0xB3 : *lenght=16; *out=0xFFD1; break; //1111111111010001
+case 0xB4 : *lenght=16; *out=0xFFD2; break; //1111111111010010
+case 0xB5 : *lenght=16; *out=0xFFD3; break; //1111111111010011
+case 0xB6 : *lenght=16; *out=0xFFD4; break; //1111111111010100
+case 0xB7 : *lenght=16; *out=0xFFD5; break; //1111111111010101
+case 0xB8 : *lenght=16; *out=0xFFD6; break; //1111111111010110
+case 0xB9 : *lenght=16; *out=0xFFD7; break; //1111111111010111
+case 0xBA : *lenght=16; *out=0xFFD8; break; //1111111111011000
+case 0xC1 : *lenght=10; *out=0xFFFA; break; //1111111010
+case 0xC2 : *lenght=16; *out=0xFFD9; break; //1111111111011001
+case 0xC3 : *lenght=16; *out=0xFFDA; break; //1111111111011010
+case 0xC4 : *lenght=16; *out=0xFFDB; break; //1111111111011011
+case 0xC5 : *lenght=16; *out=0xFFDC; break; //1111111111011100
+case 0xC6 : *lenght=16; *out=0xFFDD; break; //1111111111011101
+case 0xC7 : *lenght=16; *out=0xFFDE; break; //1111111111011110
+case 0xC8 : *lenght=16; *out=0xFFDF; break; //1111111111011111
+case 0xC9 : *lenght=16; *out=0xFFE0; break; //1111111111100000
+case 0xCA : *lenght=16; *out=0xFFE1; break; //1111111111100001
+case 0xD1 : *lenght=11; *out=0xFFF8; break; //11111111000
+case 0xD2 : *lenght=16; *out=0xFFE2; break; //1111111111100010
+case 0xD3 : *lenght=16; *out=0xFFE3; break; //1111111111100011
+case 0xD4 : *lenght=16; *out=0xFFE4; break; //1111111111100100
+case 0xD5 : *lenght=16; *out=0xFFE5; break; //1111111111100101
+case 0xD6 : *lenght=16; *out=0xFFE6; break; //1111111111100110
+case 0xD7 : *lenght=16; *out=0xFFE7; break; //1111111111100111
+case 0xD8 : *lenght=16; *out=0xFFE8; break; //1111111111101000
+case 0xD9 : *lenght=16; *out=0xFFE9; break; //1111111111101001
+case 0xDA : *lenght=16; *out=0xFFEA; break; //1111111111101010
+case 0xE1 : *lenght=16; *out=0xFFEB; break; //1111111111101011
+case 0xE2 : *lenght=16; *out=0xFFEC; break; //1111111111101100
+case 0xE3 : *lenght=16; *out=0xFFED; break; //1111111111101101
+case 0xE4 : *lenght=16; *out=0xFFEE; break; //1111111111101110
+case 0xE5 : *lenght=16; *out=0xFFEF; break; //1111111111101111
+case 0xE6 : *lenght=16; *out=0xFFF0; break; //1111111111110000
+case 0xE7 : *lenght=16; *out=0xFFF1; break; //1111111111110001
+case 0xE8 : *lenght=16; *out=0xFFF2; break; //1111111111110010
+case 0xE9 : *lenght=16; *out=0xFFF3; break; //1111111111110011
+case 0xEA : *lenght=16; *out=0xFFF4; break; //1111111111110100
+case 0xF0 : *lenght=11; *out=0xFFF9; break; //11111111001
+case 0xF1 : *lenght=16; *out=0xFFF5; break; //1111111111110101
+case 0xF2 : *lenght=16; *out=0xFFF6; break; //1111111111110110
+case 0xF3 : *lenght=16; *out=0xFFF7; break; //1111111111110111
+case 0xF4 : *lenght=16; *out=0xFFF8; break; //1111111111111000
+case 0xF5 : *lenght=16; *out=0xFFF9; break; //1111111111111001
+case 0xF6 : *lenght=16; *out=0xFFFA; break; //1111111111111010
+case 0xF7 : *lenght=16; *out=0xFFFB; break; //1111111111111011
+case 0xF8 : *lenght=16; *out=0xFFFC; break; //1111111111111100
+case 0xF9 : *lenght=16; *out=0xFFFD; break; //1111111111111101
+case 0xFA : *lenght=16; *out=0xFFFE; break; //1111111111111110
+#ifndef __MICROBLAZE
+default : printf("WAARDE STAAT NIET IN TABEL!!!!!!!!!!!!!!!!!!!!\n");break;
+#endif
+ }
+ // printf("magnitude= %x out= %x lenght= %d \n",magnitude,*out,*lenght);
+ return;
+}
+//===========================================================================
+char Extend (char additional, unsigned char magnitude)
+{
+ int vt= 1 << (magnitude-1);
+ if ( additional < vt ) return (additional + (-1 << magnitude) + 1);
+ else return additional;
+}
+//===========================================================================
+void ReverseExtend (char value, unsigned char *magnitude, unsigned char *bits)
+{
+ // printf("reverseextend value= %d\n",*magnitude);
+ if (value >=0)
+ {
+ *bits=value;
+ }
+ else
+ {
+ value=-value;
+ *bits=~value;
+ }
+ *magnitude=0;
+ while (value !=0)
+ {
+ value>>=1;
+ ++*magnitude;
+ }
+ // printf("reverseextend magnitude= %d bits= %d",magnitude,bits);
+ return;
+}
+
+static int __count3=0;
+
+//===========================================================================
+void WriteRawBits16(unsigned char amount_bits, unsigned int bits, unsigned int *remaining,unsigned char *amount_remaining, FILE* file) //*remaining needs bo be more than 8 bits because 8 bits could be added and ther ecould already be up ot 7 bits in *remaining
+// this function collects bits to send
+// if there less than 16 bits collected, nothing is send and these bits are stored in *remaining. In *amount_remaining there is stated how much bits are stored in *remaining
+// if more than 16 bits are collected, 16 bits are send and the remaining bits are stored again
+{
+ unsigned short int send;
+ unsigned int mask;
+ unsigned char send2;
+ int count;
+
+ #ifdef __MICROBLAZE
+ if (__count3<16) {
+ xil_printf("%x %x, ", amount_bits, bits);
+ __count3++;
+ if ((__count3&0x07)==0) xil_printf("\r\n");
+ }
+#else
+ if (__count3<16) {
+ printf(" %x %x, ", amount_bits, bits);
+ __count3++;
+ if ((__count3&0x07)==0) printf("\r\n");
+ }
+#endif
+
+
+ mask=0x00; //init mask
+ *remaining=(*remaining<0; count--) mask=(mask<<1)|0x01; //create mask for adding bit
+ *remaining=*remaining | (bits&mask); //add bits
+ *amount_remaining=*amount_remaining + amount_bits; //change *amount_remaining to the correct new value
+ if (*amount_remaining >= 16) //are there more than 16 bits in buffer, send 16 bits
+ {
+
+#ifndef __MICROBLAZE
+if (*amount_remaining >= 32 ) printf("ERROR, more bits to send %d",*amount_remaining);
+#endif
+
+ send=*remaining>>(*amount_remaining-16); //this value can be send/stored (in art this can be dony by selecting bits)
+ send2=(send & 0xFF00) >>8;
+#ifdef __MICROBLAZE
+ sysace_fwrite(&send2,1,1,file);
+#else
+ fwrite(&send2,1,1,file);
+#endif
+ if (send2==0xFF)
+ {
+ send2=0x00;
+#ifdef __MICROBLAZE
+ sysace_fwrite(&send2,1,1,file);
+#else
+ fwrite(&send2,1,1,file);
+#endif
+ }
+ send2=send & 0xFF;
+#ifdef __MICROBLAZE
+ sysace_fwrite(&send2,1,1,file);
+#else
+ fwrite(&send2,1,1,file);
+#endif
+ if (send2==0xFF)
+ {
+ send2=0x00;
+#ifdef __MICROBLAZE
+ sysace_fwrite(&send2,1,1,file);
+#else
+ fwrite(&send2,1,1,file);
+#endif
+ }
+ *amount_remaining=*amount_remaining-16; //descrease by 16 because these are send
+ }
+ return;
+}
+//===========================================================================
+void HuffmanEncodeFinishSend(unsigned int *remaining,unsigned char *amount_remaining, FILE* file)
+// There are still some bits left to send at the end of the 8x8 matrix (or maybe the file),
+// the remaining bits are filled up with ones and send
+// possible fault: -must it be filled up with ones?
+{
+ unsigned short int send;
+ unsigned int mask;
+ int count;
+ mask=0x00; //init mask
+ if (*amount_remaining >= 8) // //2 bytes to send, send first byte
+ {
+ send=*remaining>>(*amount_remaining-8); //shift so that first byte is ready to send
+#ifdef __MICROBLAZE
+ sysace_fwrite(&send,1,1,file);
+#else
+ fwrite(&send,1,1,file);
+#endif
+ if (send==0xFF) //is this still needed????
+ {
+ send=0x00;
+#ifdef __MICROBLAZE
+ sysace_fwrite(&send,1,1,file);
+#else
+ fwrite(&send,1,1,file);
+ #endif
+ }
+ *amount_remaining=*amount_remaining -8; // lower the value to the amount of bits that still needs to be send
+ }
+ if (*amount_remaining >= 0) //there is a last byte to send
+ {
+ send=*remaining<<(8-*amount_remaining); //shift the last bits to send to the front of the byte
+ mask=0x00; //init mask
+ for (count=(8-*amount_remaining); count>0; count--) mask=(mask<<1)|0x01; //create mask to fill byte up with ones
+ send=send | mask; //add the ones to the byte
+#ifdef __MICROBLAZE
+ sysace_fwrite(&send,1,1,file);
+#else
+ fwrite(&send,1,1,file);
+#endif
+ *amount_remaining=0x00; //is this needed?
+ }
+ return;
+}
+//===========================================================================
+void HuffmanEncodeUsingDCTable(unsigned char magnitude,unsigned int *remaining,unsigned char *amount_remaining, FILE* file)
+// Translate magnitude into needed data (from table) and send it
+{
+ unsigned char send;
+ unsigned short int huffmancode, huffmanlengt;
+ ConvertDCMagnitudeY(magnitude, &huffmancode, &huffmanlengt);
+ WriteRawBits16(huffmanlengt,huffmancode,remaining,amount_remaining, file);
+ //printf("Write DC magnitude= %2x \n",magnitude);
+ //WriteRawBits16(0x08,magnitude,remaining,amount_remaining, file);
+ return;
+}
+//===========================================================================
+void HuffmanEncodeUsingACTable(unsigned char mag,unsigned int *remaining,unsigned char *amount_remaining, FILE* file)
+// Translate magnitude into needed data (from table) and send it
+{
+ unsigned char send;
+ unsigned short int huffmancode, huffmanlengt;
+ ConvertACMagnitudeY(mag, &huffmancode, &huffmanlengt);
+ WriteRawBits16(huffmanlengt,huffmancode,remaining,amount_remaining, file);
+ return;
+}
+//===========================================================================
+char EncodeDataUnit(char dataunit[64], char last_dc_value, FILE* file, unsigned int *remaining, unsigned char *amount_remaining, unsigned int color)
+{
+ char difference;
+ unsigned char magnitude,zerorun,ii,ert;
+ unsigned int bits;
+ unsigned char bits_char;
+ //init
+ // PrintMatrix(dataunit) ;
+ difference = dataunit[0] - last_dc_value;
+ last_dc_value=dataunit[0];
+ ReverseExtend(difference, &magnitude,&bits_char);
+ bits=bits_char;
+ HuffmanEncodeUsingDCTable(magnitude,remaining,amount_remaining, file);
+ WriteRawBits16(magnitude,bits,remaining,amount_remaining, file);
+ zerorun=0;
+ ii=1;
+ while ( ii < 64 )
+ {
+ if (dataunit[ii] != 0 )
+ {
+ while ( zerorun >= 16 )
+ {
+ HuffmanEncodeUsingACTable(0xF0,remaining,amount_remaining,file);
+ zerorun=zerorun-16;
+ // printf("16 zeros: %d\n",zerorun);
+ }
+ ReverseExtend(dataunit[ii],&magnitude,&bits_char);
+ bits=bits_char;
+ ert= ((int)zerorun *16); //ERROR !!!!!!!!!!!
+ ert=ert + magnitude;
+ HuffmanEncodeUsingACTable(ert,remaining,amount_remaining,file);
+ WriteRawBits16(magnitude,bits,remaining,amount_remaining, file);
+ zerorun=0;
+ }
+ else zerorun=zerorun+1;
+ ii++;
+ }
+ if ( zerorun != 0 )
+ {
+ HuffmanEncodeUsingACTable(0x00,remaining,amount_remaining,file);
+// printf("NUL DE REST IS NUL\n");
+ }
+ // HuffmanEncodeFinishSend(remaining,amount_remaining,file);
+ return last_dc_value;
+}
+
+#if 0
+//===========================================================================
+void DecodeDataUnit(char *coefficients[64], char last_dc_value, char value)
+{
+ char ii;
+ char lowbits,highbits,extrabits;
+ //decode DC
+
+
+ //decode AC
+ //set coefficients to 0
+ for (ii=0;ii<64;ii++) *coefficients[ii]=0x00; //for the next optimu\ization step: don't write 0 before beginning, these value are overwritten. Only write 0 is you know tha value is 0, now you only write each value once, not twice is the value ain't 0.
+ while (ii<64)
+ {
+// value= DecodeUsingACTable();
+ lowbits = value && 0x0F;
+ highbits = (value && 0xF0 ) >>4;
+
+ if (lowbits != 0x00)
+ {
+// extrabits = ReadRawBits(lowbits);
+ ii=ii+highbits;
+ *coefficients[ii]=Extend(extrabits,lowbits);
+ ii++;
+ }
+ else
+ {
+ if (highbits==0xF) ii=ii+16; //run of 16 zeros
+ else if (highbits == 0x0) ii=64; //the rest are zeros
+ }
+ }
+}
+//===========================================================================
+#endif
+
+
Index: main.c
===================================================================
--- main.c (nonexistent)
+++ main.c (revision 66)
@@ -0,0 +1,305 @@
+#ifdef __MICROBLAZE
+
+#include
+#include
+
+#include "xup2pro.h"
+
+#include "zzq.h"
+#include "io.h"
+#include "huffman.h"
+#include "dct.h"
+
+char* bmpimage;
+int bmpsize;
+
+INFOHEADER _bmpheader;
+
+static signed char pixelmatrix[MATRIX_SIZE][MATRIX_SIZE*3],YMatrix[MATRIX_SIZE][MATRIX_SIZE],CrMatrix[MATRIX_SIZE][MATRIX_SIZE],CbMatrix[MATRIX_SIZE][MATRIX_SIZE];
+static signed short temp[MATRIX_SIZE][MATRIX_SIZE], dctresult[MATRIX_SIZE][MATRIX_SIZE];
+static signed char output[MATRIX_SIZE][MATRIX_SIZE];
+static signed char bitstream[NUMBER_OF_PIXELS] ;
+static unsigned char header[389];
+
+int ejpgl_error(int errno, void* remark);
+
+int main()
+{
+ SYSACE_FILE *infile;
+ SYSACE_FILE *outfile;
+ SYSACE_FILE* outfile2;
+
+ int i;
+ INFOHEADER *bmpheader;
+ JPEGHEADER *jpegheader;
+ unsigned int col, cols, row, rows, remaining,component;
+ unsigned char amount_remaining, Ydcvalue, Cbdcvalue, Crdcvalue ;
+ int encode, compression;
+
+ encode = 1;
+ compression = 0;
+
+ bmpimage=(unsigned char*)0x70000000;
+ bmpsize=0;
+
+ xil_printf("\r\nBMP2JPG Code Compiled at %s %s\r\n", __DATE__, __TIME__);
+
+ bmpheader=&_bmpheader;
+
+ if ((infile = sysace_fopen("image01.bmp", "r")) == NULL) {
+ ejpgl_error(eOPENINPUT_FILE, 0);
+ }
+
+ bmpsize = sysace_fread(bmpimage, 1, 65536, infile);
+ xil_printf("bmpsize %d\r\n", bmpsize);
+ if (bmpsize==65536) {
+ ejpgl_error(eLARGE_INPUTFILE, 0);
+ }
+
+ if ((outfile2 = sysace_fopen("image01b.bmp", "w")) == NULL) {
+ ejpgl_error(eOPENOUTPUT_FILE, 0);
+ }
+ sysace_fwrite(bmpimage, 1, bmpsize, outfile2);
+ sysace_fclose(outfile2);
+
+ if (getbmpheader(infile,bmpheader) == 0) { //File is a valid BMP
+ ejpgl_error(eINVALID_BMP, 0);
+ }
+
+ xil_printf("Image width: %d pixels\r\n", bmpheader->width);
+ xil_printf("Image height: %d pixels\r\n", bmpheader->height);
+
+ rows = bmpheader->height>>3;
+ cols = bmpheader->width>>3;
+ remaining=0x00;
+ amount_remaining=0x00;
+ Ydcvalue = 0x00;
+ Crdcvalue = 0x00;
+ Cbdcvalue = 0x00;
+
+ if ((outfile = sysace_fopen("image01.jpg", "w")) == NULL) {
+ ejpgl_error(eOPENOUTPUT_FILE, 0);
+ }
+
+ writejpegheader(outfile,bmpheader);
+
+ for (row = 0; row < rows; row++) {
+ for (col = 0; col < cols; col++) {
+ readbmpfile(infile,pixelmatrix,row,col,bmpheader);
+ RGB2YCrCb(pixelmatrix,YMatrix,CrMatrix,CbMatrix);
+ for(component=0;component<3;component++) {
+ switch (component) {
+ case 0 ://Y-encoding
+ dct(YMatrix,dctresult);
+ zzq(dctresult,bitstream,compression,encode);
+ Ydcvalue = EncodeDataUnit(bitstream,Ydcvalue,outfile, &remaining, &amount_remaining,component);
+ break;
+ case 1 ://Cr-encoding
+ dct(CrMatrix,dctresult);
+ zzq(dctresult,bitstream,compression,encode);
+ Crdcvalue = EncodeDataUnit(bitstream,Crdcvalue,outfile, &remaining, &amount_remaining,component);
+ break;
+ case 2 ://Cb-encoding
+ dct(CbMatrix,dctresult);
+ zzq(dctresult,bitstream,compression,encode);
+ Cbdcvalue = EncodeDataUnit(bitstream,Cbdcvalue,outfile, &remaining, &amount_remaining,component);
+ break;
+ }
+ }
+ }
+ }
+ HuffmanEncodeFinishSend(&remaining,&amount_remaining,outfile);
+ xil_printf("\r\nProcessed %d %dx%d-blocks.\r\n",(row-1)*cols+col,MATRIX_SIZE,MATRIX_SIZE);
+ writejpegfooter(outfile);
+
+
+ sysace_fclose(outfile);
+ sysace_fclose(infile);
+ return 0;
+
+}
+
+int ejpgl_error(int errno, void* remark) {
+
+ xil_printf("--> Error %d\r\n", errno);
+ exit(1);
+
+}
+
+
+
+#else
+
+//---------------------------------------------------------------------------
+typedef union { /* block of pixel-space values */
+ unsigned char block[8][8];
+ unsigned char linear[64];
+} PBlock;
+
+typedef union { /* block of frequency-space values */
+ int block[8][8];
+ int linear[64];
+} FBlock;
+
+#include
+#include
+#ifndef __MICROBLAZE
+#include
+#endif
+#include "zzq.h"
+#include "io.h"
+#include "huffman.h"
+#include "dct.h"
+#pragma hdrstop
+
+
+//---------------------------------------------------------------------------
+
+INFOHEADER _bmpheader;
+
+#pragma argsused
+int main(int argc, char* argv[])
+{
+ int encode, compression,i;
+ signed char pixelmatrix[MATRIX_SIZE][MATRIX_SIZE*3],YMatrix[MATRIX_SIZE][MATRIX_SIZE],CrMatrix[MATRIX_SIZE][MATRIX_SIZE],CbMatrix[MATRIX_SIZE][MATRIX_SIZE];
+ /*= {{124, 105, 139, 95, 143, 98, 132, 114},
+{105, 157, 61, 187, 51, 176, 80, 132},
+{139, 61, 205, 17, 221, 32, 176, 98},
+{95, 187, 17, 239, 0, 221, 51, 143},
+{143, 51, 221, 0, 239, 17, 187, 95},
+{98, 176, 32, 221, 17, 205, 61, 139},
+{132, 80, 176, 51, 187, 61, 157, 105},
+{114, 132, 98, 143, 95, 139, 105, 124}}; */
+ signed short temp[MATRIX_SIZE][MATRIX_SIZE], dctresult[MATRIX_SIZE][MATRIX_SIZE];
+ signed char output[MATRIX_SIZE][MATRIX_SIZE];
+ signed char bitstream[NUMBER_OF_PIXELS] ;//= {15,0,-2,-1,-1,-1,0,0,-1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
+ unsigned char header[389];
+ FILE *infile, *outfile;
+ INFOHEADER *bmpheader;
+ JPEGHEADER *jpegheader;
+#ifndef __MICROBLAZE
+ LARGE_INTEGER st, en;
+#endif
+ unsigned int col, cols, row, rows, remaining,component;
+ unsigned char amount_remaining, Ydcvalue, Cbdcvalue, Crdcvalue ;
+
+
+// bmpheader = (INFOHEADER *)malloc(sizeof(INFOHEADER));
+ bmpheader=&_bmpheader;
+
+ switch (argc) {
+ case 3 :
+ encode = 0;
+ break;
+ case 4 :
+ encode = 1;
+ break;
+ case 5 :
+ encode = 1;
+ compression = atoi(argv[4]);
+ break;
+ default :
+ printf("invalid number of parameters\n\nUSAGE: jpegcodec source_file destination_file [/E] [compression_rate]\n");
+ printf("\nsource_file \t\t location of original file");
+ printf("\ndestination_file \t location of the new file");
+ printf("\n/E \t\t\t When set the source_file will be encoded to JPEG \n\t\t\t otherwise it will be decoded to BMP.");
+ printf("\ncompression_rate \t specifies the compression ratio, defaults to the\n\t\t\t standard compression ratio. (Only valid when /D is set)\n");
+ system("PAUSE");
+ return 0;
+ }
+
+ infile = fopen(argv[1],"rb");
+ if (infile == NULL) {
+ printf("Input file %s does not exist!\n\nUSAGE: jpegcodec source_file destination_file [/E] [compression_rate]\n",argv[1]);
+ printf("\nsource_file \t\t location of original file");
+ printf("\ndestination_file \t location of the new file");
+ printf("\n/E \t\t\t When set the source_file will be encoded to JPEG \n\t\t\t otherwise it will be decoded to BMP.");
+ printf("\ncompression_rate \t specifies the compression ratio, defaults to the\n\t\t\t standard compression ratio. (Only valid when /D is set)\n");
+ system("PAUSE");
+ }
+ else { //start codec
+ outfile = fopen(argv[2],"wb");
+#ifndef __MICROBLAZE
+ QueryPerformanceCounter(&st);
+#endif
+ if(encode) { //encode infile to JPEG
+ if (getbmpheader(infile,bmpheader)) { //File is a valid BMP
+ printf("\nImage width: %d pixels", bmpheader->width);
+ printf("\nImage height: %d pixels", bmpheader->height);
+ rows = bmpheader->height>>3;
+ cols = bmpheader->width>>3;
+ remaining=0x00;
+ amount_remaining=0x00;
+ Ydcvalue = 0x00;
+ Crdcvalue = 0x00;
+ Cbdcvalue = 0x00;
+ writejpegheader(outfile,bmpheader);
+
+ for (row = 0; row < rows; row++) {
+ for (col = 0; col < cols; col++) {
+ readbmpfile(infile,pixelmatrix,row,col,bmpheader);
+ RGB2YCrCb(pixelmatrix,YMatrix,CrMatrix,CbMatrix);
+ for(component=0;component<3;component++)
+ {
+ switch (component) {
+ case 0 ://Y-encoding
+ dct(YMatrix,dctresult);
+ zzq(dctresult,bitstream,compression,encode);
+ Ydcvalue = EncodeDataUnit(bitstream,Ydcvalue,outfile, &remaining, &amount_remaining,component);
+ break;
+ case 1 ://Cr-encoding
+ dct(CrMatrix,dctresult);
+ zzq(dctresult,bitstream,compression,encode);
+ Crdcvalue = EncodeDataUnit(bitstream,Crdcvalue,outfile, &remaining, &amount_remaining,component);
+ break;
+ case 2 ://Cb-encoding
+ dct(CbMatrix,dctresult);
+ zzq(dctresult,bitstream,compression,encode);
+ Cbdcvalue = EncodeDataUnit(bitstream,Cbdcvalue,outfile, &remaining, &amount_remaining,component);
+ break;
+ }
+ }
+ }
+ }
+ HuffmanEncodeFinishSend(&remaining,&amount_remaining,outfile);
+ printf("\nProcessed %d %dx%d-blocks.",(row-1)*cols+col,MATRIX_SIZE,MATRIX_SIZE);
+ //write JPEG footer
+ writejpegfooter(outfile);
+
+ }
+ else {
+ printf("\n%s is not a valid BMP-file",argv[1]);
+ }
+
+ } else { //decode infile to BMP
+
+ // readjpegfile(infile,inputbuffer);
+ // huffmancodec(inputbuffer,bitstream,encode);
+ // zzq(pixelmatrix,bitstream,compression,encode);
+ // DCT(dctmatrix,outputbuffer,encode);
+ // writebmp(outputbuffer);*/
+ }
+
+ fclose(outfile);
+ fclose(infile);
+ /* infile = fopen("test.jpg","rb");
+ outfile = fopen("header.h","wb");
+ fread(header,389,1,infile);
+ for(i=0;i<389;i++)
+ fprintf(outfile,"0x%x, ",header[i]);
+ fclose(outfile);
+ fclose(infile); */
+#ifndef __MICROBLAZE
+ QueryPerformanceCounter(&en);
+ printf("\nExecution time: %f seconds",(double)(en.QuadPart-st.QuadPart)/1000000);
+#endif
+ // free(bmpheader);
+ }
+ printf("\n\nHit ENTER to close this window.");
+ getchar();
+ return 0;
+}
+//---------------------------------------------------------------------------
+
+#endif
+
Index: xup2pro.h
===================================================================
--- xup2pro.h (nonexistent)
+++ xup2pro.h (revision 66)
@@ -0,0 +1,50 @@
+#ifndef _XUP2PRO_H
+#define _XUP2PRO_H
+
+// Microblaze related declaration
+
+#include
+#include
+
+#include "xio.h"
+
+#define __XUPV2P
+
+
+// XUP2P board related declaration
+
+#ifdef __XUPV2P
+#define JPG_ADDRESS 0x70000000
+#define JPG_MAXSIZE 0x10000
+#define BMP_ADDRESS 0x70010000
+#define BMP_MAXSIZE 0x10000
+#else
+#define JPG_MAXSIZE 0x400000
+#define BMP_MAXSIZE 0x1c00000
+#endif
+
+// JPEG decoder related declaration
+
+extern unsigned char* jpgimage;
+extern char* bmpimage;
+extern unsigned long jpgsize;
+extern int bmpsize;
+
+// function declaration
+
+#define eOPENINPUT_FILE 1
+#define eOPENOUTPUT_FILE 2
+#define eINVALID_BMP 3
+#define eLARGE_INPUTFILE 4
+
+#ifndef htonl
+#define htonl(x) ((((x)&0xff000000)>>24) | (((x)&0x00ff0000)>>8) | (((x)&0x0000ff00)<<8) | (((x)&0x000000ff)<<24))
+#endif
+
+#ifndef hton
+#define hton(x) ((((x) & 0xff00)>>8) | (((x) &0x00ff)<<8))
+#endif
+
+#endif
+
+
Index: zzq.c
===================================================================
--- zzq.c (nonexistent)
+++ zzq.c (revision 66)
@@ -0,0 +1,94 @@
+//---------------------------------------------------------------------------
+#include
+#include "zzq.h"
+#pragma hdrstop
+//---------------------------------------------------------------------------
+#pragma argsused
+
+static unsigned char quantization_table[MATRIX_SIZE][MATRIX_SIZE] ={
+ {4, 3, 3, 4, 4, 5, 6, 6},
+ {3, 3, 4, 4, 5, 6, 6, 6},
+ {4, 4, 4, 4, 5, 6, 6, 6},
+ {4, 4, 4, 5, 6, 6, 6, 6},
+ {4, 4, 5, 6, 6, 7, 7, 6},
+ {4, 5, 6, 6, 6, 7, 7, 6},
+ {6, 6, 6, 6, 7, 7, 7, 7},
+ {6, 6, 6, 7, 7, 7, 7, 7}
+ };
+
+//static int __count3=0;
+
+void zzq(signed short pixelmatrix[MATRIX_SIZE][MATRIX_SIZE], signed char *bitstream, int compression, int encode)
+{
+ int i, x, y, jumped, deltax, deltay;
+
+ x = y = deltax = deltay = jumped = 0;
+ // printf("\nZigZag order pixelmatrix:\n\n");
+ for(i=0;i0)
+ bitstream[i] = (pixelmatrix[y][x]>>quantization_table[y][x]);
+ else
+ bitstream[i] = -((-pixelmatrix[y][x])>>quantization_table[y][x]);
+ // printf("%i ",bitstream[i]);
+#if 0
+ #ifdef __MICROBLAZE
+ if (__count3<256*3) {
+ xil_printf("%x ", bitstream[i]);
+ __count3++;
+ if ((__count3&0x0f)==0) xil_printf("\r\n");
+ }
+#else
+ if (__count3<256*3) {
+ printf(" %x ", bitstream[i]);
+ __count3++;
+ if ((__count3&0x0f)==0) printf("\r\n");
+ }
+#endif
+#endif
+ }
+
+ if((y == 0) || (y == MATRIX_SIZE-1)) { //on top or bottom side of matrix
+ if(!jumped) { //first jump to element on the right
+ x++;
+ jumped = 1;
+ } else { //modify direction
+ if(i<(NUMBER_OF_PIXELS>>1)) {
+ deltax = -1;
+ deltay = 1;
+ } else {
+ deltax = 1;
+ deltay = -1;
+ }
+ x += deltax;
+ y += deltay;
+ jumped = 0;
+ }
+ } else if ((x == 0) || (x == MATRIX_SIZE-1)) { //on left or right side of matrix
+ if(!jumped) { //jump to element below
+ y++;
+ jumped = 1;
+ } else { //modify direction
+ if(i<(NUMBER_OF_PIXELS>>1)) {
+ deltax = 1;
+ deltay = -1;
+ } else {
+ deltax = -1;
+ deltay = 1;
+ }
+ x += deltax;
+ y += deltay;
+ jumped = 0;
+ }
+ }
+ else {//not on the edges of the matrix
+ x += deltax;
+ y += deltay;
+ }
+ }
+}
+//---------------------------------------------------------------------------
+
Index: io.c
===================================================================
--- io.c (nonexistent)
+++ io.c (revision 66)
@@ -0,0 +1,374 @@
+//---------------------------------------------------------------------------
+#include
+#ifdef __MICROBLAZE
+#include "xup2pro.h"
+#endif
+
+#include "io.h"
+#pragma hdrstop
+//---------------------------------------------------------------------------
+#pragma argsused
+
+JPEGHEADER _jpegheader;
+
+unsigned char qtable[64] = {16, 8, 8, 16, 12, 8, 16, 16, 16, 16, 16, 16, 16, 16,
+16, 32, 32, 16, 16, 16, 16, 32, 32, 32, 32, 32, 64, 64, 64, 64, 64, 64, 64, 64, 64,
+64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 128, 64, 64, 128, 128, 128, 128, 128, 64, 64,
+128, 128, 128, 128, 128, 64, 128, 128, 128};
+
+unsigned char huffmancount[4][16] = {{0x00,0x01,0x05,0x01,0x01,0x01,0x01,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, //standard DC table count
+ {0x00,0x02,0x01,0x03,0x03,0x02,0x04,0x03,0x05,0x05,0x04,0x04,0x00,0x00,0x01,0x7D}, //standard AC table count
+ {0x00,0x01,0x05,0x01,0x01,0x01,0x01,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, //standard DC table count
+ {0x00,0x02,0x01,0x03,0x03,0x02,0x04,0x03,0x05,0x05,0x04,0x04,0x00,0x00,0x01,0x7D}}; //standard AC table count
+
+unsigned char huffDCvalues[12] ={0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b};// {0x00, 0x02, 0x03, 0x04, 0x05, 0x06, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E};
+unsigned char huffACvalues[162] = {0x01, 0x02, 0x03, 0x00, 0x04, 0x11, 0x05, 0x12, 0x21, 0x31, 0x41, 0x06, 0x13, 0x51, 0x61, 0x07, 0x22, 0x71,
+ 0x14, 0x32, 0x81, 0x91, 0xA1, 0x08, 0x23, 0x42, 0xB1, 0xC1, 0x15, 0x52, 0xD1, 0xF0, 0x24, 0x33, 0x62, 0x72, 0x82,
+ 0x09, 0x0A, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39,
+ 0x3A, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x63, 0x64,
+ 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A, 0x83, 0x84, 0x85, 0x86, 0x87,
+ 0x88, 0x89, 0x8A, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9A, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8,
+ 0xA9, 0xAA, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7, 0xB8, 0xB9, 0xBA, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9,
+ 0xCA, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7, 0xD8, 0xD9, 0xDA, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 0xE8, 0xE9,
+ 0xEA, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8, 0xF9, 0xFA};
+
+ //old huffman table, and propably a incorrect one.
+ /*{0x00, 0x01, 0x04, 0x0A, 0x0B, 0x0C, 0x1A, 0x1B, 0x1C, 0x3A, 0x3B, 0x78, 0x79, 0x7A, 0x7B, 0xF8, 0xF9, 0xFA, 0xF6,
+ 0xF7, 0xF8, 0xF9, 0xFA, 0xF6, 0xF7, 0xF8, 0xF9, 0xFA, 0xF6, 0xF7, 0xF8, 0xF9, 0xF4, 0xF5, 0xF6, 0xF7, 0xC0, 0x82,
+ 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F, 0x90, 0x91, 0x92, 0x93, 0x94, 0x95,
+ 0x96, 0x97, 0x98, 0x99, 0x9A, 0x9B, 0x9C, 0x9D, 0x9E, 0x9F, 0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8,
+ 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF, 0xB0, 0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7, 0xB8, 0xB9, 0xBA, 0xBB,
+ 0xBC, 0xBD, 0xBE, 0xBF, 0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE,
+ 0xCF, 0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7, 0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF, 0xE0, 0xE1,
+ 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF, 0xF0, 0xF1, 0xF2, 0xF3, 0xF4,
+ 0xF5, 0xF6, 0xF7, 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE};*/
+
+int getbmpheader(FILE * file, INFOHEADER *header)
+{
+ int retval;
+#ifdef __MICROBLAZE
+
+// sysace_fread(header, 1, 14, file);
+// retval = sysace_fread(header, 1, sizeof(INFOHEADER), file);
+
+ memcpy(header, bmpimage+14, sizeof(INFOHEADER));
+
+ header->size = htonl(header->size);
+ header->width = htonl(header->width);
+ header->height = htonl(header->height);
+ header->planes = hton(header->planes);
+ header->bits = hton(header->bits);
+ header->compression = htonl(header->compression);
+ header->imagesize = htonl(header->imagesize);
+ header->xresolution = htonl(header->xresolution);
+ header->yresolution= htonl(header->yresolution);
+ header->ncolours= htonl(header->ncolours);
+ header->importantcolours= htonl(header->importantcolours);
+
+ return 1;
+
+#else
+ fseek(file,14,SEEK_SET);
+ retval = fread(header, sizeof(INFOHEADER), 1, file);
+#endif
+
+ return retval;
+}
+ /*
+int getjpegheader(FILE * file, JPEGHEADER *header)
+{
+ unsigned int retval;
+
+ return retval;
+}
+
+void writebmpheader(FILE * file, BMPHEADER *header)
+{
+ //write header
+
+ //fill file with 0's
+ fwrite(0, 1, header->info.width*header->info.height, file);
+}
+*/
+void writejpegheader(FILE * file, INFOHEADER *header)
+{
+ JPEGHEADER *jpegheader;
+ unsigned int headersize, huffmantablesize, previoussize;
+ unsigned char QTcount, i, j, components, id, huffmantablecount;
+ unsigned short length, headerlength;
+
+ //Number of Quatization Tables
+ QTcount = 2;
+ headerlength = 12; //12 bytes are needed for the markers
+ huffmantablecount = 4; // // 2 AC and 2 DC tables
+ huffmantablesize = 0;
+ jpegheader = &_jpegheader;//(JPEGHEADER *)malloc(550);
+
+ jpegheader->SOIMarker[0] = 0xff;
+ jpegheader->SOIMarker[1] = 0xd8;
+
+ //APP0 segment
+ jpegheader->app0.APP0Marker[0] = 0xff;
+ jpegheader->app0.APP0Marker[1] = 0xe0;
+
+ headerlength += 16; //APP0 marker is always 16 bytes long
+ jpegheader->app0.Length[0] = 0x00;
+ jpegheader->app0.Length[1] = 0x10;
+ jpegheader->app0.Identifier[0] = 0x4a;
+ jpegheader->app0.Identifier[1] = 0x46;
+ jpegheader->app0.Identifier[2] = 0x49;
+ jpegheader->app0.Identifier[3] = 0x46;
+ jpegheader->app0.Identifier[4] = 0x00;
+ jpegheader->app0.Version[0] = 0x01;
+ jpegheader->app0.Version[1] = 0x00;
+ jpegheader->app0.Units = 0x00;
+ jpegheader->app0.XDensity[0] = 0x00;
+ jpegheader->app0.XDensity[1] = 0x01;
+ jpegheader->app0.YDensity[0] = 0x00;
+ jpegheader->app0.YDensity[1] = 0x01;
+ jpegheader->app0.ThumbWidth = 0x00;
+ jpegheader->app0.ThumbHeight = 0x00;
+
+ //Quantization Table Segment
+ jpegheader->qt.QTMarker[0] = 0xff;
+ jpegheader->qt.QTMarker[1] = 0xdb;
+ length = (QTcount<<6) + QTcount + 2;
+ headerlength += length;
+ jpegheader->qt.Length[0] = (length & 0xff00)>>8;
+ jpegheader->qt.Length[1] = length & 0xff;
+ // jpegheader->qt.QTInfo = 0x00; // index = 0, precision = 0
+ //write Quantization table to header
+ i = 0;
+ /* jpegheader->qt.QTInfo[0] = 0;
+ for(i=0;i<64;i++) {
+ jpegheader->qt.QTInfo[i+1] = qtable[i];
+ }
+ jpegheader->qt.QTInfo[65] = 1;
+ for(i=0;i<64;i++) {
+ jpegheader->qt.QTInfo[i+66] = qtable[i];
+ } */
+ for (id=0; idqt.QTInfo[(id<<6)+id] = id;
+ for(i=0;i<64;i++) {
+ jpegheader->qt.QTInfo[i+1+id+(id<<6)] = qtable[i];
+ }
+ }
+
+ //Start of Frame segment
+ jpegheader->sof0.SOF0Marker[0] = 0xff;
+ jpegheader->sof0.SOF0Marker[1] = 0xc0;
+ if(header->bits == 8) {
+ components = 0x01;
+ }
+ else {
+ components = 0x03;
+ }
+ length = 8 + 3*components;
+ headerlength += length;
+ jpegheader->sof0.Length[0] = (length & 0xff00) >> 8;
+ jpegheader->sof0.Length[1] = length & 0xff;
+ jpegheader->sof0.DataPrecision = 0x08;
+ jpegheader->sof0.ImageHeight[0] = (header->height & 0xff00) >> 8;
+ jpegheader->sof0.ImageHeight[1] = header->height & 0xff;
+ jpegheader->sof0.ImageWidth[0] = (header->width & 0xff00) >> 8;
+ jpegheader->sof0.ImageWidth[1] = header->width & 0xff;
+#ifdef __MICROBLAZE
+ xil_printf("--->%d %d %d %d\r\n", jpegheader->sof0.ImageHeight[0], jpegheader->sof0.ImageHeight[1], jpegheader->sof0.ImageWidth[0], jpegheader->sof0.ImageWidth[1]);
+#else
+ printf("--->%d %d %d %d\r\n", jpegheader->sof0.ImageHeight[0], jpegheader->sof0.ImageHeight[1], jpegheader->sof0.ImageWidth[0], jpegheader->sof0.ImageWidth[1]);
+#endif
+ jpegheader->sof0.Components = components;
+ for (i=0; i < components; i++) {
+ jpegheader->sof0.ComponentInfo[i][0] = i+1; //color component
+ jpegheader->sof0.ComponentInfo[i][1] = 0x11; //no sampling has been done
+ jpegheader->sof0.ComponentInfo[i][2] = (i==0)? 0x00 : 0x01; //quantization table ID
+ }
+ //Start of Huffman Table Segment
+
+ jpegheader->ht.HTMarker[0] = 0xff;
+ jpegheader->ht.HTMarker[1] = 0xc4;
+
+ //Set dummy HT segment length
+ length = 0;//tablecount*17;
+ jpegheader->ht.Length[0] = (length & 0xff00) >> 8;
+ jpegheader->ht.Length[1] = length & 0xff;
+ previoussize = 0;
+ for (id=0; id < huffmantablecount; id++) {
+ huffmantablesize = 0;
+ switch (id) {
+ case 0 : jpegheader->ht.HuffmanInfo[previoussize] = 0x00;
+ break;
+ case 1 : jpegheader->ht.HuffmanInfo[previoussize] = 0x10;
+ break;
+ case 2 : jpegheader->ht.HuffmanInfo[previoussize] = 0x01;
+ break;
+ case 3 : jpegheader->ht.HuffmanInfo[previoussize] = 0x11;
+ break;
+ }
+ for (i=1; i <= 16; i++) {
+ jpegheader->ht.HuffmanInfo[i+previoussize] = huffmancount[id][i-1];
+ huffmantablesize += huffmancount[id][i-1];
+ }
+
+ for (i=0; i < huffmantablesize; i++) {
+ jpegheader->ht.HuffmanInfo[i+previoussize+17] = (id%2 == 1)? huffACvalues[i] : huffDCvalues[i];
+ }
+ previoussize += huffmantablesize + 17;
+ }
+ //Set real HT segment length
+ length = 2+previoussize;
+ headerlength += length;
+ jpegheader->ht.Length[0] = (length & 0xff00) >> 8;
+ jpegheader->ht.Length[1] = length & 0xff;
+ //Reset marker segment
+ /* jpegheader->dri.DRIMarker[0] = 0xff;
+ jpegheader->dri.DRIMarker[1] = 0xdd;
+ jpegheader->dri.Length[0] = 0x00;
+ jpegheader->dri.Length[1] = 0x04;
+ jpegheader->dri.RestartInteral[0] = 0x00; //no restart markers
+ jpegheader->dri.RestartInteral[1] = 0x00; //no restart markers
+ headerlength += 6; //length of DRI segment
+ */
+ //Start of Scan Header Segment
+ jpegheader->sos.SOSMarker[0] = 0xff;
+ jpegheader->sos.SOSMarker[1] = 0xda;
+ length = 6 + (components<<1);
+ headerlength += length;
+ jpegheader->sos.Length[0] = (length & 0xff00) >> 8;
+ jpegheader->sos.Length[1] = length & 0xff;
+ jpegheader->sos.ComponentCount = components; //number of color components in the image
+ jpegheader->sos.Component[0][0] = 0x01; //Y component
+ jpegheader->sos.Component[0][1] = 0x00; //indexes of huffman tables for Y-component
+ if (components == 0x03) {
+ jpegheader->sos.Component[1][0] = 0x02; //the CB component
+ jpegheader->sos.Component[1][1] = 0x11; //indexes of huffman tables for CB-component
+ jpegheader->sos.Component[2][0] = 0x03; //The CR component
+ jpegheader->sos.Component[2][1] = 0x11; //indexes of huffman tables for CR-component
+ }
+ //following bytes are ignored since progressive scan is not to be implemented
+ jpegheader->sos.Ignore[0] = 0x00;
+ jpegheader->sos.Ignore[1] = 0x3f;
+ jpegheader->sos.Ignore[2] = 0x00;
+
+#ifdef __MICROBLAZE
+ sysace_fwrite(jpegheader, 1, headerlength, file);
+ xil_printf("jpeg header size %x\r\n", headerlength);
+#else
+ fwrite(jpegheader,headerlength,1,file);
+ printf("jpeg header size %x\r\n", headerlength);
+#endif
+
+}
+
+void writejpegfooter(FILE * file)
+{
+ unsigned char footer[2];
+ footer[0] = 0xff;
+ footer[1] = 0xd9;
+#ifdef __MICROBLAZE
+ sysace_fwrite(footer, 1, sizeof(footer), file);
+#else
+// fseek(file,0,SEEK_END);
+ fwrite(footer,sizeof(footer),1,file);
+#endif
+}
+
+static unsigned char buffer[MATRIX_SIZE*3];
+static int __count2=0;
+
+void readbmpfile(FILE * file, signed char pixelmatrix[MATRIX_SIZE][MATRIX_SIZE*3], unsigned int mrow, unsigned int mcol, INFOHEADER * header)
+{
+ unsigned int row, col;
+ int offset;
+
+ for(row = 0;row < MATRIX_SIZE; row++) {
+ //Find first point of row in the matrix to be read.
+#ifdef __MICROBLAZE
+// sysace_fread(buffer, 1, MATRIX_SIZE*3, file);
+ offset = bmpsize-3*header->width*(row + 1 + mrow*MATRIX_SIZE)+MATRIX_SIZE*3*mcol;
+ memcpy(buffer, bmpimage + offset, MATRIX_SIZE*3);
+#else
+ fseek(file,-(3*header->width*(row + 1 + mrow*MATRIX_SIZE)-(MATRIX_SIZE*3)*mcol),SEEK_END);
+ //Read row from matrix
+ fread(buffer, 1, MATRIX_SIZE*3, file);
+ //copy row into pixelmatrix
+#endif
+ for(col = 0; col < MATRIX_SIZE*3; col++) {
+ pixelmatrix[row][col] = buffer[col]- 128;
+#if 0
+#ifdef __MICROBLAZE
+ if (__count2<4*24*8) {
+ xil_printf("%x ", pixelmatrix[row][col]);
+ __count2++;
+ if ((__count2&0x0f)==0) xil_printf("\r\n");
+ }
+#else
+ if (__count2<4*24*8) {
+ printf(" %x ", pixelmatrix[row][col]);
+ __count2++;
+ if ((__count2&0x0f)==0) printf("\r\n");
+ }
+#endif
+#endif
+ }
+ }
+ }
+/*USED VALUES OF ROY's CODE THIS MIGHT LEAD TO PROBLEMS*/
+signed char RGB2Y (int r, int g, int b) {
+ return ((66*r + 129*g + 25*b + 128)>>8)+128;
+}
+/*USED VALUES OF ROY's CODE THIS MIGHT LEAD TO PROBLEMS*/
+signed char RGB2Cr (int r, int g, int b) {
+ return ((-38*r - 74*g + 112*b + 128)>>8)+128;
+}
+/*USED VALUES OF ROY's CODE THIS MIGHT LEAD TO PROBLEMS*/
+signed char RGB2Cb (int r, int g, int b) {
+ return ((112*r - 94*g - 18*b + 128)>>8)+128;
+}
+
+static int __count1=120;
+
+void RGB2YCrCb(signed char pixelmatrix[MATRIX_SIZE][MATRIX_SIZE*3],signed char YMatrix[MATRIX_SIZE][MATRIX_SIZE],signed char CrMatrix[MATRIX_SIZE][MATRIX_SIZE],signed char CbMatrix[MATRIX_SIZE][MATRIX_SIZE])
+{
+ unsigned int row, col;
+ for(row = 0;row < MATRIX_SIZE; row++) {
+ for(col = 0; col < MATRIX_SIZE; col++) {
+ YMatrix[row][col] = RGB2Y(pixelmatrix[row][col*3+2],pixelmatrix[row][col*3+1],pixelmatrix[row][col*3]) - 128;
+ CrMatrix[row][col] = RGB2Cr(pixelmatrix[row][col*3+2],pixelmatrix[row][col*3+1],pixelmatrix[row][col*3]) - 128;
+ CbMatrix[row][col] = RGB2Cb(pixelmatrix[row][col*3+2],pixelmatrix[row][col*3+1],pixelmatrix[row][col*3]) - 128;
+#if 0
+#ifdef __MICROBLAZE
+ if (__count1<64) {
+ xil_printf("-------------->%x %x %x\r\n", YMatrix[row][col], CrMatrix[row][col], CbMatrix[row][col]);
+ __count1++;
+ }
+#else
+ if (__count1<64) {
+ printf("-------------->%x %x %x\r\n", YMatrix[row][col], CrMatrix[row][col], CbMatrix[row][col]);
+ __count1++;
+ }
+#endif
+#endif
+ }
+ }
+}
+/*
+void readjpegfile(FILE * file, unsigned char bitstream[])
+{
+}
+
+
+void writebmpfile(FILE * file, unsigned char pixelmatrix[MATRIX_SIZE][MATRIX_SIZE], unsigned int mrow, unsigned int mcol, unsigned int width)
+{
+ unsigned int row;
+ for(row = 0;row < MATRIX_SIZE; row++) {
+ //Find first point of row in the matrix to be read.
+ fseek(file,-(width*(row + 1 + mrow*MATRIX_SIZE)-(MATRIX_SIZE*mcol)),SEEK_END);
+ //Read row from matrix
+ fwrite(pixelmatrix[row], 1, MATRIX_SIZE, file);
+ }
+}
+
+void writejpegfile(FILE * file, unsigned char bitstream[])
+{
+} */
Index: huffman.h
===================================================================
--- huffman.h (nonexistent)
+++ huffman.h (revision 66)
@@ -0,0 +1,11 @@
+#ifndef _HUFFMAN_H
+#define _HUFFMAN_H 1
+
+char EncodeDataUnit(char dataunit[NUMBER_OF_PIXELS], char last_dc_value, FILE* file, unsigned int *remaining, unsigned char *amount_remaining, unsigned int component);
+
+void HuffmanEncodeFinishSend(unsigned int *remaining,unsigned char *amount_remaining, FILE* file);
+
+#else
+#error "ERROR file huffman.h multiple times included"
+#endif /* --- _HUFFMAN_H --- */
+
Index: types.h
===================================================================
--- types.h (nonexistent)
+++ types.h (revision 66)
@@ -0,0 +1,10 @@
+typedef union { /* block of pixel-space values */
+ unsigned char block[8][8];
+ unsigned char linear[64];
+} PBlock;
+
+typedef union { /* block of frequency-space values */
+ int block[8][8];
+ int linear[64];
+} FBlock;
+
\ No newline at end of file
Index: zzq.h
===================================================================
--- zzq.h (nonexistent)
+++ zzq.h (revision 66)
@@ -0,0 +1,18 @@
+#ifndef _ZZQ_H
+#define _ZZQ_H 1
+
+#define MATRIX_SIZE 8
+#define NUMBER_OF_PIXELS MATRIX_SIZE*MATRIX_SIZE
+
+
+
+
+/*
+ * ZigZag order the pixelmatrix and quantify its values, if endode == 0 the
+ * inverse operation will be caried out.
+ */
+void zzq(signed short pixelmatrix[MATRIX_SIZE][MATRIX_SIZE], signed char *bitstream, int compression, int encode);
+#else
+#error "ERROR file zzq.h multiple times included"
+#endif /* --- _ZZQ_H --- */
+
Index: dct.c
===================================================================
--- dct.c (nonexistent)
+++ dct.c (revision 66)
@@ -0,0 +1,144 @@
+
+#include
+#include "dct.h"
+#include "weights.h"
+
+
+/*
+ Function Name: dct
+
+ Operation: Find the 8x8 DCT of an array using separable DCT
+ First, finds 1-d DCT along rows, storing the result in inter[][]
+ Then, 1-d DCT along columns of inter[][] is found
+
+ Input: pixels is the 8x8 input array
+
+ Output: dct is the 8x8 output array
+*/
+signed int max_val = 0;
+static int __count=0;
+
+void dct(signed char pixels[8][8], signed short dct[8][8])
+{
+ FILE * file;
+ int inr, inc; /* rows and columns of input image */
+ int intr, intc; /* rows and columns of intermediate image */
+ int outr, outc; /* rows and columns of dct */
+ int f_val; /* cumulative sum */
+ int inter[8][8]; /* stores intermediate result */
+ int i,j,k;
+ k=0;
+ // file = fopen("weights.h","w+");
+ // fprintf(file,"double weights1[512] = {");
+ /* find 1-d dct along rows */
+#if 0
+
+#ifdef __MICROBLAZE
+ if (__count<4) {
+ for (i=0; i<8; i++)
+ for (j=0; j<8; j++)
+ xil_printf("%x ", pixels[i][j]);
+ xil_printf("\r\n");
+ }
+#else
+ if (__count<4) {
+ for (i=0; i<8; i++)
+ for (j=0; j<8; j++)
+ printf(" %x ", pixels[i][j]);
+ printf("\r\n");
+ }
+#endif
+#endif
+
+ for (intr=0; intr<8; intr++)
+ for (intc=0; intc<8; intc++) {
+ for (i=0,f_val=0; i<8; i++) {
+
+ f_val += (pixels[intr][i]* weights[k]);//cos((double)(2*i+1)*(double)intc*PI/16);
+ k++;
+ // fprintf(file, "\n%.0f,",cos((double)(2*i+1)*(double)intc*PI/16)*16384);
+ }
+ if (intc!=0)
+ inter[intr][intc] = f_val>>15;
+ else
+ inter[intr][intc] = (11585*(f_val>>14))>>15;
+
+ }
+ // fprintf(file,"\n};");
+ // fclose(file);
+ k=0;
+ /* find 1-d dct along columns */
+ for (outc=0; outc<8; outc++)
+ for (outr=0; outr<8; outr++) {
+ for (i=0,f_val=0; i<8; i++) {
+ f_val += (inter[i][outc] *weights[k]);
+ k++;
+ }
+ if (outr!=0)
+ dct[outr][outc] = f_val>>15;
+ else
+ dct[outr][outc] = (11585*(f_val>>14)>>15);
+ }
+#if 0
+#ifdef __MICROBLAZE
+ if (__count<4) {
+ for (i=0; i<8; i++)
+ for (j=0; j<8; j++)
+ xil_printf("%x ", dct[i][j]);
+ xil_printf("\r\n");
+ __count++;
+ }
+#else
+ if (__count<4) {
+ for (i=0; i<8; i++)
+ for (j=0; j<8; j++)
+ printf(" %x ", dct[i][j]);
+ printf("\r\n");
+ __count++;
+ }
+#endif
+#endif
+
+}
+
+/*****************************************************************
+ UNCOMMENT THIS SECTION TO TEST 2D DCT
+*****************************************************************/
+
+/*
+main()
+{
+
+ unsigned char inputmatrix[8][8];
+ unsigned char outputmatrix[8][8];
+ unsigned int i,j;
+
+
+ printf("Input Matrix (8*8) :-\n");
+ for (i=0; i<8; i++){
+ printf("\n");
+ for (j=0;j<8;j++){
+ inputmatrix[i][j] = i*8+j;
+ printf("%4d",inputmatrix[i][j]);
+ }
+
+ }
+
+
+
+ dct(inputmatrix,outputmatrix);
+
+ printf("\n\nOutput Matrix (8*8) :-\n");
+
+ for (i=0; i<8; i++){
+ printf("\n");
+ for (j=0;j<8;j++){
+ printf("%4d",outputmatrix[i][j]);
+
+ }
+
+ }
+printf("\n");
+
+}
+*/
Index: io.h
===================================================================
--- io.h (nonexistent)
+++ io.h (revision 66)
@@ -0,0 +1,136 @@
+#ifndef _IO_H
+#define _IO_H 1
+#define MATRIX_SIZE 8
+typedef struct {
+ unsigned int size; /* Header size in bytes */
+ int width,height; /* Width and height of image */
+ unsigned short int planes; /* Number of colour planes */
+ unsigned short int bits; /* Bits per pixel */
+ unsigned int compression; /* Compression type */
+ unsigned int imagesize; /* Image size in bytes */
+ int xresolution,yresolution; /* Pixels per meter */
+ unsigned int ncolours; /* Number of colours */
+ unsigned int importantcolours; /* Important colours */
+ unsigned char palette[1024]; /* Storage for palette */
+} INFOHEADER;
+
+typedef struct {
+ int restofheader; //TODO
+ INFOHEADER info; /* Information header */
+} BMPHEADER;
+
+typedef struct {
+ unsigned int row; /* Width and height of image */
+ unsigned int col; /* Width and height of image */
+} BLOCKINFO;
+
+typedef struct {
+ unsigned char QTMarker[2];
+ unsigned char Length[2];
+ unsigned char QTInfo[130]; //bit 0..3: number of QT (0..3, otherwise error)
+ // bit 4..7: precision of QT, 0 = 8 bit, otherwise 16 bit
+ // unsigned char ValuesQT[]; //max 192 values. 64*(precision+1) bytes
+} QTINFO;
+
+typedef struct {
+ unsigned char HTMarker[2];
+ unsigned char Length[2];
+ unsigned char HuffmanInfo[416]; //Array containing ALL huffman information
+ //For each color component holds:
+ //First byte is used as info byte, followed by 16 bytes with values used
+ //for counting the different huffman codes, finally the corresponding
+ //huffman codes will follow. This sequence can repeat it self for
+ //different Huffman tables, both DC or AC tables.
+
+ //The structure of the information byte is as follows:
+ //bit 0..3 : number of HT (0..3, otherwise error)
+ //bit 4 : type of HT, 0 = DC table, 1 = AC table
+ //bit 5..7 : not used, must be 0 (Used for progressive scan JPEG)
+} HTINFO;
+
+
+typedef struct {
+ unsigned char APP0Marker[2];
+ unsigned char Length[2];
+ unsigned char Identifier[5];
+ unsigned char Version[2];
+ unsigned char Units;
+ unsigned char XDensity[2];
+ unsigned char YDensity[2];
+ unsigned char ThumbWidth;
+ unsigned char ThumbHeight;
+} APP0INFO;
+
+typedef struct {
+ unsigned char SOF0Marker[2];
+ unsigned char Length[2];
+ unsigned char DataPrecision; //This is in bits/sample, usually 8 (12 and 16 not supported by most software).
+ unsigned char ImageHeight[2];
+ unsigned char ImageWidth[2];
+ unsigned char Components; //Usually 1 = grey scaled, 3 = color YcbCr or YIQ 4 = color CMYK
+ unsigned char ComponentInfo[3][3]; //Read each component data of 3 bytes. It contains,
+ //(component Id(1byte)(1 = Y, 2 = Cb, 3 = Cr, 4 = I, 5 = Q),
+ //sampling factors (1byte) (bit 0-3 vertical., 4-7 horizontal.),
+ //quantization table number (1 byte)).
+} SOF0INFO;
+
+typedef struct {
+ unsigned char SOSMarker[2];
+ unsigned char Length[2]; //This must be equal to 6+2*(number of components in scan).
+ unsigned char ComponentCount; //This must be >= 1 and <=4 (otherwise error), usually 1 or 3
+ unsigned char Component[3][2]; // For each component, read 2 bytes. It contains,
+ //1 byte Component Id (1=Y, 2=Cb, 3=Cr, 4=I, 5=Q),
+ //1 byte Huffman table to use :
+ //bit 0..3 : AC table (0..3)
+ //bit 4..7 : DC table (0..3)
+ unsigned char Ignore[3]; //We have to skip 3 bytes
+} SOSINFO;
+
+typedef struct {
+ unsigned char DRIMarker[2];
+ unsigned char Length[2];
+ unsigned char RestartInteral[2]; // Interval of the restart markers
+} DRIINFO;
+
+typedef struct {
+ unsigned char SOIMarker[2]; //Start of image marker
+ APP0INFO app0;
+ QTINFO qt;
+ SOF0INFO sof0;
+ HTINFO ht;
+// DRIINFO dri;
+ SOSINFO sos;
+} JPEGHEADER;
+
+/*
+ * Read BMP header and return it in header, for now only the width and height
+ * are returned, since the other values are of no use.
+ */
+int getbmpheader(FILE * file, INFOHEADER *header);
+
+int getjpegheader(FILE * file, JPEGHEADER *header);
+
+void writebmpheader(FILE * file, BMPHEADER *header);
+
+void writejpegheader(FILE * file, INFOHEADER *header);
+
+void writejpegfooter(FILE * file);
+
+/*
+ * Read BMP to retrieve 8*8 block starting at horizontal position mcol*8, and
+ * vertical position mrow*8 in the image. This block is returned in pixelmatrix.
+ *
+ */
+void readbmpfile(FILE * file, signed char pixelmatrix[MATRIX_SIZE][MATRIX_SIZE*3], unsigned int mrow, unsigned int mcol, INFOHEADER * header);
+
+void RGB2YCrCb(signed char pixelmatrix[MATRIX_SIZE][MATRIX_SIZE*3],signed char YMatrix[MATRIX_SIZE][MATRIX_SIZE],signed char CrMatrix[MATRIX_SIZE][MATRIX_SIZE],signed char CbMatrix[MATRIX_SIZE][MATRIX_SIZE]);
+
+void readjpegfile(FILE * file, unsigned char bitstream[]);
+
+void writebmpfile(FILE * file, unsigned char pixelmatrix[MATRIX_SIZE][MATRIX_SIZE], unsigned int mrow, unsigned int mcol, unsigned int width);
+
+void writejpegfile(FILE * file, unsigned char bitstream[]);
+#else
+#error "ERROR file io.h multiple times included"
+#endif /* --- _IO_H --- */
+
Index: header.h
===================================================================
--- header.h (nonexistent)
+++ header.h (revision 66)
@@ -0,0 +1 @@
+0xff, 0xd8, 0xff, 0xe0, 0x0, 0x10, 0x4a, 0x46, 0x49, 0x46, 0x0, 0x1, 0x0, 0x0, 0x0, 0x1, 0x0, 0x1, 0x0, 0x0, 0xff, 0xdb, 0x0, 0x84, 0x0, 0x10, 0x8, 0x8, 0x10, 0xc, 0x8, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x20, 0x20, 0x10, 0x10, 0x10, 0x10, 0x20, 0x20, 0x20, 0x20, 0x20, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x80, 0x40, 0x40, 0x80, 0x80, 0x80, 0x80, 0x80, 0x40, 0x40, 0x80, 0x80, 0x80, 0x80, 0x80, 0x40, 0x80, 0x80, 0x80, 0x1, 0x10, 0x8, 0x8, 0x10, 0xc, 0x8, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x20, 0x20, 0x10, 0x10, 0x10, 0x10, 0x20, 0x20, 0x20, 0x20, 0x20, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x80, 0x40, 0x40, 0x80, 0x80, 0x80, 0x80, 0x80, 0x40, 0x40, 0x80, 0x80, 0x80, 0x80, 0x80, 0x40, 0x80, 0x80, 0x80, 0xff, 0xc0, 0x0, 0xb, 0x8, 0x1, 0x20, 0x1, 0xb0, 0x1, 0x1, 0x11, 0x0, 0xff, 0xc4, 0x0, 0xd2, 0x0, 0x0, 0x1, 0x5, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0x10, 0x0, 0x2, 0x1, 0x3, 0x3, 0x2, 0x4, 0x3, 0x5, 0x5, 0x4, 0x4, 0x0, 0x0, 0x1, 0x7d, 0x1, 0x2, 0x3, 0x0, 0x4, 0x11, 0x5, 0x12, 0x21, 0x31, 0x41, 0x6, 0x13, 0x51, 0x61, 0x7, 0x22, 0x71, 0x14, 0x32, 0x81, 0x91, 0xa1, 0x8, 0x23, 0x42, 0xb1, 0xc1, 0x15, 0x52, 0xd1, 0xf0, 0x24, 0x33, 0x62, 0x72, 0x82, 0x9, 0xa, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xff, 0xda, 0x0, 0x8, 0x1, 0x1, 0x0, 0x0, 0x3f, 0x0,
\ No newline at end of file