Changeset 5700 for trunk/Ohana/src/kii/picture/JPEGit24.c
- Timestamp:
- Dec 5, 2005, 3:55:45 PM (21 years ago)
- File:
-
- 1 edited
-
trunk/Ohana/src/kii/picture/JPEGit24.c (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/kii/picture/JPEGit24.c
r5637 r5700 1 1 # include "Ximage.h" 2 2 # include "jpeglib.h" 3 4 void JPEGit24 (Graphic *graphic, Layout *layout) { 3 # include <png.h> 4 # include "bDraw.h" 5 6 # define WHITE_R 255 7 # define WHITE_G 255 8 # define WHITE_B 255 9 10 int JPEGit24 (Graphic *graphic, Layout *layout) { 5 11 6 12 struct jpeg_compress_struct cinfo; … … 8 14 JSAMPROW row_pointer[1]; /* pointer to JSAMPLE row[s] */ 9 15 JSAMPLE *image_buffer; /* Points to data for current line */ 10 11 int i, j, ii, jj; 16 JSAMPLE *line_buffer; /* Points to data for current line */ 17 18 int ii, i, j; 12 19 int i_start, i_end, j_start, j_end; 13 20 int dropback, extra; /* this is a bit of a kludge... */ 14 21 int dx, dy, DX, DY; 22 int status, Nbytes, quality; 23 int expand_in, expand_out; 15 24 double expand, Rx, Ry, X, Y; 16 int expand_in, expand_out; 17 unsigned char *out_pix, *out_pix2, *data; 18 unsigned char *in_pix, *in_pix2; 25 unsigned char *out_pix, *in_pix, *in_pix_ref; 19 26 unsigned char pixel1[256], pixel2[256], pixel3[256]; 20 unsigned char pixvalue1, pixvalue2, pixvalue3; 21 unsigned long white; 22 unsigned char white1, white2, white3; 27 char filename[1024]; 23 28 FILE *f; 24 29 … … 36 41 f = fopen (filename, "w"); 37 42 if (f == (FILE *) NULL) { 38 fprintf (stderr, " failed to open %s for output\n", filename);43 fprintf (stderr, "Kii: failed to open %s for output\n", filename); 39 44 return (TRUE); 40 45 } … … 55 60 jpeg_start_compress (&cinfo, TRUE); 56 61 57 /* output line buffer */58 ALLOCATE (image_buffer, JSAMPLE, 3*layout[0].picture.dx);59 60 62 /** cmap[i].pixel must be defined even if X is not used **/ 61 63 for (i = 0; i < 256; i++) { /* set up pixel array */ 62 pixel1[i] = 0x0000ff & (layout[0].cmap[i].pixel >> 0); 63 pixel2[i] = 0x0000ff & (layout[0].cmap[i].pixel >> 8); 64 pixel3[i] = 0x0000ff & (layout[0].cmap[i].pixel >> 16); 65 } 66 white = layout[0].white; 67 white1 = 0x0000ff & (white >> 0); 68 white2 = 0x0000ff & (white >> 8); 69 white3 = 0x0000ff & (white >> 16); 64 pixel1[i] = layout[0].cmap[i].red >> 8; 65 pixel2[i] = layout[0].cmap[i].green >> 8; 66 pixel3[i] = layout[0].cmap[i].blue >> 8; 67 } 70 68 71 69 expand = expand_in = expand_out = 1.0; … … 85 83 dx = layout[0].picture.dx; 86 84 dy = layout[0].picture.dy; 87 DX = layout[0].matrix[0].Naxis[0]; 88 DY = layout[0].matrix[0].Naxis[1]; 89 extra = 4 - (dx * 3) % 4; /* why is this needed?? */ 85 DX = layout[0].matrix.Naxis[0]; 86 DY = layout[0].matrix.Naxis[1]; 90 87 91 88 /* X,Y are the image coordinates of the first image pixel */ … … 119 116 if ((i_end - i_start) % expand_out == 0) dropback = 0; 120 117 121 out_pix = image_buffer; 122 in_pix = (unsigned char *) (layout[0].matrix[0].buffer) + DX*(int)MAX(Y,0) + (int)MAX(X,0); 118 /* output line buffer */ 119 ALLOCATE (image_buffer, JSAMPLE, 3*dx*dy); 120 ALLOCATE (line_buffer, JSAMPLE, 3*dx); 121 122 in_pix_ref = (unsigned char *) (layout[0].matrix.buffer) + DX*(int)MAX(Y,0) + (int)MAX(X,0); 123 123 124 124 /********** below we do the mapping from buffer pixels (in) to picture pixels (out) **********/ 125 125 126 /* we write the jpeg image data one row at a time */127 128 126 /**** fill in bottom area ****/ 129 out_pix = image_buffer;127 out_pix = line_buffer; 130 128 for (i = 0; i < dx; i++, out_pix+=3) { 131 129 out_pix[0] = WHITE_R; … … 134 132 } 135 133 for (j = 0; j < j_start; j++) { 136 row_pointer[0] = image_buffer; 137 (void) jpeg_write_scanlines (&cinfo, row_pointer, 1); 134 memcpy (&image_buffer[j*3*dx], line_buffer, 3*dx); 138 135 } 139 136 140 137 /*** fill in the image data region ***/ 141 for (j = j_start; j < j_end; j+= expand_out, in_pix += expand_in*DX) {138 for (j = j_start; j < j_end; j+= expand_out, in_pix_ref += expand_in*DX) { 142 139 143 140 /* create one output image line */ 144 out_pix = image_buffer; 141 in_pix = in_pix_ref; 142 out_pix = line_buffer; 145 143 146 144 /**** fill in area to the left of the picture ****/ … … 152 150 153 151 /*** fill in the picture region ***/ 154 for (i = i_start; i < i_end; i++, in_pix+=expand_in, out_pix+=3) { 155 out_pix[0] = pixel1[*in_pix]; 156 out_pix[1] = pixel2[*in_pix]; 157 out_pix[2] = pixel3[*in_pix]; 152 for (i = i_start; i < i_end; i+=expand_out, in_pix+=expand_in) { 153 for (ii = 0; ii < expand_out; ii++, out_pix+=3) { 154 out_pix[0] = pixel1[*in_pix]; 155 out_pix[1] = pixel2[*in_pix]; 156 out_pix[2] = pixel3[*in_pix]; 157 } 158 158 } 159 159 … … 167 167 /* write out the image line expand_out times */ 168 168 for (i = 0; i < expand_out; i++) { 169 row_pointer[0] = image_buffer; 170 (void) jpeg_write_scanlines (&cinfo, row_pointer, 1); 169 memcpy (&image_buffer[(j + i)*3*dx], line_buffer, 3*dx); 171 170 } 172 171 } 173 172 174 173 /**** fill in top area ****/ 175 out_pix = image_buffer;174 out_pix = line_buffer; 176 175 for (i = 0; i < dx; i++, out_pix+=3) { 177 176 out_pix[0] = WHITE_R; … … 179 178 out_pix[2] = WHITE_B; 180 179 } 181 for (j = 0; j < (dy - j_end); j++) { 182 row_pointer[0] = image_buffer; 180 for (j = j_end; j < dy; j++) { 181 memcpy (&image_buffer[j*3*dx], line_buffer, 3*dx); 182 } 183 184 185 /* I need to write the overlay objects on the jpeg image. 186 if i can write / overwrite data in jpeg buffer, then do it here, 187 otherwise i need to create a temporary image buffer, then write the 188 scanlines to that buffer */ 189 190 { 191 int Npalette; 192 png_color *palette; 193 bDrawColor white, color; 194 bDrawBuffer *buffer; 195 196 palette = MakePNGPalette (&Npalette); 197 198 buffer = bDrawBufferCreate (dx, dy); 199 bDrawSetBuffer (buffer); 200 for (i = 0; i < NOVERLAYS; i++) { 201 if (OVERLAY[i]) bDrawOverlay (layout, i); 202 } 203 204 white = GetColorByName ("white"); 205 for (j = 0; j < dy; j++) { 206 for (i = 0; i < dx; i++) { 207 color = buffer[0].pixels[j][i]; 208 if (color == white) continue; 209 image_buffer[j*3*dx + 3*i + 0] = palette[color].red; 210 image_buffer[j*3*dx + 3*i + 1] = palette[color].green; 211 image_buffer[j*3*dx + 3*i + 2] = palette[color].blue; 212 } 213 } 214 bDrawBufferFree (buffer); 215 } 216 217 for (i = 0; i < dy; i++) { 218 row_pointer[0] = &image_buffer[i*3*dx]; 183 219 (void) jpeg_write_scanlines (&cinfo, row_pointer, 1); 184 220 } … … 190 226 return (TRUE); 191 227 } 192
Note:
See TracChangeset
for help on using the changeset viewer.
