sp_pack.c
来自「常用的无损压缩算法源代码」· C语言 代码 · 共 90 行
C
90 行
/* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = *//* S + P I M A G E D E C O M P R E S S I O N *//* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = *//* > > > > > ANSI C version 2.06 - 05/30/95 < < < < < *//* Huffman code version *//* Amir Said - amir@densis.fee.unicamp.br *//* Faculty of Electrical Engineering *//* University of Campinas (UNICAMP) - Campinas, SP 13081, Brazil *//* William A. Pearlman - pearlman@ecse.rpi.edu *//* Dept. of Electrical, Computer, and Systems Engineering *//* Rensselaer Polytechnic Institute - Troy, NY 12180, USA *//* Copyright (c) 1995 Amir Said & William A. Pearlman *//* This program is Copyright (c) by Amir Said and William A. Pearlman. It may be freely redistributed in its entirety provided that this copyright notice is not removed. It may not be sold for profit or incorporated in commercial programs without the written permission of the copyright holders. This program is provided as is, without any express or implied warranty, without even the warranty of fitness for a particular purpose.*//* - - Inclusion - - - - - - - - - - - - - - - - - - - - - - - - - - - */#define KEY_1 0xB4const char * FILE_TYPE = "SPP";#include "huffman.h"#include "sp_comm.c"#include "sp_code.c"/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - *//* - - Implementations - - - - - - - - - - - - - - - - - - - - - - - - */void Code_Quadrant(int q, Image_Coord d, int ** cf){ int i, j, s, v; long count[NumbSets]; Image_Coord min, max; Select_Quadrant(q, d, &min, &max); for (i = 0; i < NumbSets; i++) count[i] = 0; for (i = min.x; i < max.x; i++) for (j = min.y; j < max.y; j++) ++count[Set(cf[i][j])]; for (i = NumbSets; count[i-1] == 0; i--) ; Write_Code(&code_file, i, count); for (i = min.x; i < max.x; i++) for (j = min.y; j < max.y; j++) { s = Set(v = cf[i][j]); Write_Symbol(&code_file, s); if (s) Write_Bits(&code_file, set_table[s].bits, ((abs(v) - set_table[s].bias) << 1) + (v < 0)); }}/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */void Code_Image(int lv, Image_Coord d, int ** cf){ int i, k; lv -= 2; d.x >>= lv; d.y >>= lv; Code_Quadrant(0, d, cf); for (i = lv - 1; i >= 0; i--) { for (k = 1; k <= 3; k++) Code_Quadrant(k, d, cf); d.x <<= 1; d.y <<= 1; }}/* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = *//* end of file < sp_pack.c > */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?