Skip to content

Commit

Permalink
Stop using <stdint.h> (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
jwiggins authored Oct 4, 2017
1 parent 83edded commit 5de8f41
Show file tree
Hide file tree
Showing 13 changed files with 30 additions and 721 deletions.
1 change: 0 additions & 1 deletion celiagg/_celiagg.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import cython
from cython.operator cimport dereference
cimport numpy
import numpy
from libc.stdint cimport uint8_t, uint16_t, uint32_t, uint64_t

cimport _enums
cimport _font
Expand Down
1 change: 0 additions & 1 deletion celiagg/_graphics_state.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import cython
cimport numpy
import numpy
from libc.stdint cimport uint8_t
from libcpp cimport bool
from libcpp.vector cimport vector

Expand Down
5 changes: 1 addition & 4 deletions celiagg/_image.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,9 @@
#
# Authors: John Wiggins

from libc.stdint cimport uint8_t


cdef extern from "image.h":
cdef cppclass Image:
Image(uint8_t* buf, unsigned width, unsigned height, int stride)
Image(unsigned char* buf, unsigned width, unsigned height, int stride)

unsigned height()
unsigned width()
3 changes: 1 addition & 2 deletions celiagg/_ndarray_canvas.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import cython
cimport numpy
import numpy
from libc.stdint cimport uint8_t
from libcpp cimport bool

cimport _font
Expand Down Expand Up @@ -73,7 +72,7 @@ cdef extern from "ndarray_canvas.h":
const _graphics_state.GraphicsState& gs)

cdef cppclass ndarray_canvas[pixfmt_T]:
ndarray_canvas(uint8_t* buf,
ndarray_canvas(unsigned char* buf,
const unsigned width,
const unsigned height,
const int stride,
Expand Down
2 changes: 1 addition & 1 deletion celiagg/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

#include "image.h"

Image::Image(uint8_t* buf, unsigned width, unsigned height, int stride)
Image::Image(unsigned char* buf, unsigned width, unsigned height, int stride)
: m_buf(buf, width, height, stride)
{
}
Expand Down
4 changes: 1 addition & 3 deletions celiagg/image.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
#ifndef CELIAGG_IMAGE_H
#define CELIAGG_IMAGE_H

#include <stdint.h>

#include <agg_image_accessors.h>
#include <agg_path_storage.h>
#include <agg_pixfmt_gray.h>
Expand Down Expand Up @@ -244,7 +242,7 @@ class Image
agg::rendering_buffer m_buf;

public:
Image(uint8_t* buf, unsigned width, unsigned height, int stride);
Image(unsigned char* buf, unsigned width, unsigned height, int stride);

agg::rendering_buffer& get_buffer();
agg::path_storage image_outline() const;
Expand Down
22 changes: 12 additions & 10 deletions celiagg/image.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#
# Authors: John Wiggins

cimport numpy as np

ctypedef _image.Image* img_ptr_t

cdef _get_format_dtype(PixelFormat pixel_format):
Expand Down Expand Up @@ -57,33 +59,33 @@ cdef _get_format_last_dim(PixelFormat pixel_format):
return format_dims[pixel_format]


cdef img_ptr_t _get_2d_u8_img(uint8_t[:, ::1] arr, bool bottom_up):
return new _image.Image(<uint8_t*>&arr[0][0], arr.shape[1], arr.shape[0],
cdef img_ptr_t _get_2d_u8_img(np.npy_uint8[:, ::1] arr, bool bottom_up):
return new _image.Image(<unsigned char*>&arr[0][0], arr.shape[1], arr.shape[0],
-arr.strides[0] if bottom_up else arr.strides[0])


cdef img_ptr_t _get_2d_u16_img(uint16_t[:, ::1] arr, bool bottom_up):
return new _image.Image(<uint8_t*>&arr[0][0], arr.shape[1], arr.shape[0],
cdef img_ptr_t _get_2d_u16_img(np.npy_uint16[:, ::1] arr, bool bottom_up):
return new _image.Image(<unsigned char*>&arr[0][0], arr.shape[1], arr.shape[0],
-arr.strides[0] if bottom_up else arr.strides[0])


cdef img_ptr_t _get_2d_f32_img(float[:, ::1] arr, bool bottom_up):
return new _image.Image(<uint8_t*>&arr[0][0], arr.shape[1], arr.shape[0],
return new _image.Image(<unsigned char*>&arr[0][0], arr.shape[1], arr.shape[0],
-arr.strides[0] if bottom_up else arr.strides[0])


cdef img_ptr_t _get_3d_u8_img(uint8_t[:, :, ::1] arr, bool bottom_up):
return new _image.Image(<uint8_t*>&arr[0][0][0], arr.shape[1], arr.shape[0],
cdef img_ptr_t _get_3d_u8_img(np.npy_uint8[:, :, ::1] arr, bool bottom_up):
return new _image.Image(<unsigned char*>&arr[0][0][0], arr.shape[1], arr.shape[0],
-arr.strides[0] if bottom_up else arr.strides[0])


cdef img_ptr_t _get_3d_u16_img(uint16_t[:, :, ::1] arr, bool bottom_up):
return new _image.Image(<uint8_t*>&arr[0][0][0], arr.shape[1], arr.shape[0],
cdef img_ptr_t _get_3d_u16_img(np.npy_uint16[:, :, ::1] arr, bool bottom_up):
return new _image.Image(<unsigned char*>&arr[0][0][0], arr.shape[1], arr.shape[0],
-arr.strides[0] if bottom_up else arr.strides[0])


cdef img_ptr_t _get_3d_f32_img(float[:, :, ::1] arr, bool bottom_up):
return new _image.Image(<uint8_t*>&arr[0][0][0], arr.shape[1], arr.shape[0],
return new _image.Image(<unsigned char*>&arr[0][0][0], arr.shape[1], arr.shape[0],
-arr.strides[0] if bottom_up else arr.strides[0])


Expand Down
5 changes: 1 addition & 4 deletions celiagg/ndarray_canvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@
#define _USE_MATH_DEFINES
#include <cmath>

// for integer typedefs
#include <stdint.h>

#include <agg_alpha_mask_u8.h>
#include <agg_bezier_arc.h>
#include <agg_bspline.h>
Expand Down Expand Up @@ -91,7 +88,7 @@ template<typename pixfmt_t>
class ndarray_canvas : public ndarray_canvas_base
{
public:
ndarray_canvas(uint8_t* buf,
ndarray_canvas(unsigned char* buf,
const unsigned width, const unsigned height, const int stride,
const size_t channel_count, const bool bottom_up = false);
virtual ~ndarray_canvas(){}
Expand Down
2 changes: 1 addition & 1 deletion celiagg/ndarray_canvas.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@


template<typename pixfmt_t>
ndarray_canvas<pixfmt_t>::ndarray_canvas(uint8_t* buf,
ndarray_canvas<pixfmt_t>::ndarray_canvas(unsigned char* buf,
const unsigned width, const unsigned height, const int stride,
const size_t channel_count, const bool bottom_up)
: m_channel_count(channel_count)
Expand Down
22 changes: 12 additions & 10 deletions celiagg/ndarray_canvas.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

cimport numpy

ctypedef unsigned char _bytes_t

ctypedef _ndarray_canvas.ndarray_canvas_base canvas_base_t
ctypedef _ndarray_canvas.ndarray_canvas[_ndarray_canvas.pixfmt_rgba128] canvas_rgba128_t
ctypedef _ndarray_canvas.ndarray_canvas[_ndarray_canvas.pixfmt_bgra32] canvas_brga32_t
Expand All @@ -43,10 +45,10 @@ cdef class CanvasBase:
if image is None:
raise ValueError('image argument must not be None.')

cdef uint64_t[:] image_shape = numpy.asarray(image.shape,
dtype=numpy.uint64,
order='c')
cdef uint64_t image_ndim = <uint64_t> image.ndim
cdef numpy.npy_int32[:] image_shape = numpy.asarray(image.shape,
dtype=numpy.int32,
order='c')
cdef int image_ndim = <int> image.ndim

if not has_alpha:
# Draw colors for images without alpha channels are specified with
Expand Down Expand Up @@ -298,7 +300,7 @@ cdef class CanvasRGBA128(CanvasBase):
self.base_init(image, 4, True)
self.pixel_format = PixelFormat.RGBA128
self.bottom_up = bottom_up
self._this = <canvas_base_t*> new canvas_rgba128_t(<uint8_t*>&image[0][0][0],
self._this = <canvas_base_t*> new canvas_rgba128_t(<_bytes_t*>&image[0][0][0],
image.shape[1],
image.shape[0],
image.strides[0], 4,
Expand All @@ -315,7 +317,7 @@ cdef class CanvasBGRA32(CanvasBase):
:param array: A ``numpy.uint8`` array with shape (H, W, 4).
:param bottom_up: If True, the origin is the bottom left, instead of top-left
"""
def __cinit__(self, uint8_t[:,:,::1] image, bottom_up=False):
def __cinit__(self, _bytes_t[:,:,::1] image, bottom_up=False):
self.base_init(image, 4, True)
self.pixel_format = PixelFormat.BGRA32
self.bottom_up = bottom_up
Expand All @@ -336,7 +338,7 @@ cdef class CanvasRGBA32(CanvasBase):
:param array: A ``numpy.uint8`` array with shape (H, W, 4).
:param bottom_up: If True, the origin is the bottom left, instead of top-left
"""
def __cinit__(self, uint8_t[:,:,::1] image, bottom_up=False):
def __cinit__(self, _bytes_t[:,:,::1] image, bottom_up=False):
self.base_init(image, 4, True)
self.pixel_format = PixelFormat.RGBA32
self.bottom_up = bottom_up
Expand All @@ -357,7 +359,7 @@ cdef class CanvasRGB24(CanvasBase):
:param array: A ``numpy.uint8`` array with shape (H, W, 3).
:param bottom_up: If True, the origin is the bottom left, instead of top-left
"""
def __cinit__(self, uint8_t[:,:,::1] image, bottom_up=False):
def __cinit__(self, _bytes_t[:,:,::1] image, bottom_up=False):
self.base_init(image, 4, False)
self.pixel_format = PixelFormat.RGB24
self.bottom_up = bottom_up
Expand All @@ -378,7 +380,7 @@ cdef class CanvasGA16(CanvasBase):
:param array: A ``numpy.uint8`` array with shape (H, W, 2).
:param bottom_up: If True, the origin is the bottom left, instead of top-left
"""
def __cinit__(self, uint8_t[:,:,::1] image, bottom_up=False):
def __cinit__(self, _bytes_t[:,:,::1] image, bottom_up=False):
self.base_init(image, 2, True)
self.pixel_format = PixelFormat.Gray8
self.bottom_up = bottom_up
Expand All @@ -399,7 +401,7 @@ cdef class CanvasG8(CanvasBase):
:param array: A ``numpy.uint8`` array with shape (H, W).
:param bottom_up: If True, the origin is the bottom left, instead of top-left
"""
def __cinit__(self, uint8_t[:,::1] image, bottom_up=False):
def __cinit__(self, _bytes_t[:,::1] image, bottom_up=False):
self.base_init(image, 2, False)
self.pixel_format = PixelFormat.Gray8
self.bottom_up = bottom_up
Expand Down
2 changes: 0 additions & 2 deletions celiagg/paint.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
#ifndef CELIAGG_PAINT_H
#define CELIAGG_PAINT_H

#include <stdint.h>

#include <agg_array.h>
#include <agg_basics.h>
#include <agg_color_rgba.h>
Expand Down
3 changes: 0 additions & 3 deletions celiagg/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,6 @@ def configuration(parent_package='', top_path=None):
if platform.system() == "Windows":
# Visual studio does not support these
extra_compile_args = []
# Python 2.7 uses an old Visual Studio with no stdint.h
if sys.version_info[:2] == (2, 7):
include_dirs.append('celiagg/windows')
else:
extra_compile_args = [
'-Wfatal-errors',
Expand Down
Loading

0 comments on commit 5de8f41

Please sign in to comment.