summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOliver Schinagl <oliver@schinagl.nl>2005-04-10 20:55:23 (GMT)
committerOliver Schinagl <oliver@schinagl.nl>2005-04-10 20:55:23 (GMT)
commit06f2fad8fd69c8405769efbd64c6312ec9815341 (patch)
tree30f28e48fc24b365f7ef5fe5b4c50e1af610adb1
parenta9fec5259222066d6a49151af1929f5e11cafa11 (diff)
download5kk53-06f2fad8fd69c8405769efbd64c6312ec9815341.zip
5kk53-06f2fad8fd69c8405769efbd64c6312ec9815341.tar.gz
5kk53-06f2fad8fd69c8405769efbd64c6312ec9815341.tar.bz2
Some small updates and split some up to color.c and bmpjpeg.c
-rw-r--r--src/main.c88
1 files changed, 41 insertions, 47 deletions
diff --git a/src/main.c b/src/main.c
index e49f249..dcf60a5 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1,11 +1,12 @@
#include <stdio.h>
#include "dct.h"
+#include "bmpjpeg.h"
#define ENCODE 0
#define DECODE 1
#define MAXROWS 1024
#define MAXCOLS 768
-#define HEADER 56
+#define HEADER 54
#define SOI_MK 0xFFD8 /* start of image */
#define SOF_MK 0xFFC0 /* start of frame */
@@ -16,49 +17,12 @@
unsigned char Image1[MAXCOLS*3*MAXROWS+HEADER];
-unsigned char clip(int value) {
- if (value < 0) return (char) 0;
- if (value > 255) return (char) 255;
- return (unsigned char) value;
-}
-
-/* RGB -> YCbCr (also from BMP to JPEG) */
-// Y = 0.299 R + 0.587 G + 0.114 B
-unsigned char RGB2Y (unsigned char R, unsigned char G, unsigned char B) {
- return clip(((R*77)>>8) + ((G*150)>>8) + ((B*29)>>8));
-}
-
-// Cb = - 0.1687 R - 0.3313 G + 0.5 B + 128
-unsigned char RGB2Cb (unsigned char R, unsigned char G, unsigned char B) {
- return clip((B>>1)-((R*43)>>8) - ((G*85)>>8) + 128);
-}
-
-//Cr = 0.5 R - 0.4187 G - 0.0813 B + 128
-unsigned char RGB2Cr (unsigned char R, unsigned char G, unsigned char B) {
- return clip((R>>1) - ((G*107)>>8) - ((B*21)>>8) + 128);
-}
-
-
-/* RGB -> YCbCr (also from JPEG to BMP) */
-// R = Y + 1.402 (Cr-128)
-unsigned char YCbCr2R (unsigned char Y, unsigned char Cr) {
- return clip(Y + (((Cr-128)*359)>>8));
-}
-
-// G = Y - 0.34414 (Cb-128) - 0.71414 (Cr-128)
-unsigned char YCbCr2G (unsigned char Y, unsigned char Cb, unsigned char Cr) {
- return clip(Y - (((Cb-128)*88)>>8) - (((Cr-128)*183)>>8));
-}
-
-// B = Y + 1.772 (Cb-128)
-unsigned char YCbCr2B (unsigned char Y, unsigned char Cb) {
- return clip(Y + (((Cb-128)*227)>>7));
-}
-
-
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;
@@ -71,7 +35,7 @@ int main(int argc, char *argv[]) {
/* Just for testing on the PC */
if(argc != 4)
{
- printf("need more arguments");
+ printf("need more arguments, 0|1 for de/encrypt and 2 more for the in/ouput files");
return 0;
}
@@ -157,13 +121,43 @@ int main(int argc, char *argv[]) {
retval = 0;
type = ENCODE;
+ printf("Before:");
+ for(i=0;i<(x_size*y_size*3);i++)
+ {
+ if((i%24)==0) printf("\n");
+ printf("%02x ",Image1[i+offset]);
+ }
+ printf("\nBMPto8x8 functie\n");
+
+ BMPto8x8AndYCbCr(0,0,x_size,y_size,offset,depth,Image1,blok8x8);
+ printf("\n8x8 Blok:\n");
+ for(i=0;i<64;i++)
+ {
+ printf("%02x",blok8x8[i]);
+ }
+
+ for(i=0;i<(x_size*y_size*3);i++)
+ {
+ Image1[i+offset] = 0;
+ }
+
+ printf("\n8x8toBMP functie\n");
+ YCbCrAnd8x8toBMP(0,0,x_size,y_size,offset,depth,Image1,blok8x8);
+
+ printf("\nAfter:\n");
+ for(i=0;i<(x_size*y_size*3);i++)
+ {
+ if((i%24)==0) printf("\n");
+ printf("%02x ",Image1[i+offset]);
+ }
+
switch(type) {
case ENCODE:
- // RGB -> YUV
-
- // Convert to 8x8
+ // RGB -> YUV ---> done
+ // Convert to 8x8 --> done
+ //BMPto8x8AndYCbCr(0,0,x_size,y_size,offset,depth,Image1,blok8x8);
// DCT
fdct(workspace);
@@ -183,9 +177,9 @@ int main(int argc, char *argv[]) {
// IDCT
//idct(workspace);
- // Convert 8x8 to lines
-
+ // Convert 8x8 to BMP style -> done
// YUV -> RGB
+ // YCbCrAnd8x8toBMP()
break;
}