Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. /*
  2.  * Copyright 2011 John-Mark Bell <jmb@netsurf-browser.org>
  3.  *
  4.  * This file is part of NetSurf, http://www.netsurf-browser.org/
  5.  *
  6.  * NetSurf is free software; you can redistribute it and/or modify
  7.  * it under the terms of the GNU General Public License as published by
  8.  * the Free Software Foundation; version 2 of the License.
  9.  *
  10.  * NetSurf is distributed in the hope that it will be useful,
  11.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.  * GNU General Public License for more details.
  14.  *
  15.  * You should have received a copy of the GNU General Public License
  16.  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  17.  */
  18.  
  19. #include <assert.h>
  20. #include <stdint.h>
  21. #include <stdbool.h>
  22. #include <string.h>
  23.  
  24. #include "utils/errors.h"
  25. #include "utils/config.h"
  26. #include "utils/log.h"
  27. #include "desktop/plotters.h"
  28. #include "image/bitmap.h"
  29.  
  30. #include "image/bmp.h"
  31. #include "image/gif.h"
  32. #include "image/ico.h"
  33. #include "image/jpeg.h"
  34. #include "image/mng.h"
  35. #include "image/nssprite.h"
  36. #include "image/png.h"
  37. #include "image/rsvg.h"
  38. #include "image/svg.h"
  39. #include "image/webp.h"
  40.  
  41. #include "image/image.h"
  42.  
  43. /**
  44.  * Initialise image content handlers
  45.  *
  46.  * \return NSERROR_OK on success, appropriate error otherwise.
  47.  */
  48. nserror image_init(void)
  49. {
  50.         nserror error;
  51.  
  52. #ifdef WITH_BMP
  53.         error = nsbmp_init();
  54.         if (error != NSERROR_OK)
  55.                 return error;
  56. #endif
  57.  
  58. #ifdef WITH_GIF
  59.         error = nsgif_init();
  60.         if (error != NSERROR_OK)
  61.                 return error;
  62. #endif
  63.  
  64. #ifdef WITH_BMP
  65.         error = nsico_init();
  66.         if (error != NSERROR_OK)
  67.                 return error;
  68. #endif
  69.  
  70. #ifdef WITH_JPEG
  71.         error = nsjpeg_init();
  72.         if (error != NSERROR_OK)
  73.                 return error;
  74. #endif
  75.  
  76. #ifdef WITH_MNG
  77.         error = nsmng_init();
  78.         if (error != NSERROR_OK)
  79.                 return error;
  80.  
  81.         error = nsjpng_init();
  82.         if (error != NSERROR_OK)
  83.                 return error;
  84. #endif
  85.  
  86. #ifdef WITH_PNG
  87.         /* Prefer libpng over libmng for pngs by registering later */
  88.         error = nspng_init();
  89.         if (error != NSERROR_OK)
  90.                 return error;
  91. #endif
  92.  
  93. #ifdef WITH_NSSPRITE
  94.         error = nssprite_init();
  95.         if (error != NSERROR_OK)
  96.                 return error;
  97. #endif
  98.  
  99.         /* Prefer rsvg over libsvgtiny for svgs */
  100. #ifdef WITH_NS_SVG
  101.         error = svg_init();
  102.         if (error != NSERROR_OK)
  103.                 return error;
  104. #endif
  105. #ifdef WITH_RSVG
  106.         error = nsrsvg_init();
  107.         if (error != NSERROR_OK)
  108.                 return error;
  109. #endif
  110.  
  111. #ifdef WITH_WEBP
  112.         error = webp_init();
  113.         if (error != NSERROR_OK)
  114.                 return error;
  115. #endif /* WITH_WEBP */
  116.  
  117.         return NSERROR_OK;
  118. }
  119.  
  120.  
  121. bool image_bitmap_plot(struct bitmap *bitmap,
  122.                        struct content_redraw_data *data,
  123.                        const struct rect *clip,
  124.                        const struct redraw_context *ctx)
  125. {
  126.         bitmap_flags_t flags = BITMAPF_NONE;
  127.  
  128.         int width;
  129.         int height;
  130.         unsigned char *pixel;
  131.         plot_style_t fill_style;
  132.         struct rect area;
  133.  
  134.         width = bitmap_get_width(bitmap);
  135.         if (width == 1) {
  136.                 height = bitmap_get_height(bitmap);
  137.                 if (height == 1) {
  138.                         /* optimise 1x1 bitmap plot */
  139.                         pixel = bitmap_get_buffer(bitmap);
  140.                         fill_style.fill_colour = pixel_to_colour(pixel);
  141.  
  142.                         if (bitmap_get_opaque(bitmap) ||
  143.                             ((fill_style.fill_colour & 0xff000000) == 0xff000000)) {
  144.  
  145.                                 area = *clip;
  146.  
  147.                                 if (data->repeat_x != true) {
  148.                                         area.x0 = data->x;
  149.                                         area.x1 = data->x + data->width;
  150.                                 }
  151.  
  152.                                 if (data->repeat_y != true) {
  153.                                         area.y0 = data->y;
  154.                                         area.y1 = data->y + data->height;
  155.                                 }
  156.  
  157.                                 fill_style.stroke_type = PLOT_OP_TYPE_NONE;
  158.                                 fill_style.fill_type = PLOT_OP_TYPE_SOLID;
  159.  
  160.                                 return ctx->plot->rectangle(area.x0, area.y0,
  161.                                                             area.x1, area.y1,  
  162.                                                             &fill_style);
  163.  
  164.                         } else if ((fill_style.fill_colour & 0xff000000) == 0) {
  165.                                 /* transparent pixel used as spacer, skip it */
  166.                                 return true;
  167.                         }
  168.                 }
  169.         }
  170.  
  171.         /* do the plot */
  172.         if (data->repeat_x)
  173.                 flags |= BITMAPF_REPEAT_X;
  174.         if (data->repeat_y)
  175.                 flags |= BITMAPF_REPEAT_Y;
  176.  
  177.         return ctx->plot->bitmap(data->x, data->y, data->width, data->height,
  178.                                  bitmap, data->background_colour, flags);
  179.        
  180.  
  181. }
  182.