LOGIN   :::   RECOVER PASS   :::   GET ACCOUNT    
Browse
  • Projects
  • Code (CVS)
  • Forums
  • News
  • Articles
  • Polls
  •  
    OpenCores
  • FAQ
  • CVS HowTo
  • Mission
  • Media
  • Tools
  • Advertise
  • Mirrors
  • Logos
  • Contact us
  • Find Resources
  • Job Opportunity
  •  
    Tools
  • Search
      
  • Download Cores (CVSGet)
  •  
    More
  • Wishbone
  • Perlilog
  • EDA tools
  • OpenTech CD
  •  
    Navigation: All forums > Cvs-checkins > Message List > Message Post

    Message

    Reply | Reply all
    Date Prev | Date Next | Thread Prev | Thread Next Date Index | Thread Index

    From: cvs at opencores.org<cvs@o...>
    Date: Fri Sep 15 14:15:38 CEST 2006
    Subject: [cvs-checkins] MODIFIED: mb-jpeg ...
    Top
    Date: 00/06/09 15:14:15

    Modified: mb-jpeg/bmp2jpg_mb ColorConversion.c bmp2jpg_mb.c ejpgl.h
    io.h mb.h
    Log:
    add 4:2:0 subsampling feature


    Revision Changes Path
    1.3 mb-jpeg/bmp2jpg_mb/ColorConversion.c

    http://www.opencores.org/cvsweb.shtml/mb-jpeg/bmp2jpg_mb/ColorConversion.c.diff?r1=1.2&r2=1.3

    (In the diff below, changes in quantity of whitespace are not shown.)

    Index: ColorConversion.c
    ===================================================================
    RCS file: /cvsroot/quickwayne/mb-jpeg/bmp2jpg_mb/ColorConversion.c,v
    retrieving revision 1.2
    retrieving revision 1.3
    diff -u -b -r1.2 -r1.3
    --- ColorConversion.c 29 Jul 2006 00:22:51 -0000 1.2
    +++ ColorConversion.c 15 Sep 2006 12:15:38 -0000 1.3
    @@ -1,68 +1,27 @@
    #include <stdio.h>
    #include "io.h"

    -#if 0
    -/*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;
    -}
    -
    -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;
    - }
    - }
    -}
    -#endif
    -
    #define RGB2Y(r, g, b) (((66*r + 129*g + 25*b + 128)>>8)+128)
    #define RGB2Cr(r, g, b) (((-38*r - 74*g + 112*b + 128)>>8)+128)
    #define RGB2Cb(r, g, b) (((112*r - 94*g - 18*b + 128)>>8)+128)

    -
    -void RGB2Y_matrix(signed char pixelmatrix[MATRIX_SIZE][MATRIX_SIZE*3],signed char YUVMatrix[MATRIX_SIZE][MATRIX_SIZE])
    +void RGB2YCrCb(signed char pixelmatrix[MACRO_BLOCK_SIZE][MACRO_BLOCK_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 sample)
    {
    - unsigned int row, col, col_3;
    + unsigned int row, col, rowoffset, coloffset, xoffset, yoffset;
    for(row = 0;row < MATRIX_SIZE; row++) {
    - for(col = 0, col_3=0; col < MATRIX_SIZE; col++, col_3+=3) {
    - pixelmatrix[row][col_3] -= 128;
    - pixelmatrix[row][col_3+1] -= 128;
    - pixelmatrix[row][col_3+2] -= 128;
    - YUVMatrix[row][col] = RGB2Y(pixelmatrix[row][col_3+2],pixelmatrix[row][col_3+1],pixelmatrix[row][col_3]) - 128;
    - }
    - }
    -}
    -void RGB2Cr_matrix(signed char pixelmatrix[MATRIX_SIZE][MATRIX_SIZE*3],signed char YUVMatrix[MATRIX_SIZE][MATRIX_SIZE])
    -{
    - unsigned int row, col, col_3;
    - for(row = 0;row < MATRIX_SIZE; row++) {
    - for(col = 0, col_3=0; col < MATRIX_SIZE; col++, col_3+=3) {
    - YUVMatrix[row][col] = RGB2Cr(pixelmatrix[row][col_3+2],pixelmatrix[row][col_3+1],pixelmatrix[row][col_3]) - 128;
    + for(col = 0; col < MATRIX_SIZE; col++) {
    + coloffset = (sample&0x01)*8;
    + rowoffset = (sample&0x02)*4;
    + YMatrix[row][col] = RGB2Y(pixelmatrix[row+rowoffset][(col+coloffset)*3+2],pixelmatrix[row+rowoffset][(col+coloffset)*3+1],pixelmatrix[row+rowoffset][(col+coloffset)*3]) - 128;
    + if (col%2==0) {
    + yoffset = (sample&0x01)*4;
    + xoffset = (sample&0x02)*2;
    + if (row%2==0) {
    + CrMatrix[xoffset+(row>>1)][yoffset+(col>>1)] = RGB2Cr(pixelmatrix[row+rowoffset][(col+coloffset)*3+2],pixelmatrix[row+rowoffset][(col+coloffset)*3+1],pixelmatrix[row+rowoffset][(col+coloffset)*3]) - 128;
    + } else {
    + CbMatrix[xoffset+((row)>>2)][yoffset+(col>>2)] = RGB2Cb(pixelmatrix[row+rowoffset][(col+coloffset)*3+2],pixelmatrix[row+rowoffset][(col+coloffset)*3+1],pixelmatrix[row+rowoffset][(col+coloffset)*3]) - 128;
    }
    }
    -}
    -void RGB2Cb_matrix(signed char pixelmatrix[MATRIX_SIZE][MATRIX_SIZE*3],signed char YUVMatrix[MATRIX_SIZE][MATRIX_SIZE])
    -{
    - unsigned int row, col, col_3;
    - for(row = 0;row < MATRIX_SIZE; row++) {
    - for(col = 0, col_3; col < MATRIX_SIZE; col++, col_3) {
    - YUVMatrix[row][col] = RGB2Cb(pixelmatrix[row][col_3+2],pixelmatrix[row][col_3+1],pixelmatrix[row][col_3]) - 128;
    }
    }
    }
    - - - 1.5 mb-jpeg/bmp2jpg_mb/bmp2jpg_mb.c http://www.opencores.org/cvsweb.shtml/mb-jpeg/bmp2jpg_mb/bmp2jpg_mb.c.diff?r1=1.4&r2=1.5 (In the diff below, changes in quantity of whitespace are not shown.) Index: bmp2jpg_mb.c =================================================================== RCS file: /cvsroot/quickwayne/mb-jpeg/bmp2jpg_mb/bmp2jpg_mb.c,v retrieving revision 1.4 retrieving revision 1.5 diff -u -b -r1.4 -r1.5 --- bmp2jpg_mb.c 29 Jul 2006 00:22:51 -0000 1.4 +++ bmp2jpg_mb.c 15 Sep 2006 12:15:38 -0000 1.5 @@ -1,6 +1,7 @@ #include <stdio.h> #include <stdlib.h> +#include "ejpgl.h" #include "mb.h" #include "zzq.h" @@ -45,18 +46,27 @@ 0xEA, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8, 0xF9, 0xFA}; -signed char pixelmatrix[MATRIX_SIZE][MATRIX_SIZE*3]; -signed char pmatrix2[MATRIX_SIZE][MATRIX_SIZE]; //YUV domain pixels +signed char pixelmatrix[MACRO_BLOCK_SIZE][MACRO_BLOCK_SIZE*3]; +signed char YMatrix[MATRIX_SIZE][MATRIX_SIZE]; +signed char CrMatrix[MATRIX_SIZE][MATRIX_SIZE]; +signed char CbMatrix[MATRIX_SIZE][MATRIX_SIZE]; int ejpgl_error(int errno, void* remark); -void get_MB(int mb_row, int mb_col, signed char pixelmatrix[MATRIX_SIZE][MATRIX_SIZE*3]) { +static unsigned char buffer[MACRO_BLOCK_SIZE*3]; // move array on main memory + +void get_MB(int mb_row, int mb_col, signed char pixelmatrix[MACRO_BLOCK_SIZE][MACRO_BLOCK_SIZE*3]) { unsigned int row, col; int offset; - for(row = 0;row < MATRIX_SIZE; row++) { - offset = bmpsize-3*bmpheader->width*(row + 1 + mb_row*MATRIX_SIZE)+MATRIX_SIZE*3*mb_col; - memcpy(pixelmatrix[row], bmpimage + offset, MATRIX_SIZE*3); + for(row = 0;row < MACRO_BLOCK_SIZE; row++) { +// offset = bmpsize-3*bmpheader->width*(row + 1 + mb_row*MATRIX_SIZE)+MATRIX_SIZE*3*mb_col; +// memcpy(pixelmatrix[row], bmpimage + offset, MATRIX_SIZE*3); + offset = bmpsize-3*bmpheader->width*(row + 1 + mb_row*MACRO_BLOCK_SIZE)+MACRO_BLOCK_SIZE*3*mb_col; + memcpy(buffer, bmpimage + offset, MACRO_BLOCK_SIZE*3); + for(col = 0; col < MACRO_BLOCK_SIZE*3; col++) { + pixelmatrix[row][col] = buffer[col]- 128; + } } } @@ -87,6 +97,7 @@ int i; unsigned int col, cols, row, rows; int compression; + int sample; compression = 0; @@ -121,8 +132,8 @@ 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; + rows = bmpheader->height>>4; // 3; + cols = bmpheader->width>>4; // 3; if ((outfile = sysace_fopen("image01.jpg", "w")) == NULL) { ejpgl_error(eOPENOUTPUT_FILE, 0); @@ -140,12 +151,25 @@ // dct->zz/q->vlc dct call zz/q call vlc - RGB2Y_matrix(pixelmatrix, pmatrix2); +/* RGB2Y_matrix(pixelmatrix, pmatrix2); dct(pmatrix2, 0); RGB2Cr_matrix(pixelmatrix, pmatrix2); dct(pmatrix2, 1); RGB2Cb_matrix(pixelmatrix, pmatrix2); - dct(pmatrix2, 2); + dct(pmatrix2, 2); */ + for(sample=0;sample<5;sample++) { + if(sample<4) { + RGB2YCrCb(pixelmatrix,YMatrix,CrMatrix,CbMatrix,sample); + //Y-encoding + dct(YMatrix,0); + } else { + //Cr-encoding + dct(CrMatrix,1); + //Cb-encoding + dct(CbMatrix,2); + } + } + } } @@ -276,7 +300,11 @@ 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 + if(i==0) { + jpegheader->sof0.ComponentInfo[i][1] = 0x22; //4:2:0 subsampling + } else { + jpegheader->sof0.ComponentInfo[i][1] = 0x11; //4:2:0 subsampling + } jpegheader->sof0.ComponentInfo[i][2] = (i==0)? 0x00 : 0x01; //quantization table ID } //Start of Huffman Table Segment 1.2 mb-jpeg/bmp2jpg_mb/ejpgl.h http://www.opencores.org/cvsweb.shtml/mb-jpeg/bmp2jpg_mb/ejpgl.h.diff?r1=1.1&r2=1.2 (In the diff below, changes in quantity of whitespace are not shown.) Index: ejpgl.h =================================================================== RCS file: /cvsroot/quickwayne/mb-jpeg/bmp2jpg_mb/ejpgl.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -b -r1.1 -r1.2 --- ejpgl.h 28 Jul 2006 13:46:53 -0000 1.1 +++ ejpgl.h 15 Sep 2006 12:15:38 -0000 1.2 @@ -2,17 +2,7 @@ #define _EJPGL_H #define MATRIX_SIZE 8 - - -#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 - - +#define MACRO_BLOCK_SIZE 16 int idct8x8(int* fblock, char* sblock); 1.2 mb-jpeg/bmp2jpg_mb/io.h http://www.opencores.org/cvsweb.shtml/mb-jpeg/bmp2jpg_mb/io.h.diff?r1=1.1&r2=1.2 (In the diff below, changes in quantity of whitespace are not shown.) Index: io.h =================================================================== RCS file: /cvsroot/quickwayne/mb-jpeg/bmp2jpg_mb/io.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -b -r1.1 -r1.2 --- io.h 28 Jul 2006 13:46:53 -0000 1.1 +++ io.h 15 Sep 2006 12:15:38 -0000 1.2 @@ -1,6 +1,8 @@ #ifndef _IO_H #define _IO_H 1 -#define MATRIX_SIZE 8 + +#include "ejpgl.h" + typedef struct { unsigned int size; /* Header size in bytes */ int width,height; /* Width and height of image */ @@ -121,9 +123,7 @@ * 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 RGB2YCrCb(signed char pixelmatrix[MACRO_BLOCK_SIZE][MACRO_BLOCK_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 sample); void readjpegfile(FILE * file, unsigned char bitstream[]); 1.3 mb-jpeg/bmp2jpg_mb/mb.h http://www.opencores.org/cvsweb.shtml/mb-jpeg/bmp2jpg_mb/mb.h.diff?r1=1.2&r2=1.3 (In the diff below, changes in quantity of whitespace are not shown.) Index: mb.h =================================================================== RCS file: /cvsroot/quickwayne/mb-jpeg/bmp2jpg_mb/mb.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -b -r1.2 -r1.3 --- mb.h 28 Jul 2006 22:19:13 -0000 1.2 +++ mb.h 15 Sep 2006 12:15:38 -0000 1.3 @@ -37,16 +37,6 @@ #define eINVALID_BMP 3 #define eLARGE_INPUTFILE 4 -#if 0 -#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 - #endif

     
    Copyright (c) 1999 OPENCORES.ORG. All rights reserved.