Ejemplo n.º 1
0
Archivo: t2.c Proyecto: kerido/koapch
int t2_decode_packets(unsigned char *src, int len, j2k_image_t *img, j2k_cp_t *cp, int tileno, tcd_tile_t *tile) {
    unsigned char *c=src;
    pi_iterator_t *pi;
    pi=pi_create(img, cp, tileno);
    while (pi_next(pi)) {
        //fprintf(stderr, "compno=%d, resno=%d, precno=%d, layno=%d\n", pi->compno, pi->resno, pi->precno, pi->layno);
        c+=t2_decode_packet(c, src+len-c, tile, &cp->tcps[tileno], pi->compno, pi->resno, pi->precno, pi->layno);
    }
	pi_destroy(pi);
    return c-src;
}
Ejemplo n.º 2
0
int t2_decode_packets(opj_t2_t *t2, unsigned char *src, int len, int tileno, opj_tcd_tile_t *tile) {
	unsigned char *c = src;
	opj_pi_iterator_t *pi;
	int pino, e = 0;
	int n = 0;

	opj_image_t *image = t2->image;
	opj_cp_t *cp = t2->cp;
	
	/* create a packet iterator */
	pi = pi_create(image, cp, tileno);
	if(!pi) {
		/* TODO: throw an error */
		return -999;
	}
	
	for (pino = 0; pino <= cp->tcps[tileno].numpocs; pino++) {
		while (pi_next(&pi[pino])) {
			if ((cp->layer==0) || (cp->layer>=((pi[pino].layno)+1))) {
				e = t2_decode_packet(t2, c, src + len - c, tile, &cp->tcps[tileno], &pi[pino]);
			} else {
				e = 0;
			}
			
			/* progression in resolution */
			image->comps[pi[pino].compno].resno_decoded =	
				(e > 0) ? 
				int_max(pi[pino].resno, image->comps[pi[pino].compno].resno_decoded) 
				: image->comps[pi[pino].compno].resno_decoded;
			n++;
			
			if (e == -999) {		/* ADD */
				break;
			} else {
				c += e;
			}
		}
	}

	/* don't forget to release pi */
	pi_destroy(pi, cp, tileno);
	
	if (e == -999) {
		return e;
	}
	
    return (c - src);
}
Ejemplo n.º 3
0
int t2_decode_packets(opj_t2_t *t2, unsigned char *src, int len, int tileno, opj_tcd_tile_t *tile) {
	unsigned char *c = src;
	opj_pi_iterator_t *pi;
	int pino, e = 0;
	int n = 0,i;

	opj_volume_t *volume = t2->volume;
	opj_cp_t *cp = t2->cp;
	
	/* create a packet iterator */
	pi = pi_create(volume, cp, tileno);
	if(!pi) {
		/* TODO: throw an error */
		return -999;
	}
	
	for (pino = 0; pino <= cp->tcps[tileno].numpocs; pino++) {
		while (pi_next(&pi[pino])) {
			if ((cp->layer==0) || (cp->layer>=((pi[pino].layno)+1))) {
				e = t2_decode_packet(t2, c, src + len - c, tile, &cp->tcps[tileno], &pi[pino]);
			} else {
				e = 0;
			}
			
			/* progression in resolution */
			for (i = 0; i < 3; i++){
                volume->comps[pi[pino].compno].resno_decoded[i] = (e > 0) ? int_max(pi[pino].resno, volume->comps[pi[pino].compno].resno_decoded[i]) : volume->comps[pi[pino].compno].resno_decoded[i];
			}
			n++;
			
			if (e == -999) {		/* ADD */
				break;
			} else {
				opj_event_msg(t2->cinfo, EVT_INFO, "  t2_decode_packet: %d bytes decoded\n",e);
				c += e;
			}
		}
	}

	/* don't forget to release pi */
	pi_destroy(pi, cp, tileno);
	
	if (e == -999) {
		return e;
	}
	
    return (c - src);
}
Ejemplo n.º 4
0
int t2_decode_packets(opj_t2_t *t2, unsigned char *src, int len, int tileno, opj_tcd_tile_t *tile, opj_codestream_info_t *cstr_info) {
	unsigned char *c = src;
	opj_pi_iterator_t *pi;
	int pino, e = 0;
	int n = 0, curtp = 0;
	int tp_start_packno;

	opj_image_t *image = t2->image;
	opj_cp_t *cp = t2->cp;
	
	/* create a packet iterator */
	pi = pi_create_decode(image, cp, tileno);
	if(!pi) {
		/* TODO: throw an error */
		return -999;
	}

	tp_start_packno = 0;
	
	for (pino = 0; pino <= cp->tcps[tileno].numpocs; pino++) {
		while (pi_next(&pi[pino])) {
			if ((cp->layer==0) || (cp->layer>=((pi[pino].layno)+1))) {
				opj_packet_info_t *pack_info;
				if (cstr_info)
					pack_info = &cstr_info->tile[tileno].packet[cstr_info->packno];
				else
					pack_info = NULL;
				e = t2_decode_packet(t2, c, src + len - c, tile, &cp->tcps[tileno], &pi[pino], pack_info);
			} else {
				e = 0;
			}
			if(e == -999) return -999;
			/* progression in resolution */
			image->comps[pi[pino].compno].resno_decoded =	
				(e > 0) ? 
				int_max(pi[pino].resno, image->comps[pi[pino].compno].resno_decoded) 
				: image->comps[pi[pino].compno].resno_decoded;
			n++;

			/* INDEX >> */
			if(cstr_info) {
				opj_tile_info_t *info_TL = &cstr_info->tile[tileno];
				opj_packet_info_t *info_PK = &info_TL->packet[cstr_info->packno];
				if (!cstr_info->packno) {
					info_PK->start_pos = info_TL->end_header + 1;
				} else if (info_TL->packet[cstr_info->packno-1].end_pos >= (int)cstr_info->tile[tileno].tp[curtp].tp_end_pos){ /* New tile part*/
					info_TL->tp[curtp].tp_numpacks = cstr_info->packno - tp_start_packno; /* Number of packets in previous tile-part*/
          info_TL->tp[curtp].tp_start_pack = tp_start_packno;
					tp_start_packno = cstr_info->packno;
					curtp++;
					info_PK->start_pos = cstr_info->tile[tileno].tp[curtp].tp_end_header+1;
				} else {
					info_PK->start_pos = (cp->tp_on && info_PK->start_pos) ? info_PK->start_pos : info_TL->packet[cstr_info->packno - 1].end_pos + 1;
				}
				info_PK->end_pos = info_PK->start_pos + e - 1;
				info_PK->end_ph_pos += info_PK->start_pos - 1;	/* End of packet header which now only represents the distance 
																												// to start of packet is incremented by value of start of packet*/
				cstr_info->packno++;
			}
			/* << INDEX */
			
			if (e == -999) {		/* ADD */
				break;
			} else {
				c += e;
			}			
		}
	}
	/* INDEX >> */
	if(cstr_info) {
		cstr_info->tile[tileno].tp[curtp].tp_numpacks = cstr_info->packno - tp_start_packno; /* Number of packets in last tile-part*/
    cstr_info->tile[tileno].tp[curtp].tp_start_pack = tp_start_packno;
	}
	/* << INDEX */

	/* don't forget to release pi */
	pi_destroy(pi, cp, tileno);
	
	if (e == -999) {
		return e;
	}
	
	return (c - src);
}
Ejemplo n.º 5
0
bool t2_decode_packets(
            opj_t2_t *p_t2,
            OPJ_UINT32 p_tile_no,
            struct opj_tcd_tile *p_tile,
            OPJ_BYTE *p_src,
            OPJ_UINT32 * p_data_read,
            OPJ_UINT32 p_max_len,
            struct opj_codestream_info *p_cstr_info)
{
  OPJ_BYTE *l_current_data = p_src;
  opj_pi_iterator_t *l_pi = 00;
  OPJ_UINT32 pino;
  opj_image_t *l_image = p_t2->image;
  opj_cp_t *l_cp = p_t2->cp;
  opj_cp_t *cp = p_t2->cp;
  opj_tcp_t *l_tcp = &(p_t2->cp->tcps[p_tile_no]);
  OPJ_UINT32 l_nb_bytes_read;
  OPJ_UINT32 l_nb_pocs = l_tcp->numpocs + 1;
  opj_pi_iterator_t *l_current_pi = 00;
  OPJ_UINT32 curtp = 0;
  OPJ_UINT32 tp_start_packno;
  opj_packet_info_t *l_pack_info = 00;
  opj_image_comp_t* l_img_comp = 00;


  if
    (p_cstr_info)
  {
    l_pack_info = p_cstr_info->tile[p_tile_no].packet;
  }

  /* create a packet iterator */
  l_pi = pi_create_decode(l_image, l_cp, p_tile_no);
  if
    (!l_pi)
  {
    return false;
  }

  tp_start_packno = 0;
  l_current_pi = l_pi;

  for
    (pino = 0; pino <= l_tcp->numpocs; ++pino)
  {
    while
      (pi_next(l_current_pi))
    {

      if
        (l_tcp->num_layers_to_decode > l_current_pi->layno && l_current_pi->resno < p_tile->comps[l_current_pi->compno].minimum_num_resolutions)
      {
        l_nb_bytes_read = 0;
        if
          (! t2_decode_packet(p_t2,p_tile,l_tcp,l_current_pi,l_current_data,&l_nb_bytes_read,p_max_len,l_pack_info))
        {
          pi_destroy(l_pi,l_nb_pocs);
          return false;
        }
        l_img_comp = &(l_image->comps[l_current_pi->compno]);
        l_img_comp->resno_decoded = uint_max(l_current_pi->resno, l_img_comp->resno_decoded);
      }
      else
      {
        l_nb_bytes_read = 0;
        if
          (! t2_skip_packet(p_t2,p_tile,l_tcp,l_current_pi,l_current_data,&l_nb_bytes_read,p_max_len,l_pack_info))
        {
          pi_destroy(l_pi,l_nb_pocs);
          return false;
        }
      }
      l_current_data += l_nb_bytes_read;
      p_max_len -= l_nb_bytes_read;

      /* INDEX >> */
      if(p_cstr_info) {
        opj_tile_info_t *info_TL = &p_cstr_info->tile[p_tile_no];
        opj_packet_info_t *info_PK = &info_TL->packet[p_cstr_info->packno];
        if (!p_cstr_info->packno) {
          info_PK->start_pos = info_TL->end_header + 1;
        } else if (info_TL->packet[p_cstr_info->packno-1].end_pos >= (OPJ_INT32)p_cstr_info->tile[p_tile_no].tp[curtp].tp_end_pos){ // New tile part
          info_TL->tp[curtp].tp_numpacks = p_cstr_info->packno - tp_start_packno; // Number of packets in previous tile-part
          tp_start_packno = p_cstr_info->packno;
          curtp++;
          info_PK->start_pos = p_cstr_info->tile[p_tile_no].tp[curtp].tp_end_header+1;
        } else {
          info_PK->start_pos = (cp->m_specific_param.m_enc.m_tp_on && info_PK->start_pos) ? info_PK->start_pos : info_TL->packet[p_cstr_info->packno - 1].end_pos + 1;
        }
        info_PK->end_pos = info_PK->start_pos + l_nb_bytes_read - 1;
        info_PK->end_ph_pos += info_PK->start_pos - 1;  // End of packet header which now only represents the distance
        ++p_cstr_info->packno;
      }
      /* << INDEX */
    }
    ++l_current_pi;
  }
  /* INDEX >> */
  if
    (p_cstr_info) {
    p_cstr_info->tile[p_tile_no].tp[curtp].tp_numpacks = p_cstr_info->packno - tp_start_packno; // Number of packets in last tile-part
  }
  /* << INDEX */

  /* don't forget to release pi */
  pi_destroy(l_pi,l_nb_pocs);
  *p_data_read = l_current_data - p_src;
  return true;
}