File: i_compress.c

package info (click to toggle)
pxljr 1.4%2Brepack0-5
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster
  • size: 352 kB
  • sloc: ansic: 1,968; sh: 105; perl: 54; makefile: 36; python: 8
file content (87 lines) | stat: -rw-r--r-- 2,912 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/**
 * Copyright (c) 2005 Hin-Tak Leung. All rights reserved.
 *
**/
/*
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
*/
/**
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
**/

#include <stdio.h>
#include <stdlib.h>
#define JPEG_INTERNALS
#include "jpeglib.h"
#include "i_job_info.h"
#include "mode12.h"


int i_compress_row(i_job_info_t *job_info, 
			 char *ptr_row_current, 
			 char *ptr_row_prev, int wbytes)
{
  if (job_info->compressedbuffer == NULL)
    {
      job_info->compressedbuffer = (unsigned char *)calloc(1, job_info->pixel_h * 128 *4); /* worst case */
      job_info->buffersize =(int *)calloc(1, sizeof(int)); 
      if (job_info->qfactor)
	{
      jpeg_buffer_dest(job_info->cinfo, job_info->compressedbuffer, job_info->buffersize);
      job_info->cinfo->write_JFIF_header = FALSE;
      job_info->cinfo->write_Adobe_marker = FALSE;
      jpeg_start_compress(job_info->cinfo, FALSE);
      job_info->cinfo->master->call_pass_startup = FALSE;
      jpeg_suppress_tables(job_info->cinfo, TRUE);
	}
      else
	{
      *(job_info->buffersize) = 2; /* dirty trick for mode 12 */
	}

    }


  if(job_info->qfactor > 0)
    {
      JSAMPROW row_pointer[1];
      row_pointer[0]  = ptr_row_current;
      jpeg_write_scanlines(job_info->cinfo, row_pointer, 1);
    }
  else
    {
      unsigned char *buffer = job_info->compressedbuffer + *(job_info->buffersize);

      if (job_info->components == 1)
	{
	  *(job_info->buffersize) += mode12gray_compress(job_info->pixel_h, ptr_row_current,
							 ptr_row_prev, buffer, job_info->cached_color);
	}
      else
	{
	  *(job_info->buffersize) += mode12color_compress(job_info->pixel_h, ptr_row_current,
                                                          ptr_row_prev, buffer, job_info->cached_color);
	}
    }
  return 0;

}