266 |
266 |
267 |
267 |
268 /** |
268 /** |
269 * Return a pointer to the pixel data on \a row, starting at \a col. |
269 * Return a pointer to the pixel data on \a row, starting at \a col. |
270 */ |
270 */ |
271 static inline void* tile_row_col (const struct pt_png_header *header, uint8_t *data, size_t row, size_t col) |
271 static inline const void* tile_row_col (const struct pt_png_header *header, const uint8_t *data, size_t row, size_t col) |
272 { |
272 { |
273 return data + (row * header->row_bytes) + (col * header->col_bytes); |
273 return data + (row * header->row_bytes) + (col * header->col_bytes); |
274 } |
274 } |
275 |
275 |
276 /** |
276 /** |
283 } |
283 } |
284 |
284 |
285 /** |
285 /** |
286 * Write raw tile image data, directly from the cache |
286 * Write raw tile image data, directly from the cache |
287 */ |
287 */ |
288 static int pt_png_encode_direct (struct pt_png_img *img, const struct pt_png_header *header, uint8_t *data, const struct pt_tile_info *ti) |
288 static int pt_png_encode_direct (struct pt_png_img *img, const struct pt_png_header *header, const uint8_t *data, const struct pt_tile_info *ti) |
289 { |
289 { |
290 for (size_t row = ti->y; row < ti->y + ti->height; row++) |
290 for (size_t row = ti->y; row < ti->y + ti->height; row++) |
291 // write data directly |
291 // write data directly |
292 png_write_row(img->png, tile_row_col(header, data, row, ti->x)); |
292 // missing const... |
|
293 png_write_row(img->png, (const png_bytep) tile_row_col(header, data, row, ti->x)); |
293 |
294 |
294 return 0; |
295 return 0; |
295 } |
296 } |
296 |
297 |
297 /** |
298 /** |
298 * Write clipped tile image data (a tile that goes over the edge of the actual image) by aligning the data from the cache as needed |
299 * Write clipped tile image data (a tile that goes over the edge of the actual image) by aligning the data from the cache as needed |
299 */ |
300 */ |
300 static int pt_png_encode_clipped (struct pt_png_img *img, const struct pt_png_header *header, uint8_t *data, const struct pt_tile_info *ti) |
301 static int pt_png_encode_clipped (struct pt_png_img *img, const struct pt_png_header *header, const uint8_t *data, const struct pt_tile_info *ti) |
301 { |
302 { |
302 png_byte *rowbuf; |
303 png_byte *rowbuf; |
303 size_t row; |
304 size_t row; |
304 |
305 |
305 // image data goes from (ti->x ... clip_x, ti->y ... clip_y), remaining region is filled |
306 // image data goes from (ti->x ... clip_x, ti->y ... clip_y), remaining region is filled |
356 return value; |
357 return value; |
357 } |
358 } |
358 |
359 |
359 #define ADD_AVG(l, r) (l) = ((l) + (r)) / 2 |
360 #define ADD_AVG(l, r) (l) = ((l) + (r)) / 2 |
360 |
361 |
361 static int png_pixel_data (png_color *out, const struct pt_png_header *header, uint8_t *data, size_t row, size_t col) |
362 static int png_pixel_data (png_color *out, const struct pt_png_header *header, const uint8_t *data, size_t row, size_t col) |
362 { |
363 { |
363 if (header->color_type == PNG_COLOR_TYPE_PALETTE) { |
364 if (header->color_type == PNG_COLOR_TYPE_PALETTE) { |
364 // palette entry number |
365 // palette entry number |
365 int p; |
366 int p; |
366 |
367 |
383 } |
384 } |
384 |
385 |
385 /** |
386 /** |
386 * Write unscaled tile data |
387 * Write unscaled tile data |
387 */ |
388 */ |
388 static int pt_png_encode_unzoomed (struct pt_png_img *img, const struct pt_png_header *header, uint8_t *data, const struct pt_tile_info *ti) |
389 static int pt_png_encode_unzoomed (struct pt_png_img *img, const struct pt_png_header *header, const uint8_t *data, const struct pt_tile_info *ti) |
389 { |
390 { |
390 int err; |
391 int err; |
391 |
392 |
392 // set basic info |
393 // set basic info |
393 png_set_IHDR(img->png, img->info, ti->width, ti->height, header->bit_depth, header->color_type, |
394 png_set_IHDR(img->png, img->info, ti->width, ti->height, header->bit_depth, header->color_type, |
418 } |
419 } |
419 |
420 |
420 /** |
421 /** |
421 * Write scaled tile data |
422 * Write scaled tile data |
422 */ |
423 */ |
423 static int pt_png_encode_zoomed (struct pt_png_img *img, const struct pt_png_header *header, uint8_t *data, const struct pt_tile_info *ti) |
424 static int pt_png_encode_zoomed (struct pt_png_img *img, const struct pt_png_header *header, const uint8_t *data, const struct pt_tile_info *ti) |
424 { |
425 { |
425 // size of the image data in px |
426 // size of the image data in px |
426 size_t data_width = scale_by_zoom_factor(ti->width, -ti->zoom); |
427 size_t data_width = scale_by_zoom_factor(ti->width, -ti->zoom); |
427 size_t data_height = scale_by_zoom_factor(ti->height, -ti->zoom); |
428 size_t data_height = scale_by_zoom_factor(ti->height, -ti->zoom); |
428 |
429 |