| 129 | |
| 130 | |
| 131 | static int encode_bitstream(FlashSVContext *s, AVFrame *p, uint8_t *buf, int buf_size, |
| 132 | int block_width, int block_height, uint8_t *previous_frame, int* I_frame) { |
| 133 | |
| 134 | PutBitContext pb; |
| 135 | int h_blocks, v_blocks, h_part, v_part, i, j; |
| 136 | int buf_pos, res; |
| 137 | int pred_blocks = 0; |
| 138 | |
| 139 | init_put_bits(&pb, buf, buf_size*8); |
| 140 | |
| 141 | put_bits(&pb, 4, (block_width/16)-1); |
| 142 | put_bits(&pb, 12, s->image_width); |
| 143 | put_bits(&pb, 4, (block_height/16)-1); |
| 144 | put_bits(&pb, 12, s->image_height); |
| 145 | flush_put_bits(&pb); |
| 146 | buf_pos=4; |
| 147 | |
| 148 | h_blocks = s->image_width / block_width; |
| 149 | h_part = s->image_width % block_width; |
| 150 | v_blocks = s->image_height / block_height; |
| 151 | v_part = s->image_height % block_height; |
| 152 | |
| 153 | /* loop over all block columns */ |
| 154 | for (j = 0; j < v_blocks + (v_part?1:0); j++) |
| 155 | { |
| 156 | |
| 157 | int hp = j*block_height; // horiz position in frame |
| 158 | int hs = (j<v_blocks)?block_height:v_part; // size of block |
| 159 | |
| 160 | /* loop over all block rows */ |
| 161 | for (i = 0; i < h_blocks + (h_part?1:0); i++) |
| 162 | { |
| 163 | int wp = i*block_width; // vert position in frame |
| 164 | int ws = (i<h_blocks)?block_width:h_part; // size of block |
| 165 | int ret=Z_OK; |
| 166 | uint8_t *ptr; |
| 167 | |
| 168 | ptr = buf+buf_pos; |
| 169 | |
| 170 | //copy the block to the temp buffer before compression (if it differs from the previous frame's block) |
| 171 | res = copy_region_enc(p->data[0], s->tmpblock, s->image_height-(hp+hs+1), wp, hs, ws, p->linesize[0], previous_frame); |
| 172 | |
| 173 | if (res || *I_frame) { |
| 174 | unsigned long zsize; |
| 175 | zsize = 3*block_width*block_height; |
| 176 | ret = compress2(ptr+2, &zsize, s->tmpblock, 3*ws*hs, 9); |
| 177 | |
| 178 | |
| 179 | //ret = deflateReset(&(s->zstream)); |
| 180 | if (ret != Z_OK) |
| 181 | av_log(s->avctx, AV_LOG_ERROR, "error while compressing block %dx%d\n", i, j); |
| 182 | |
| 183 | bytestream_put_be16(&ptr,(unsigned int)zsize); |
| 184 | buf_pos += zsize+2; |
| 185 | //av_log(avctx, AV_LOG_ERROR, "buf_pos = %d\n", buf_pos); |
| 186 | } else { |
| 187 | pred_blocks++; |
| 188 | bytestream_put_be16(&ptr,0); |
no test coverage detected