Changeset 3081 for libpipi/trunk
- Timestamp:
- Oct 24, 2008, 1:49:31 PM (12 years ago)
- Location:
- libpipi/trunk/pipi
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
libpipi/trunk/pipi/codec.c
r3075 r3081 39 39 ret = pipi_load_oric(name); 40 40 41 #if USE_ LIBJPEG41 #if USE_MODULAR 42 42 if(!ret) 43 43 ret = pipi_load_modular(name); … … 91 91 ret = pipi_save_oric(img, name); 92 92 93 #if USE_MODULAR 94 if(ret < 0) 95 ret = pipi_save_modular(img, name); 96 #endif 93 97 #if USE_IMLIB2 94 98 if(ret < 0) -
libpipi/trunk/pipi/codec/modular/jpeg.c
r3075 r3081 120 120 int pipi_save_jpeg(pipi_image_t *img, const char *name) 121 121 { 122 int quality = 75; /* FIXME */ 123 124 struct jpeg_compress_struct cinfo; 125 struct jpeg_error_mgr jerr; 126 unsigned char *data = NULL; 127 unsigned char *line = NULL; 128 129 pipi_pixels_t *pixels = pipi_getpixels(img, PIPI_PIXELS_RGBA_C); 130 131 if (!pixels) 132 return 0; 133 134 data = pixels->pixels; 135 136 137 line = malloc(img->w * 3 * sizeof(unsigned char)); 138 if (!line) 139 return 0; 140 141 FILE *fp = fopen(name, "wb"); 142 if (!fp) { 143 free(line); 144 return 0; 145 } 146 147 jerr.error_exit = error_msg; 148 jerr.emit_message = emit_msg; 149 jerr.output_message = output_msg; 150 151 cinfo.err = jpeg_std_error(&(jerr)); 152 153 jpeg_create_compress(&cinfo); 154 jpeg_stdio_dest(&cinfo, fp); 155 cinfo.image_width = img->w; 156 cinfo.image_height = img->h; 157 cinfo.input_components = 3; 158 cinfo.in_color_space = JCS_RGB; 159 160 jpeg_set_defaults(&cinfo); 161 jpeg_set_quality(&cinfo, quality, TRUE); 162 jpeg_start_compress(&cinfo, TRUE); 163 164 int j, i, y = 0; 165 uint32_t *ptr = (uint32_t*)data; 166 JSAMPROW *jbuf; 167 168 while (cinfo.next_scanline < cinfo.image_height) 169 { 170 for (j = 0, i = 0; i < img->w; i++) 171 { 172 line[j++] = ((*ptr) >> 16) & 0xff; 173 line[j++] = ((*ptr) >> 8) & 0xff; 174 line[j++] = ((*ptr)) & 0xff; 175 ptr++; 176 } 177 /* write scanline */ 178 jbuf = (JSAMPROW *) (&line); 179 jpeg_write_scanlines(&cinfo, jbuf, 1); 180 y++; 181 } 182 183 jpeg_finish_compress(&cinfo); 184 jpeg_destroy_compress(&cinfo); 185 free(line); 186 fclose(fp); 187 188 return 1; 189 } 190 191 static int pipi_free_jpeg(pipi_image_t *img) 192 { 193 if(img->p[PIPI_PIXELS_RGBA_C].pixels) 194 free(img->p[PIPI_PIXELS_RGBA_C].pixels); 122 195 return 0; 123 196 } 124 197 125 static int pipi_free_jpeg(pipi_image_t *img) 126 { 127 return 0; 128 } 129 130 131 132 198 199 200
Note: See TracChangeset
for help on using the changeset viewer.