/* Includes ------------------------------------------------------------------*/
#include "stm32f4xx.h"
#include "platform_config.h"
//#include "ili9320.h"
#include "OV7660.h"
//#include "delay.h"
#include <string.h>
#include <stdio.h>#include "jpeglib.h"//#include <stm32f4xx.h>
#include "FSMC_SUB.h" 
#include "stm32f4xx_fsmc.h"
#include "stm32f4xx_rcc.h"
#include "stm32f4xx_gpio.h" 
#include "stm32f4xx_syscfg.h"
#include "delay.h"
#include "ascii.h" 
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
ErrorStatus HSEStartUpStatus;
#define WIDTH             320//图片宽度
#define HEIGHT            240//图片高度
#define QUALITY           0.5//压缩质量
#define RGB565_MASK_RED   0xF800//获取红色分量 
#define RGB565_MASK_GREEN 0x07E0//获取绿色分量
#define RGB565_MASK_BLUE  0x001F//获取蓝色分量    
//char ID_Mode=0x02;
u16 max_x=240,max_y=320;typedef struct
{
  vu16 LCD_REG;
  vu16 LCD_RAM;
} LCD_TypeDef;
u16 Txt_Color = 0xf800;//定义文本颜色
u16 Back_Ground =0xffff ;//定义背景色
u16 POINT_COLOR=0x001f;//定义画笔绿色#define LCD_Data_Addr    ((uint32_t)0x60020000)   //数据地址 
#define LCD_Reg_Addr     ((uint32_t)0x60000000)   //寄存器地址
#define LCD_BASE    ((u32)(0x60020000 | 0x60000000))
#define LCD         ((LCD_TypeDef *) LCD_BASE)
       
/* Private function prototypes -----------------------------------------------*/
void Demo_Init(void);
/* Private function prototypes -----------------------------------------------*/
void RCC_Configuration(void);
void NVIC_Configuration(void);
void GPIO_Configuration(void);
void USART_Configuration(void);
/* Private functions ---------------------------------------------------------*///加入的程序
extern void Compression(int width,int height,float quality); //设定图像要压缩图像的宽高,压缩质量 //需加入main2.c文件做子文件
extern unsigned int pt_buf;//缓冲区指针
extern unsigned char JPG_enc_buf[20000];//RGB565压缩后jpeg数据输出缓冲
extern unsigned char inbuf_buf[230400] __attribute__((at(0x68000000)));//输入缓冲 //需加入main2.c文件做子文件
void RGB565TORGB24(u32 num,u16 Pixel);     //加入的程序void RGB565TORGB24(u32 num,u16 Pixel)
{  
    u32 Addr=0;
    Addr=(num-1)*3;
    inbuf_buf[Addr]=(Pixel&RGB565_MASK_RED)>>11;  //R vs??  获取蓝色分量存入buf右移11位,变为最低5位
    inbuf_buf[Addr+1]=(Pixel&RGB565_MASK_GREEN)>>5; //G   获取绿色分量存入buf右移5位
    inbuf_buf[Addr+2]=(Pixel&RGB565_MASK_BLUE);    //B
    inbuf_buf[Addr]<<=3; 
    inbuf_buf[Addr+1]<<=2; 
    inbuf_buf[Addr+2]<<=3;  
}
/*******************************************************************************
* Function Name  : main
* Description    : Main program
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
u32 TimerCnt = 0;  //计数
u16 value; //unsigned int
u16 val;extern  unsigned char OV7660_init(void);int main(void)
{
u16 i=0; //串口,输入的字符
    static unsigned int temp7660 = 0;#ifdef DEBUG
    debug();
#endif
    
    Demo_Init();   
  /* Configure the system clocks */
  RCC_Configuration();
  /* NVIC Configuration */
  NVIC_Configuration();
  /* Configure the GPIOs */
  GPIO_Configuration();
  /* Configure the USART1 */
  USART_Configuration();
  printf("\r\n Welcome to www.PowerAVR.com \r\n");
  printf("\r\n Please Input Character From Keyboard \r\n");
//    LCD_CtrlLinesConfig();
    TFT_GPIO_Config();
    FSMC_NORAMTiminginit();
    Lcd_Init();
    TFT_Clear(0xf800);    delay_ms(1000);
    while(1!=OV7660_init()); // 初始化ov7660
        TimerCnt = 0;
        while(TimerCnt < 76800)  //320*240=76800
        {
            LCD_WriteRAM(0x0000); //TFT GRAM 数据  uint16_t LCD_RD_data(void)
//            LCD_RD_data(0x0000);
TimerCnt ++;
        }
    while(1) 
    {
        TimerCnt = 0;
        temp7660 = 0;//        CLK_init_ON(); // OV7660 XCLK 开
        while(value & 0x0800)    value = GPIOC->IDR;   // Vsync=H    
        while((~value) & 0x0800) value = GPIOC->IDR;   // Vhync=L   
        // TFT开窗口
        TFT_SetCursor(0,0);   
//        LCD_WriteReg(0x0050, 0);
        LCD_WR_CMD(0x0050, 0);
//        LCD_WriteReg(0x0052, 0);
        LCD_WR_CMD(0x0052, 0);
//        LCD_WriteReg(0x0051, 239);
        LCD_WR_CMD(0x0051, 239);
//        LCD_WriteReg(0x0053, 319);    
        LCD_WR_CMD(0x0053, 319);
TFT_SetCursor(0,0);//        LCD_WriteRAM_Prepare(); // 开显存
        delay_ms(10);
//        CLK_init_OFF(); //OV7660 XCLK 关
        while(TimerCnt < 76800)
        {
            RCLK_L; 
            RCLK_H;       
            value = GPIOC->IDR;
temp7660 ++;
            if(value & 0x0100) // HREF = H
            {
                if(temp7660 == 1)// 高字节
                {
                    val = value << 8;
                }
                else // 低字节
                {
                    val |= (value & 0x00ff);
                    temp7660 = 0;
//                  LCD_WriteRAM(val); //TFT GRAM 数据
// LCD_RD_data(val);
RGB565TORGB24(TimerCnt,val);/////
//val2=ili9320_BGR2RGB(val);
TimerCnt ++;
                }
            }
if(temp7660 ==0) RGB565TORGB24(TimerCnt,val);
        }
#ifdef MYDEBUG
            SendAString("开始压缩\r\n");
            #endif
            Compression(WIDTH,HEIGHT,QUALITY);//压缩 
            #ifdef MYDEBUG
            SendAString("压缩完毕\r\n");
            #endif    //加入的程序

if(USART_GetFlagStatus(USART1,USART_IT_RXNE)==SET)
{ //while(USART_GetFlagStatus(USART1,USART_IT_RXNE)!=SET)           
{
i = USART_ReceiveData(USART1);
printf("%c\n",i&0xFF);    /* print the input char */
}
}
    }
}
  /*******************************************************************************
* Function Name  : assert_failed
* Description    : Reports the name of the source file and the source line number
*                  where the assert_param error has occurred.
* Input          : - file: pointer to the source file name
*                  - line: assert_param error line source number
* Output         : None
* Return         : None
*******************************************************************************/
void assert_failed(u8* file, u32 line)

    /* User can add his own implementation to report the file name and line number */
  printf("\n\r Wrong parameter value detected on\r\n");
  printf("       file  %s\r\n", file);
  printf("       line  %d\r\n", line);
    
  /* Infinite loop */
  /* while (1)
  {
  } */
}
#endif
int fputc(int ch, FILE *f)
{
  /* Place your implementation of fputc here */
  /* e.g. write a character to the USART */
  USART_SendData(USART1, (u8) ch);  /* Loop until the end of transmission */
  while(USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET)
  {
  }  return ch;
}/******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/

解决方案 »

  1.   

    1 有没有执行Compression
    2 改改QUALITY看有没有变化
    3 看Compression是怎么写的
      

  2.   

    用7zip开源算法,包括现在很流行的CxImg开源中也是用到了这种算法,具体的有zlib开源类自己去下个看看吧.
      

  3.   

    有Compression算法啊
    1.压缩:
    /*************************************************************************
    *函数描述:全局变量和位定义
    *参数入口:
    *参数出口:
    *函数说明:   
    *************************************************************************/
    unsigned char JPG_enc_buf[20000];//jpeg 输出
    volatile unsigned int pt_buf;//缓冲区指针
    //__no_init  
    unsigned char inbuf_buf[230400] __attribute__((at(0x68000000)));//输入缓冲
    //注意:原始RGB565数据和输入缓冲用同一段外扩RAM!我这样做是节省空间!!
    jpeg_compress_info info1;
    JQUANT_TBL  JQUANT_TBL_2[2];   //量化表
    JHUFF_TBL   JHUFF_TBL_4[4];    //哈弗曼表
    unsigned char dcttab[3][512];  //DCT变换表
    //压缩
    void Compression(int width,int height,float quality) 
    {
      jpeg_compress_info *cinfo;  pt_buf=0;
      cinfo=jpeg_create_compress();    //cinfo:图像输入信息
      cinfo->image_width=width;//设定图片大小
      cinfo->image_height=height;
      cinfo->output=JPG_enc_buf;//设定输出缓冲位置
      jpeg_set_default(cinfo,quality);  
      jpeg_start_compress(cinfo);
      while(cinfo->next_line<cinfo->image_height)//一行一行的扫描进输入缓冲中 
      {
        jpeg_write_scanline(cinfo,&inbuf_buf[(cinfo->next_line*cinfo->image_width*3)]);
      }
      jpeg_finish_compress(cinfo);
    }
    2.量化
    //写入量化表
    void jmkr_write_quant_table(jpeg_compress_info *cinfo)
    {
      int i, j;
      for (i=0; i<NUM_QUANT_TBLS; i++) 
      {
        if (!cinfo->quant_table[i])
          continue;
        /* er */
        jutl_write_byte(0xFF, cinfo->output);    //quant table defination
        jutl_write_byte(DQT, cinfo->output);
        /* length, always 43h */
        jutl_write_byte(0x00, cinfo->output);
        jutl_write_byte(0x43, cinfo->output);
        /* ouput Pq & Tq */
        jutl_write_byte(i&0xFF, cinfo->output);
        /* all element */
        for (j=0; j<DCTSIZE2; j++) 
        {
          UINT8 Q = cinfo->quant_table[i]->quantval[j];
          jutl_write_byte(Q, cinfo->output);
        }
      }
    }
    void jint_add_quant_table( jpeg_compress_info *cinfo, 
                          unsigned int which_tbl, const UINT16 *base_tbl, 
                          float quality) 
    {
      int i;
      DCTVAL *qtblptr;
      cinfo->quant_table[which_tbl] = &JQUANT_TBL_2[which_tbl];//(JQUANT_TBL *)malloc(sizeof(JQUANT_TBL));  qtblptr = cinfo->quant_table[which_tbl]->quantval;
      for (i=0; i<DCTSIZE2; i++)
      {
        qtblptr[i] = (INT16)(base_tbl[i] * quality + 0.5);//根据压缩质量产生新的量化表
      }
      jutl_zigzag_sort(qtblptr);
    }
    void jint_std_quant_tables( jpeg_compress_info *cinfo ) 
    {
      const UINT16 std_luminance_quant_tbl[DCTSIZE2] = 
      {
        16,  11,  10,  16,  24,  40,  51,  61,
        12,  12,  14,  19,  26,  58,  60,  55,
        14,  13,  16,  24,  40,  57,  69,  56,
        14,  17,  22,  29,  51,  87,  80,  62,
        18,  22,  37,  56,  68, 109, 103,  77,
        24,  35,  55,  64,  81, 104, 113,  92,
        49,  64,  78,  87, 103, 121, 120, 101,
        72,  92,  95,  98, 112, 100, 103,  99
      };
      const UINT16 std_chrominance_quant_tbl[DCTSIZE2] =
       {
        17,  18,  24,  47,  99,  99,  99,  99,
        18,  21,  26,  66,  99,  99,  99,  99,
        24,  26,  56,  99,  99,  99,  99,  99,
        47,  66,  99,  99,  99,  99,  99,  99,
        99,  99,  99,  99,  99,  99,  99,  99,
        99,  99,  99,  99,  99,  99,  99,  99,
        99,  99,  99,  99,  99,  99,  99,  99,
        99,  99,  99,  99,  99,  99,  99,  99
      };
      jint_add_quant_table(cinfo, 0, std_luminance_quant_tbl, cinfo->quality);
      jint_add_quant_table(cinfo, 1, std_chrominance_quant_tbl, cinfo->quality);
    }这是我的压缩和量化程序,大侠帮忙看一下吧。在这论坛上有点慢,我留个QQ号码,可以再QQ上讨论吗?565690710.期待好心人~~~
      

  4.   

    还有大家有谁有完整的JPEG压缩和解压缩C的程序,可以参考一下吗???