📄 sp_uncompress.c
字号:
/* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = *//* S + P I M A G E D E C O M P R E S S I O N *//* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = *//* > > > > > ANSI C version 3.06 - 05/30/95 < < < < < *//* Arithmetic 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 0xA3#include "arithm.h"#include "sp_comm.c"#include "sp_decd.c"/* - - Definitions - - - - - - - - - - - - - - - - - - - - - - - - - - */#define CondValues 5#define CondModels 25/* - - Static variables - - - - - - - - - - - - - - - - - - - - - - - */Adaptive_Model set_model[CondModels];/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - *//* - - Implementations - - - - - - - - - - - - - - - - - - - - - - - - */int Read_Value(Adaptive_Model * model, int * ns){ int m, v, c, s = Read_Symbol(&code_file, model); *ns = s; if (!s) return 0; if ((m = set_table[s].bits) <= 10) c = Read_Bits(&code_file, m); else { c = Read_Bits(&code_file, 10); c |= Read_Bits(&code_file, m - 10) << 10; } v = (c >> 1) + set_table[s].bias; return (c & 1 ? -v : v);}/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */void Decode_First_Quadrant(Image_Coord d, int ** cf){ int i, j, k; for (i = 0; i < d.x; i++) for (j = 0; j < d.y; j++) cf[i][j] = Read_Value(set_model, &k); Reset_Model(set_model);}/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */void Decode_Quadrant(int q, Image_Coord d, int ** cf){ int i, j, k, mls, lm = CondValues - 1; int * ptr, * ps = buffer[0], * as = buffer[1], ls[4]; Image_Coord min, max; Select_Quadrant(q, d, &min, &max); for (ls[0] = i = 0; i < d.x; i++) { if (!(i & 1)) { ptr = cf[(i+min.x)>>1] + (min.y >> 1); ls[2] = Set(*ptr); ++ptr; for (j = 2; j < d.y; j += 2) { ls[1] = ls[2]; ls[2] = Set(*ptr); ++ptr; k = (ls[1] + ls[2] + 2) >> 2; ps[j-1] = ps[j] = CondValues * (k < lm ? k : lm); } ps[0] = ps[1]; ps[d.y-1] = ps[d.y-2]; } if (i) { ls[0] = ls[3] = as[0]; ls[2] = as[1]; as[d.y] = as[d.y-1]; } for (j = 0; j < d.y; j++) { if (i) { ls[1] = ls[2]; ls[2] = ls[3]; ls[3] = as[j+1]; mls = (ls[0] + ls[1] + ls[2] + ls[3] + 4) >> 3; } else mls = ls[0] >> 1; mls = ps[j] + (mls < lm ? mls : lm); cf[i+min.x][j+min.y] = Read_Value(set_model + mls, ls); as[j] = ls[0]; } }}/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */int ** Decode_Image(int lv, Image_Coord d){ int ** cf, i, k; if ((cf = (int **) malloc(d.x * sizeof(int *))) == NULL) Error(m_msg); for (k = 0; k < d.x; k++) if ((cf[k] = (int *) malloc(d.y * sizeof(int))) == NULL) Error(m_msg); k = 1 + (d.x > d.y ? d.x : d.y); for (i = 0; i <= 1; i++) if ((buffer[i] = (int *) malloc(k * sizeof(int))) == NULL) Error(m_msg); k = Read_Bits(&code_file, 5); for (i = 0; i < CondModels; i++) Create_Model(set_model + i, k); d.x >>= --lv; d.y >>= lv; Decode_First_Quadrant(d, cf); for (i = lv - 1; i >= 0; i--) { for (k = 1; k <= 3; k++) { Decode_Quadrant(k, d, cf); } d.x <<= 1; d.y <<= 1; } return cf;}/* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = *//* end of file < sp_uncompress.c > */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -