kusano 7d535a
/*
kusano 7d535a
 * jctrans.c
kusano 7d535a
 *
kusano 7d535a
 * Copyright (C) 1995-1998, Thomas G. Lane.
kusano 7d535a
 * Modified 2000-2012 by Guido Vollbeding.
kusano 7d535a
 * This file is part of the Independent JPEG Group's software.
kusano 7d535a
 * For conditions of distribution and use, see the accompanying README file.
kusano 7d535a
 *
kusano 7d535a
 * This file contains library routines for transcoding compression,
kusano 7d535a
 * that is, writing raw DCT coefficient arrays to an output JPEG file.
kusano 7d535a
 * The routines in jcapimin.c will also be needed by a transcoder.
kusano 7d535a
 */
kusano 7d535a
kusano 7d535a
#define JPEG_INTERNALS
kusano 7d535a
#include "jinclude.h"
kusano 7d535a
#include "jpeglib.h"
kusano 7d535a
kusano 7d535a
kusano 7d535a
/* Forward declarations */
kusano 7d535a
LOCAL(void) transencode_master_selection
kusano 7d535a
	JPP((j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays));
kusano 7d535a
LOCAL(void) transencode_coef_controller
kusano 7d535a
	JPP((j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays));
kusano 7d535a
kusano 7d535a
kusano 7d535a
/*
kusano 7d535a
 * Compression initialization for writing raw-coefficient data.
kusano 7d535a
 * Before calling this, all parameters and a data destination must be set up.
kusano 7d535a
 * Call jpeg_finish_compress() to actually write the data.
kusano 7d535a
 *
kusano 7d535a
 * The number of passed virtual arrays must match cinfo->num_components.
kusano 7d535a
 * Note that the virtual arrays need not be filled or even realized at
kusano 7d535a
 * the time write_coefficients is called; indeed, if the virtual arrays
kusano 7d535a
 * were requested from this compression object's memory manager, they
kusano 7d535a
 * typically will be realized during this routine and filled afterwards.
kusano 7d535a
 */
kusano 7d535a
kusano 7d535a
GLOBAL(void)
kusano 7d535a
jpeg_write_coefficients (j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays)
kusano 7d535a
{
kusano 7d535a
  if (cinfo->global_state != CSTATE_START)
kusano 7d535a
    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
kusano 7d535a
  /* Mark all tables to be written */
kusano 7d535a
  jpeg_suppress_tables(cinfo, FALSE);
kusano 7d535a
  /* (Re)initialize error mgr and destination modules */
kusano 7d535a
  (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
kusano 7d535a
  (*cinfo->dest->init_destination) (cinfo);
kusano 7d535a
  /* Perform master selection of active modules */
kusano 7d535a
  transencode_master_selection(cinfo, coef_arrays);
kusano 7d535a
  /* Wait for jpeg_finish_compress() call */
kusano 7d535a
  cinfo->next_scanline = 0;	/* so jpeg_write_marker works */
kusano 7d535a
  cinfo->global_state = CSTATE_WRCOEFS;
kusano 7d535a
}
kusano 7d535a
kusano 7d535a
kusano 7d535a
/*
kusano 7d535a
 * Initialize the compression object with default parameters,
kusano 7d535a
 * then copy from the source object all parameters needed for lossless
kusano 7d535a
 * transcoding.  Parameters that can be varied without loss (such as
kusano 7d535a
 * scan script and Huffman optimization) are left in their default states.
kusano 7d535a
 */
kusano 7d535a
kusano 7d535a
GLOBAL(void)
kusano 7d535a
jpeg_copy_critical_parameters (j_decompress_ptr srcinfo,
kusano 7d535a
			       j_compress_ptr dstinfo)
kusano 7d535a
{
kusano 7d535a
  JQUANT_TBL ** qtblptr;
kusano 7d535a
  jpeg_component_info *incomp, *outcomp;
kusano 7d535a
  JQUANT_TBL *c_quant, *slot_quant;
kusano 7d535a
  int tblno, ci, coefi;
kusano 7d535a
kusano 7d535a
  /* Safety check to ensure start_compress not called yet. */
kusano 7d535a
  if (dstinfo->global_state != CSTATE_START)
kusano 7d535a
    ERREXIT1(dstinfo, JERR_BAD_STATE, dstinfo->global_state);
kusano 7d535a
  /* Copy fundamental image dimensions */
kusano 7d535a
  dstinfo->image_width = srcinfo->image_width;
kusano 7d535a
  dstinfo->image_height = srcinfo->image_height;
kusano 7d535a
  dstinfo->input_components = srcinfo->num_components;
kusano 7d535a
  dstinfo->in_color_space = srcinfo->jpeg_color_space;
kusano 7d535a
  dstinfo->jpeg_width = srcinfo->output_width;
kusano 7d535a
  dstinfo->jpeg_height = srcinfo->output_height;
kusano 7d535a
  dstinfo->min_DCT_h_scaled_size = srcinfo->min_DCT_h_scaled_size;
kusano 7d535a
  dstinfo->min_DCT_v_scaled_size = srcinfo->min_DCT_v_scaled_size;
kusano 7d535a
  /* Initialize all parameters to default values */
kusano 7d535a
  jpeg_set_defaults(dstinfo);
kusano 7d535a
  /* jpeg_set_defaults may choose wrong colorspace, eg YCbCr if input is RGB.
kusano 7d535a
   * Fix it to get the right header markers for the image colorspace.
kusano 7d535a
   * Note: Entropy table assignment in jpeg_set_colorspace depends
kusano 7d535a
   * on color_transform.
kusano 7d535a
   */
kusano 7d535a
  dstinfo->color_transform = srcinfo->color_transform;
kusano 7d535a
  jpeg_set_colorspace(dstinfo, srcinfo->jpeg_color_space);
kusano 7d535a
  dstinfo->data_precision = srcinfo->data_precision;
kusano 7d535a
  dstinfo->CCIR601_sampling = srcinfo->CCIR601_sampling;
kusano 7d535a
  /* Copy the source's quantization tables. */
kusano 7d535a
  for (tblno = 0; tblno < NUM_QUANT_TBLS; tblno++) {
kusano 7d535a
    if (srcinfo->quant_tbl_ptrs[tblno] != NULL) {
kusano 7d535a
      qtblptr = & dstinfo->quant_tbl_ptrs[tblno];
kusano 7d535a
      if (*qtblptr == NULL)
kusano 7d535a
	*qtblptr = jpeg_alloc_quant_table((j_common_ptr) dstinfo);
kusano 7d535a
      MEMCOPY((*qtblptr)->quantval,
kusano 7d535a
	      srcinfo->quant_tbl_ptrs[tblno]->quantval,
kusano 7d535a
	      SIZEOF((*qtblptr)->quantval));
kusano 7d535a
      (*qtblptr)->sent_table = FALSE;
kusano 7d535a
    }
kusano 7d535a
  }
kusano 7d535a
  /* Copy the source's per-component info.
kusano 7d535a
   * Note we assume jpeg_set_defaults has allocated the dest comp_info array.
kusano 7d535a
   */
kusano 7d535a
  dstinfo->num_components = srcinfo->num_components;
kusano 7d535a
  if (dstinfo->num_components < 1 || dstinfo->num_components > MAX_COMPONENTS)
kusano 7d535a
    ERREXIT2(dstinfo, JERR_COMPONENT_COUNT, dstinfo->num_components,
kusano 7d535a
	     MAX_COMPONENTS);
kusano 7d535a
  for (ci = 0, incomp = srcinfo->comp_info, outcomp = dstinfo->comp_info;
kusano 7d535a
       ci < dstinfo->num_components; ci++, incomp++, outcomp++) {
kusano 7d535a
    outcomp->component_id = incomp->component_id;
kusano 7d535a
    outcomp->h_samp_factor = incomp->h_samp_factor;
kusano 7d535a
    outcomp->v_samp_factor = incomp->v_samp_factor;
kusano 7d535a
    outcomp->quant_tbl_no = incomp->quant_tbl_no;
kusano 7d535a
    /* Make sure saved quantization table for component matches the qtable
kusano 7d535a
     * slot.  If not, the input file re-used this qtable slot.
kusano 7d535a
     * IJG encoder currently cannot duplicate this.
kusano 7d535a
     */
kusano 7d535a
    tblno = outcomp->quant_tbl_no;
kusano 7d535a
    if (tblno < 0 || tblno >= NUM_QUANT_TBLS ||
kusano 7d535a
	srcinfo->quant_tbl_ptrs[tblno] == NULL)
kusano 7d535a
      ERREXIT1(dstinfo, JERR_NO_QUANT_TABLE, tblno);
kusano 7d535a
    slot_quant = srcinfo->quant_tbl_ptrs[tblno];
kusano 7d535a
    c_quant = incomp->quant_table;
kusano 7d535a
    if (c_quant != NULL) {
kusano 7d535a
      for (coefi = 0; coefi < DCTSIZE2; coefi++) {
kusano 7d535a
	if (c_quant->quantval[coefi] != slot_quant->quantval[coefi])
kusano 7d535a
	  ERREXIT1(dstinfo, JERR_MISMATCHED_QUANT_TABLE, tblno);
kusano 7d535a
      }
kusano 7d535a
    }
kusano 7d535a
    /* Note: we do not copy the source's entropy table assignments;
kusano 7d535a
     * instead we rely on jpeg_set_colorspace to have made a suitable choice.
kusano 7d535a
     */
kusano 7d535a
  }
kusano 7d535a
  /* Also copy JFIF version and resolution information, if available.
kusano 7d535a
   * Strictly speaking this isn't "critical" info, but it's nearly
kusano 7d535a
   * always appropriate to copy it if available.  In particular,
kusano 7d535a
   * if the application chooses to copy JFIF 1.02 extension markers from
kusano 7d535a
   * the source file, we need to copy the version to make sure we don't
kusano 7d535a
   * emit a file that has 1.02 extensions but a claimed version of 1.01.
kusano 7d535a
   * We will *not*, however, copy version info from mislabeled "2.01" files.
kusano 7d535a
   */
kusano 7d535a
  if (srcinfo->saw_JFIF_marker) {
kusano 7d535a
    if (srcinfo->JFIF_major_version == 1) {
kusano 7d535a
      dstinfo->JFIF_major_version = srcinfo->JFIF_major_version;
kusano 7d535a
      dstinfo->JFIF_minor_version = srcinfo->JFIF_minor_version;
kusano 7d535a
    }
kusano 7d535a
    dstinfo->density_unit = srcinfo->density_unit;
kusano 7d535a
    dstinfo->X_density = srcinfo->X_density;
kusano 7d535a
    dstinfo->Y_density = srcinfo->Y_density;
kusano 7d535a
  }
kusano 7d535a
}
kusano 7d535a
kusano 7d535a
kusano 7d535a
/*
kusano 7d535a
 * Master selection of compression modules for transcoding.
kusano 7d535a
 * This substitutes for jcinit.c's initialization of the full compressor.
kusano 7d535a
 */
kusano 7d535a
kusano 7d535a
LOCAL(void)
kusano 7d535a
transencode_master_selection (j_compress_ptr cinfo,
kusano 7d535a
			      jvirt_barray_ptr * coef_arrays)
kusano 7d535a
{
kusano 7d535a
  /* Initialize master control (includes parameter checking/processing) */
kusano 7d535a
  jinit_c_master_control(cinfo, TRUE /* transcode only */);
kusano 7d535a
kusano 7d535a
  /* Entropy encoding: either Huffman or arithmetic coding. */
kusano 7d535a
  if (cinfo->arith_code)
kusano 7d535a
    jinit_arith_encoder(cinfo);
kusano 7d535a
  else {
kusano 7d535a
    jinit_huff_encoder(cinfo);
kusano 7d535a
  }
kusano 7d535a
kusano 7d535a
  /* We need a special coefficient buffer controller. */
kusano 7d535a
  transencode_coef_controller(cinfo, coef_arrays);
kusano 7d535a
kusano 7d535a
  jinit_marker_writer(cinfo);
kusano 7d535a
kusano 7d535a
  /* We can now tell the memory manager to allocate virtual arrays. */
kusano 7d535a
  (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
kusano 7d535a
kusano 7d535a
  /* Write the datastream header (SOI, JFIF) immediately.
kusano 7d535a
   * Frame and scan headers are postponed till later.
kusano 7d535a
   * This lets application insert special markers after the SOI.
kusano 7d535a
   */
kusano 7d535a
  (*cinfo->marker->write_file_header) (cinfo);
kusano 7d535a
}
kusano 7d535a
kusano 7d535a
kusano 7d535a
/*
kusano 7d535a
 * The rest of this file is a special implementation of the coefficient
kusano 7d535a
 * buffer controller.  This is similar to jccoefct.c, but it handles only
kusano 7d535a
 * output from presupplied virtual arrays.  Furthermore, we generate any
kusano 7d535a
 * dummy padding blocks on-the-fly rather than expecting them to be present
kusano 7d535a
 * in the arrays.
kusano 7d535a
 */
kusano 7d535a
kusano 7d535a
/* Private buffer controller object */
kusano 7d535a
kusano 7d535a
typedef struct {
kusano 7d535a
  struct jpeg_c_coef_controller pub; /* public fields */
kusano 7d535a
kusano 7d535a
  JDIMENSION iMCU_row_num;	/* iMCU row # within image */
kusano 7d535a
  JDIMENSION mcu_ctr;		/* counts MCUs processed in current row */
kusano 7d535a
  int MCU_vert_offset;		/* counts MCU rows within iMCU row */
kusano 7d535a
  int MCU_rows_per_iMCU_row;	/* number of such rows needed */
kusano 7d535a
kusano 7d535a
  /* Virtual block array for each component. */
kusano 7d535a
  jvirt_barray_ptr * whole_image;
kusano 7d535a
kusano 7d535a
  /* Workspace for constructing dummy blocks at right/bottom edges. */
kusano 7d535a
  JBLOCKROW dummy_buffer[C_MAX_BLOCKS_IN_MCU];
kusano 7d535a
} my_coef_controller;
kusano 7d535a
kusano 7d535a
typedef my_coef_controller * my_coef_ptr;
kusano 7d535a
kusano 7d535a
kusano 7d535a
LOCAL(void)
kusano 7d535a
start_iMCU_row (j_compress_ptr cinfo)
kusano 7d535a
/* Reset within-iMCU-row counters for a new row */
kusano 7d535a
{
kusano 7d535a
  my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
kusano 7d535a
kusano 7d535a
  /* In an interleaved scan, an MCU row is the same as an iMCU row.
kusano 7d535a
   * In a noninterleaved scan, an iMCU row has v_samp_factor MCU rows.
kusano 7d535a
   * But at the bottom of the image, process only what's left.
kusano 7d535a
   */
kusano 7d535a
  if (cinfo->comps_in_scan > 1) {
kusano 7d535a
    coef->MCU_rows_per_iMCU_row = 1;
kusano 7d535a
  } else {
kusano 7d535a
    if (coef->iMCU_row_num < (cinfo->total_iMCU_rows-1))
kusano 7d535a
      coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
kusano 7d535a
    else
kusano 7d535a
      coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
kusano 7d535a
  }
kusano 7d535a
kusano 7d535a
  coef->mcu_ctr = 0;
kusano 7d535a
  coef->MCU_vert_offset = 0;
kusano 7d535a
}
kusano 7d535a
kusano 7d535a
kusano 7d535a
/*
kusano 7d535a
 * Initialize for a processing pass.
kusano 7d535a
 */
kusano 7d535a
kusano 7d535a
METHODDEF(void)
kusano 7d535a
start_pass_coef (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
kusano 7d535a
{
kusano 7d535a
  my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
kusano 7d535a
kusano 7d535a
  if (pass_mode != JBUF_CRANK_DEST)
kusano 7d535a
    ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
kusano 7d535a
kusano 7d535a
  coef->iMCU_row_num = 0;
kusano 7d535a
  start_iMCU_row(cinfo);
kusano 7d535a
}
kusano 7d535a
kusano 7d535a
kusano 7d535a
/*
kusano 7d535a
 * Process some data.
kusano 7d535a
 * We process the equivalent of one fully interleaved MCU row ("iMCU" row)
kusano 7d535a
 * per call, ie, v_samp_factor block rows for each component in the scan.
kusano 7d535a
 * The data is obtained from the virtual arrays and fed to the entropy coder.
kusano 7d535a
 * Returns TRUE if the iMCU row is completed, FALSE if suspended.
kusano 7d535a
 *
kusano 7d535a
 * NB: input_buf is ignored; it is likely to be a NULL pointer.
kusano 7d535a
 */
kusano 7d535a
kusano 7d535a
METHODDEF(boolean)
kusano 7d535a
compress_output (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
kusano 7d535a
{
kusano 7d535a
  my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
kusano 7d535a
  JDIMENSION MCU_col_num;	/* index of current MCU within row */
kusano 7d535a
  JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
kusano 7d535a
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
kusano 7d535a
  int blkn, ci, xindex, yindex, yoffset, blockcnt;
kusano 7d535a
  JDIMENSION start_col;
kusano 7d535a
  JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
kusano 7d535a
  JBLOCKROW MCU_buffer[C_MAX_BLOCKS_IN_MCU];
kusano 7d535a
  JBLOCKROW buffer_ptr;
kusano 7d535a
  jpeg_component_info *compptr;
kusano 7d535a
kusano 7d535a
  /* Align the virtual buffers for the components used in this scan. */
kusano 7d535a
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
kusano 7d535a
    compptr = cinfo->cur_comp_info[ci];
kusano 7d535a
    buffer[ci] = (*cinfo->mem->access_virt_barray)
kusano 7d535a
      ((j_common_ptr) cinfo, coef->whole_image[compptr->component_index],
kusano 7d535a
       coef->iMCU_row_num * compptr->v_samp_factor,
kusano 7d535a
       (JDIMENSION) compptr->v_samp_factor, FALSE);
kusano 7d535a
  }
kusano 7d535a
kusano 7d535a
  /* Loop to process one whole iMCU row */
kusano 7d535a
  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
kusano 7d535a
       yoffset++) {
kusano 7d535a
    for (MCU_col_num = coef->mcu_ctr; MCU_col_num < cinfo->MCUs_per_row;
kusano 7d535a
	 MCU_col_num++) {
kusano 7d535a
      /* Construct list of pointers to DCT blocks belonging to this MCU */
kusano 7d535a
      blkn = 0;			/* index of current DCT block within MCU */
kusano 7d535a
      for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
kusano 7d535a
	compptr = cinfo->cur_comp_info[ci];
kusano 7d535a
	start_col = MCU_col_num * compptr->MCU_width;
kusano 7d535a
	blockcnt = (MCU_col_num < last_MCU_col) ? compptr->MCU_width
kusano 7d535a
						: compptr->last_col_width;
kusano 7d535a
	for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
kusano 7d535a
	  if (coef->iMCU_row_num < last_iMCU_row ||
kusano 7d535a
	      yindex+yoffset < compptr->last_row_height) {
kusano 7d535a
	    /* Fill in pointers to real blocks in this row */
kusano 7d535a
	    buffer_ptr = buffer[ci][yindex+yoffset] + start_col;
kusano 7d535a
	    for (xindex = 0; xindex < blockcnt; xindex++)
kusano 7d535a
	      MCU_buffer[blkn++] = buffer_ptr++;
kusano 7d535a
	  } else {
kusano 7d535a
	    /* At bottom of image, need a whole row of dummy blocks */
kusano 7d535a
	    xindex = 0;
kusano 7d535a
	  }
kusano 7d535a
	  /* Fill in any dummy blocks needed in this row.
kusano 7d535a
	   * Dummy blocks are filled in the same way as in jccoefct.c:
kusano 7d535a
	   * all zeroes in the AC entries, DC entries equal to previous
kusano 7d535a
	   * block's DC value.  The init routine has already zeroed the
kusano 7d535a
	   * AC entries, so we need only set the DC entries correctly.
kusano 7d535a
	   */
kusano 7d535a
	  for (; xindex < compptr->MCU_width; xindex++) {
kusano 7d535a
	    MCU_buffer[blkn] = coef->dummy_buffer[blkn];
kusano 7d535a
	    MCU_buffer[blkn][0][0] = MCU_buffer[blkn-1][0][0];
kusano 7d535a
	    blkn++;
kusano 7d535a
	  }
kusano 7d535a
	}
kusano 7d535a
      }
kusano 7d535a
      /* Try to write the MCU. */
kusano 7d535a
      if (! (*cinfo->entropy->encode_mcu) (cinfo, MCU_buffer)) {
kusano 7d535a
	/* Suspension forced; update state counters and exit */
kusano 7d535a
	coef->MCU_vert_offset = yoffset;
kusano 7d535a
	coef->mcu_ctr = MCU_col_num;
kusano 7d535a
	return FALSE;
kusano 7d535a
      }
kusano 7d535a
    }
kusano 7d535a
    /* Completed an MCU row, but perhaps not an iMCU row */
kusano 7d535a
    coef->mcu_ctr = 0;
kusano 7d535a
  }
kusano 7d535a
  /* Completed the iMCU row, advance counters for next one */
kusano 7d535a
  coef->iMCU_row_num++;
kusano 7d535a
  start_iMCU_row(cinfo);
kusano 7d535a
  return TRUE;
kusano 7d535a
}
kusano 7d535a
kusano 7d535a
kusano 7d535a
/*
kusano 7d535a
 * Initialize coefficient buffer controller.
kusano 7d535a
 *
kusano 7d535a
 * Each passed coefficient array must be the right size for that
kusano 7d535a
 * coefficient: width_in_blocks wide and height_in_blocks high,
kusano 7d535a
 * with unitheight at least v_samp_factor.
kusano 7d535a
 */
kusano 7d535a
kusano 7d535a
LOCAL(void)
kusano 7d535a
transencode_coef_controller (j_compress_ptr cinfo,
kusano 7d535a
			     jvirt_barray_ptr * coef_arrays)
kusano 7d535a
{
kusano 7d535a
  my_coef_ptr coef;
kusano 7d535a
  JBLOCKROW buffer;
kusano 7d535a
  int i;
kusano 7d535a
kusano 7d535a
  coef = (my_coef_ptr)
kusano 7d535a
    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
kusano 7d535a
				SIZEOF(my_coef_controller));
kusano 7d535a
  cinfo->coef = &coef->pub;
kusano 7d535a
  coef->pub.start_pass = start_pass_coef;
kusano 7d535a
  coef->pub.compress_data = compress_output;
kusano 7d535a
kusano 7d535a
  /* Save pointer to virtual arrays */
kusano 7d535a
  coef->whole_image = coef_arrays;
kusano 7d535a
kusano 7d535a
  /* Allocate and pre-zero space for dummy DCT blocks. */
kusano 7d535a
  buffer = (JBLOCKROW)
kusano 7d535a
    (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
kusano 7d535a
				C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
kusano 7d535a
  FMEMZERO((void FAR *) buffer, C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
kusano 7d535a
  for (i = 0; i < C_MAX_BLOCKS_IN_MCU; i++) {
kusano 7d535a
    coef->dummy_buffer[i] = buffer + i;
kusano 7d535a
  }
kusano 7d535a
}