- if( (l_offset_x0_src < 0 ) || (l_offset_y0_src < 0 ) || (l_offset_x1_src < 0 ) || (l_offset_y1_src < 0 ) ){
- return OPJ_FALSE;
- }
- /* testcase 2977.pdf.asan.67.2198 */
- if ((OPJ_INT32)l_width_dest < 0 || (OPJ_INT32)l_height_dest < 0) {
- return OPJ_FALSE;
- }
- /*-----*/
-
- /* Compute the input buffer offset */
- l_start_offset_src = l_offset_x0_src + l_offset_y0_src * (OPJ_INT32)l_width_src;
- l_line_offset_src = l_offset_x1_src + l_offset_x0_src;
- l_end_offset_src = l_offset_y1_src * (OPJ_INT32)l_width_src - l_offset_x0_src;
-
- /* Compute the output buffer offset */
- l_start_offset_dest = (OPJ_INT32)(l_start_x_dest + l_start_y_dest * l_img_comp_dest->w);
- l_line_offset_dest = (OPJ_INT32)(l_img_comp_dest->w - l_width_dest);
-
- /* Move the output buffer to the first place where we will write*/
- l_dest_ptr = l_img_comp_dest->data + l_start_offset_dest;
-
- /*if (i == 0) {
- fprintf(stdout, "COMPO[%d]:\n",i);
- fprintf(stdout, "SRC: l_start_x_src=%d, l_start_y_src=%d, l_width_src=%d, l_height_src=%d\n"
- "\t tile offset:%d, %d, %d, %d\n"
- "\t buffer offset: %d; %d, %d\n",
- l_res->x0, l_res->y0, l_width_src, l_height_src,
- l_offset_x0_src, l_offset_y0_src, l_offset_x1_src, l_offset_y1_src,
- l_start_offset_src, l_line_offset_src, l_end_offset_src);
-
- fprintf(stdout, "DEST: l_start_x_dest=%d, l_start_y_dest=%d, l_width_dest=%d, l_height_dest=%d\n"
- "\t start offset: %d, line offset= %d\n",
- l_start_x_dest, l_start_y_dest, l_width_dest, l_height_dest, l_start_offset_dest, l_line_offset_dest);
- }*/
-
- switch (l_size_comp) {
- case 1:
- {
- OPJ_CHAR * l_src_ptr = (OPJ_CHAR*) p_data;
- l_src_ptr += l_start_offset_src; /* Move to the first place where we will read*/
-
- if (l_img_comp_src->sgnd) {
- for (j = 0 ; j < l_height_dest ; ++j) {
- for ( k = 0 ; k < l_width_dest ; ++k) {
- *(l_dest_ptr++) = (OPJ_INT32) (*(l_src_ptr++)); /* Copy only the data needed for the output image */
- }
-
- l_dest_ptr+= l_line_offset_dest; /* Move to the next place where we will write */
- l_src_ptr += l_line_offset_src ; /* Move to the next place where we will read */
- }
- }
- else {
- for ( j = 0 ; j < l_height_dest ; ++j ) {
- for ( k = 0 ; k < l_width_dest ; ++k) {
- *(l_dest_ptr++) = (OPJ_INT32) ((*(l_src_ptr++))&0xff);
- }
-
- l_dest_ptr+= l_line_offset_dest;
- l_src_ptr += l_line_offset_src;
- }
- }
-
- l_src_ptr += l_end_offset_src; /* Move to the end of this component-part of the input buffer */
- p_data = (OPJ_BYTE*) l_src_ptr; /* Keep the current position for the next component-part */
- }
- break;
- case 2:
- {
- OPJ_INT16 * l_src_ptr = (OPJ_INT16 *) p_data;
- l_src_ptr += l_start_offset_src;
-
- if (l_img_comp_src->sgnd) {
- for (j=0;j<l_height_dest;++j) {
- for (k=0;k<l_width_dest;++k) {
- *(l_dest_ptr++) = *(l_src_ptr++);
- }
-
- l_dest_ptr+= l_line_offset_dest;
- l_src_ptr += l_line_offset_src ;
- }
- }
- else {
- for (j=0;j<l_height_dest;++j) {
- for (k=0;k<l_width_dest;++k) {
- *(l_dest_ptr++) = (*(l_src_ptr++))&0xffff;
- }
-
- l_dest_ptr+= l_line_offset_dest;
- l_src_ptr += l_line_offset_src ;
- }
- }
-
- l_src_ptr += l_end_offset_src;
- p_data = (OPJ_BYTE*) l_src_ptr;
- }
- break;
- case 4:
- {
- OPJ_INT32 * l_src_ptr = (OPJ_INT32 *) p_data;
- l_src_ptr += l_start_offset_src;
-
- for (j=0;j<l_height_dest;++j) {
- for (k=0;k<l_width_dest;++k) {
- *(l_dest_ptr++) = (*(l_src_ptr++));
- }
-
- l_dest_ptr+= l_line_offset_dest;
- l_src_ptr += l_line_offset_src ;
- }
-
- l_src_ptr += l_end_offset_src;
- p_data = (OPJ_BYTE*) l_src_ptr;
- }
- break;