summaryrefslogtreecommitdiffstats
path: root/src/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c169
1 files changed, 66 insertions, 103 deletions
diff --git a/src/main.c b/src/main.c
index dcf60a5..332978c 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1,6 +1,8 @@
#include <stdio.h>
#include "dct.h"
#include "bmpjpeg.h"
+#include "bmp.h"
+#include "jpeg.h"
#define ENCODE 0
#define DECODE 1
@@ -8,28 +10,37 @@
#define MAXCOLS 768
#define HEADER 54
-#define SOI_MK 0xFFD8 /* start of image */
-#define SOF_MK 0xFFC0 /* start of frame */
-#define EOI_MK 0xFFD9 /* end of image */
-#define DRI_MK 0xFFDD /* restart interval */
+unsigned char Image1[MAXCOLS*3*MAXROWS+HEADER];
-#define get_size(fi) (((unsigned int)Image1[fi]) << 8) + (unsigned int)Image1[fi+1]
+/*------------------------------------------*/
+/* some constants for on-the-fly IQ and IZZ */
+/*------------------------------------------*/
+
+static const int G_ZZ[] = {
+ 0, 1, 8, 16, 9, 2, 3, 10,
+ 17, 24, 32, 25, 18, 11, 4, 5,
+ 12, 19, 26, 33, 40, 48, 41, 34,
+ 27, 20, 13, 6, 7, 14, 21, 28,
+ 35, 42, 49, 56, 57, 50, 43, 36,
+ 29, 22, 15, 23, 30, 37, 44, 51,
+ 58, 59, 52, 45, 38, 31, 39, 46,
+ 53, 60, 61, 54, 47, 55, 62, 63
+};
-unsigned char Image1[MAXCOLS*3*MAXROWS+HEADER];
int main(int argc, char *argv[]) {
int retval, i;
int workspace[DCTSIZE_BLOCK];
-
unsigned char blok8x8[64*3];
-
- int type, hCounter = 0;
- int x_size, y_size, offset, depth;
+ unsigned char type;
+ unsigned int x_size, y_size, offset;
+ unsigned char depth;
char *fileIn, *fileOut;
+
FILE *fI, *fO;
- unsigned char ch, mrgb[3];
- unsigned int aux;
+
+
/*******************************************************************************************/
/* Just for testing on the PC */
@@ -58,69 +69,47 @@ int main(int argc, char *argv[]) {
/* The image must be in the memory by now */
+// retval = 0;
+
switch(type) {
- case ENCODE:
- offset = ((int)Image1[13] << 24) + ((int)Image1[12] << 16) + ((int)Image1[11] << 8) + Image1[10];
- x_size = ((int)Image1[21] << 24) + ((int)Image1[20] << 16) + ((int)Image1[19] << 8) + Image1[18];
- y_size = ((int)Image1[25] << 24) + ((int)Image1[24] << 16) + ((int)Image1[23] << 8) + Image1[22];
- depth = ((int)Image1[29] << 8) + Image1[28];
-
-/**/ printf("Image Resolution: %d x %d x %i Offset: %i\n", x_size, y_size, depth, offset);
-
- break;
- case DECODE:
-
- /* First find the SOI marker: */
- aux = get_size(hCounter); hCounter+=2;
- if (aux != SOI_MK)
- { printf("INFO:\tNO SOI marker!\n"); return 0;}
-
- printf("%ld:\tINFO:\tFound the SOI marker!\n", hCounter);
-
- /* Read first marker */
- while( aux != SOF_MK)
- {
- aux = get_size(hCounter); hCounter+=2;
- if(aux == SOF_MK)
- {
- get_size(hCounter); hCounter+=2; /* header size, don't care */
-
- /* load basic image parameters */
- hCounter++; /* precision, 8bit, don't care */
- y_size = get_size(hCounter); hCounter+=2;
- x_size = get_size(hCounter); hCounter+=2;
-
- printf("\tINFO:\tImage size is %d by %d\n", x_size, y_size);
-
- depth = Image1[hCounter]; /* # of components */
-
- printf("\tINFO:\t");
- switch (depth)
- {
- case 1:
- printf("Monochrome");
- break;
- case 3:
- printf("Color");
- break;
- default:
- printf("Not a");
- break;
- }
- printf(" JPEG image!\n");
-
- return 0;
- }
- else
- {
- hCounter = hCounter + get_size(hCounter);
- }
- }
-}
+ case ENCODE:
+
+ GetBMPHeaderInfo (Image1,&offset,&x_size,&y_size,&depth);
+ printf("Image Resolution: %d x %d x %i Offset: %i\n", x_size, y_size, depth, offset);
+ // RGB -> YUV ---> done
+
+ // Convert to 8x8 --> done
+ //BMPto8x8AndYCbCr(0,0,x_size,y_size,offset,depth,Image1,blok8x8);
+ // DCT
+ fdct(workspace);
+
+ // ZZ
+
+ // Q
+
+ // VLC (huffman)
+
+ break;
+ case DECODE:
+
+ GetJPEGHeaderInfo (Image1,&offset,&x_size,&y_size,&depth);
+ // VLD (huffman)
+
+ // IQ
+
+ // ZZ
+
+ // IDCT
+ //idct(workspace);
+ // Convert 8x8 to BMP style -> done
+ // YUV -> RGB
+ // YCbCrAnd8x8toBMP()
+ // WriteBMPHeaderInfo(Image1,offset,x_size,y_size, depth);
+
+ break;
+ }
- retval = 0;
- type = ENCODE;
printf("Before:");
for(i=0;i<(x_size*y_size*3);i++)
{
@@ -152,38 +141,12 @@ int main(int argc, char *argv[]) {
}
- switch(type) {
- case ENCODE:
- // RGB -> YUV ---> done
-
- // Convert to 8x8 --> done
- //BMPto8x8AndYCbCr(0,0,x_size,y_size,offset,depth,Image1,blok8x8);
- // DCT
- fdct(workspace);
-
- // ZZ
-
- // Q
-
- // VLC (huffman)
-
- break;
- case DECODE:
- // VLD (huffman)
-
- // IQ
-
- // ZZ
-
- // IDCT
- //idct(workspace);
- // Convert 8x8 to BMP style -> done
- // YUV -> RGB
- // YCbCrAnd8x8toBMP()
-
- break;
- }
+ //Write Image to the output file.
+ fwrite(Image1, sizeof(unsigned char), (x_size*y_size*(depth/8))+offset, fO);
+ fclose(fI);
+ fclose(fO);
return retval;
}
+