File: pgraster_wkb_reader.hpp

package info (click to toggle)
mapnik 3.1.0%2Bds-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 20,208 kB
  • sloc: cpp: 144,467; python: 30,152; sh: 797; makefile: 166; xml: 140; lisp: 13
file content (85 lines) | stat: -rw-r--r-- 2,802 bytes parent folder | download | duplicates (2)
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
/*****************************************************************************
 *
 * This file is part of Mapnik (c++ mapping toolkit)
 *
 * Copyright (C) 2021 Artem Pavlenko
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 *****************************************************************************
 *
 * Initially developed by Sandro Santilli <strk@keybit.net> for CartoDB
 *
 *****************************************************************************/

#ifndef PGRASTER_WKB_READER_HPP
#define PGRASTER_WKB_READER_HPP

// mapnik
#include <mapnik/feature.hpp> // for raster_ptr
#include <mapnik/box2d.hpp>

enum pgraster_color_interp {
  // Automatic color interpretation:
  // uses grayscale for single band, rgb for 3 bands
  // rgba for 4 bands
  pgr_auto,
  // Grayscale interpretation
  pgr_grayscale,
  pgr_indexed,
  pgr_rgb,
  pgr_rgba
};

class pgraster_wkb_reader
{
public:

  pgraster_wkb_reader(const uint8_t* wkb, int size, int bnd=0)
    : ptr_(wkb), bandno_(bnd)
  {}

  mapnik::raster_ptr get_raster();

  /// @param bnd band number. If 0 (default) it'll try to read all bands
  ///            with automatic color interpretation (rgb for 3 bands,
  ///            rgba for 4 bands, grayscale for 1 band).
  ///            Any other value results in pixel
  ///            values being copied verbatim into the returned raster
  ///            for interpretation by the caller.
  static mapnik::raster_ptr read(const uint8_t* wkb, int size, int bnd=0)
  {
    pgraster_wkb_reader reader(wkb,size,bnd);
    return reader.get_raster();
  }

private:
  mapnik::raster_ptr read_indexed(mapnik::box2d<double> const& bbox, uint16_t width, uint16_t height);
  mapnik::raster_ptr read_grayscale(mapnik::box2d<double> const& bbox, uint16_t width, uint16_t height);
  mapnik::raster_ptr read_rgba(mapnik::box2d<double> const& bbox, uint16_t width, uint16_t height);

  //int wkbsize_;
  //const uint8_t* wkb_;
  //const uint8_t* wkbend_;
  const uint8_t* ptr_;
  uint8_t endian_;
  int bandno_;
  uint16_t numBands_;
  uint16_t width_;
  uint16_t height_;
};


#endif // PGRASTER_WKB_READER_HPP