Example #1
0
pre_process_data (j_compress_ptr cinfo,
                  JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
                  JDIMENSION in_rows_avail,
                  JSAMPIMAGE output_buf, JDIMENSION *out_row_group_ctr,
                  JDIMENSION out_row_groups_avail)
{
    my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
    int numrows, ci;
    JDIMENSION inrows;
    jpeg_component_info * compptr;

    while (*in_row_ctr < in_rows_avail &&
            *out_row_group_ctr < out_row_groups_avail) {
        /* Do color conversion to fill the conversion buffer. */
        inrows = in_rows_avail - *in_row_ctr;
        numrows = cinfo->max_v_samp_factor - prep->next_buf_row;
        numrows = (int) MIN((JDIMENSION) numrows, inrows);
        (*cinfo->cconvert->color_convert) (cinfo, input_buf + *in_row_ctr,
                                           prep->color_buf,
                                           (JDIMENSION) prep->next_buf_row,
                                           numrows);
        *in_row_ctr += numrows;
        prep->next_buf_row += numrows;
        prep->rows_to_go -= numrows;
        /* If at bottom of image, pad to fill the conversion buffer. */
        if (prep->rows_to_go == 0 &&
                prep->next_buf_row < cinfo->max_v_samp_factor) {
            for (ci = 0; ci < cinfo->num_components; ci++) {
                expand_bottom_edge(prep->color_buf[ci], cinfo->image_width,
                                   prep->next_buf_row, cinfo->max_v_samp_factor);
            }
            prep->next_buf_row = cinfo->max_v_samp_factor;
        }
        /* If we've filled the conversion buffer, empty it. */
        if (prep->next_buf_row == cinfo->max_v_samp_factor) {
            (*cinfo->downsample->downsample) (cinfo,
                                              prep->color_buf, (JDIMENSION) 0,
                                              output_buf, *out_row_group_ctr);
            prep->next_buf_row = 0;
            (*out_row_group_ctr)++;
        }
        /* If at bottom of image, pad the output to a full iMCU height.
         * Note we assume the caller is providing a one-iMCU-height output buffer!
         */
        if (prep->rows_to_go == 0 &&
                *out_row_group_ctr < out_row_groups_avail) {
            for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
                    ci++, compptr++) {
                numrows = (compptr->v_samp_factor * compptr->DCT_v_scaled_size) /
                          cinfo->min_DCT_v_scaled_size;
                expand_bottom_edge(output_buf[ci],
                                   compptr->width_in_blocks * compptr->DCT_h_scaled_size,
                                   (int) (*out_row_group_ctr * numrows),
                                   (int) (out_row_groups_avail * numrows));
            }
            *out_row_group_ctr = out_row_groups_avail;
            break;            /* can exit outer loop without test */
        }
    }
}
Example #2
0
pre_process_context (j_compress_ptr cinfo,
                     JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
                     JDIMENSION in_rows_avail,
                     JSAMPIMAGE output_buf, JDIMENSION *out_row_group_ctr,
                     JDIMENSION out_row_groups_avail)
{
    my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
    int numrows, ci;
    int buf_height = cinfo->max_v_samp_factor * 3;
    JDIMENSION inrows;

    while (*out_row_group_ctr < out_row_groups_avail) {
        if (*in_row_ctr < in_rows_avail) {
            /* Do color conversion to fill the conversion buffer. */
            inrows = in_rows_avail - *in_row_ctr;
            numrows = prep->next_buf_stop - prep->next_buf_row;
            numrows = (int) MIN((JDIMENSION) numrows, inrows);
            (*cinfo->cconvert->color_convert) (cinfo, input_buf + *in_row_ctr,
                                               prep->color_buf,
                                               (JDIMENSION) prep->next_buf_row,
                                               numrows);
            /* Pad at top of image, if first time through */
            if (prep->rows_to_go == cinfo->image_height) {
                for (ci = 0; ci < cinfo->num_components; ci++) {
                    int row;
                    for (row = 1; row <= cinfo->max_v_samp_factor; row++) {
                        jcopy_sample_rows(prep->color_buf[ci], 0,
                                          prep->color_buf[ci], -row,
                                          1, cinfo->image_width);
                    }
                }
            }
            *in_row_ctr += numrows;
            prep->next_buf_row += numrows;
            prep->rows_to_go -= numrows;
        } else {
            /* Return for more data, unless we are at the bottom of the image. */
            if (prep->rows_to_go != 0)
                break;
            /* When at bottom of image, pad to fill the conversion buffer. */
            if (prep->next_buf_row < prep->next_buf_stop) {
                for (ci = 0; ci < cinfo->num_components; ci++) {
                    expand_bottom_edge(prep->color_buf[ci], cinfo->image_width,
                                       prep->next_buf_row, prep->next_buf_stop);
                }
                prep->next_buf_row = prep->next_buf_stop;
            }
        }
        /* If we've gotten enough data, downsample a row group. */
        if (prep->next_buf_row == prep->next_buf_stop) {
            (*cinfo->downsample->downsample) (cinfo,
                                              prep->color_buf,
                                              (JDIMENSION) prep->this_row_group,
                                              output_buf, *out_row_group_ctr);
            (*out_row_group_ctr)++;
            /* Advance pointers with wraparound as necessary. */
            prep->this_row_group += cinfo->max_v_samp_factor;
            if (prep->this_row_group >= buf_height)
                prep->this_row_group = 0;
            if (prep->next_buf_row >= buf_height)
                prep->next_buf_row = 0;
            prep->next_buf_stop = prep->next_buf_row + cinfo->max_v_samp_factor;
        }
    }
}
Example #3
0
METHODDEF void
pre_process_context( j_compress_ptr cinfo,
                     JSAMPARRAY input_buf, JDIMENSION * in_row_ctr,
                     JDIMENSION in_rows_avail,
                     JSAMPIMAGE output_buf, JDIMENSION * out_row_group_ctr,
                     JDIMENSION out_row_groups_avail ) {
    my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
    int numrows, ci;
    int buf_height = cinfo->max_v_samp_factor * 3;
    JDIMENSION inrows;
    jpeg_component_info * compptr;

    while ( *out_row_group_ctr < out_row_groups_avail ) {
        if ( *in_row_ctr < in_rows_avail ) {
            /* Do color conversion to fill the conversion buffer. */
            inrows = in_rows_avail - *in_row_ctr;
            numrows = prep->next_buf_stop - prep->next_buf_row;
            numrows = (int) MIN( (JDIMENSION) numrows, inrows );
            ( *cinfo->cconvert->color_convert )( cinfo, input_buf + *in_row_ctr,
                                                 prep->color_buf,
                                                 (JDIMENSION) prep->next_buf_row,
                                                 numrows );
            /* Pad at top of image, if first time through */
            if ( prep->rows_to_go == cinfo->image_height ) {
                for ( ci = 0; ci < cinfo->num_components; ci++ ) {
                    int row;
                    for ( row = 1; row <= cinfo->max_v_samp_factor; row++ ) {
                        jcopy_sample_rows( prep->color_buf[ci], 0,
                                           prep->color_buf[ci], -row,
                                           1, cinfo->image_width );
                    }
                }
            }
            *in_row_ctr += numrows;
            prep->next_buf_row += numrows;
            prep->rows_to_go -= numrows;
        } else {
            /* Return for more data, unless we are at the bottom of the image. */
            if ( prep->rows_to_go != 0 ) {
                break;
            }
        }
        /* If at bottom of image, pad to fill the conversion buffer. */
        if ( ( prep->rows_to_go == 0 ) &&
            ( prep->next_buf_row < prep->next_buf_stop ) ) {
            for ( ci = 0; ci < cinfo->num_components; ci++ ) {
                expand_bottom_edge( prep->color_buf[ci], cinfo->image_width,
                                    prep->next_buf_row, prep->next_buf_stop );
            }
            prep->next_buf_row = prep->next_buf_stop;
        }
        /* If we've gotten enough data, downsample a row group. */
        if ( prep->next_buf_row == prep->next_buf_stop ) {
            ( *cinfo->downsample->downsample )( cinfo,
                                                prep->color_buf,
                                                (JDIMENSION) prep->this_row_group,
                                                output_buf, *out_row_group_ctr );
            ( *out_row_group_ctr )++;
            /* Advance pointers with wraparound as necessary. */
            prep->this_row_group += cinfo->max_v_samp_factor;
            if ( prep->this_row_group >= buf_height ) {
                prep->this_row_group = 0;
            }
            if ( prep->next_buf_row >= buf_height ) {
                prep->next_buf_row = 0;
            }
            prep->next_buf_stop = prep->next_buf_row + cinfo->max_v_samp_factor;
        }
        /* If at bottom of image, pad the output to a full iMCU height.
         * Note we assume the caller is providing a one-iMCU-height output buffer!
         */
        if ( ( prep->rows_to_go == 0 ) &&
            ( *out_row_group_ctr < out_row_groups_avail ) ) {
            for ( ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
                  ci++, compptr++ ) {
                expand_bottom_edge( output_buf[ci],
                                   compptr->width_in_blocks * DCTSIZE,
                                   (int) ( *out_row_group_ctr * compptr->v_samp_factor ),
                                   (int) ( out_row_groups_avail * compptr->v_samp_factor ) );
            }
            *out_row_group_ctr = out_row_groups_avail;
            break;      /* can exit outer loop without test */
        }
    }
}