Skip to content
This repository has been archived by the owner on Jun 30, 2020. It is now read-only.

Commit

Permalink
massive docs refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
ojii committed Jul 6, 2012
1 parent 0308143 commit 780b02a
Show file tree
Hide file tree
Showing 15 changed files with 788 additions and 90 deletions.
741 changes: 741 additions & 0 deletions docs/dev/api.rst

Large diffs are not rendered by default.

27 changes: 0 additions & 27 deletions docs/dev/image.rst

This file was deleted.

3 changes: 1 addition & 2 deletions docs/dev/index.rst
Expand Up @@ -15,8 +15,7 @@ Contents
:maxdepth: 2

/dev/setup
/dev/overview
/dev/image
/dev/api
/dev/incubator
/dev/formats
/dev/contribute
4 changes: 2 additions & 2 deletions docs/dev/setup.rst
Expand Up @@ -4,5 +4,5 @@ Setup for development

Clone the git repository using ``git clone https://github.com/ojii/pymaging.git``.

To run the code, you need to be in a virtualenv that has ``distribute``
installed. For the tests you can use ``nose`` but it is not required.
To run the tests, simply execute ``setup.py test`` with a Python version of your choice, or run ``./runtests.sh`` to run
it against all installed (and supported) Python versions.
2 changes: 1 addition & 1 deletion pymaging/__init__.py
Expand Up @@ -25,4 +25,4 @@

from pymaging.image import Image

__version__ = '0.0.0'
__version__ = '0.1'
2 changes: 0 additions & 2 deletions pymaging/exceptions.py
Expand Up @@ -27,7 +27,5 @@

class PymagingException(Exception): pass

class ImageModeError(PymagingException): pass
class ImageSizeMismatch(PymagingException): pass
class FormatNotSupported(PymagingException): pass
class InvalidColor(PymagingException): pass
5 changes: 0 additions & 5 deletions pymaging/formats.py
Expand Up @@ -60,10 +60,6 @@ def register(self, format):
for extension in format.extensions:
self.names[extension] = format

def get_formats(self):
self._populate()
return self.registry

def get_format_objects(self):
self._populate()
return self.formats
Expand All @@ -73,7 +69,6 @@ def get_format(self, format):
return self.names.get(format, None)

registry = FormatRegistry()
get_formats = registry.get_formats
get_format_objects = registry.get_format_objects
get_format = registry.get_format
register = registry.register
19 changes: 0 additions & 19 deletions pymaging/helpers.py
Expand Up @@ -23,26 +23,7 @@
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

import array
from math import ceil
from collections import deque

class Fliprow(object):
def __init__(self, rowlength, pixelsize):
self.indices = deque()
indicesappend = self.indices.append
tmp = deque()
append = tmp.append
pop = tmp.pop
for i in range(rowlength - 1, -1, -1):
append(i)
if not i % pixelsize:
while tmp:
indicesappend(pop())

def flip(self, row):
return array.array('B', (row[i] for i in self.indices))


def get_transformed_dimensions(transform, box):
Expand Down
3 changes: 1 addition & 2 deletions pymaging/image.py
Expand Up @@ -27,9 +27,8 @@
from pymaging.affine import AffineTransform
from pymaging.exceptions import FormatNotSupported, InvalidColor
from pymaging.formats import get_format, get_format_objects
from pymaging.helpers import Fliprow, get_transformed_dimensions
from pymaging.helpers import get_transformed_dimensions
from pymaging.resample import nearest
import array
import os


Expand Down
6 changes: 0 additions & 6 deletions pymaging/pixelarray.py
Expand Up @@ -41,12 +41,6 @@ def get(self, x, y):
start = self._translate(x, y)
return [self.data[start+i] for i in range(self.pixelsize)]

def get_multiple(self, start_x, end_x, start_y, end_y):
"""
Returns a list of pixels (a list of lists of length `self.pixelsize`) in the rectangle start_x/start_y-end_x/end_y
"""
return [[self.get(x, y) for x in range(start_x, end_x)] for y in range(start_y, end_y)]

def set(self, x, y, pixel):
"""
Sets the pixel (a tuple of length `self.pixelsize`) to the pixel array at x/y
Expand Down
3 changes: 1 addition & 2 deletions pymaging/resample.py
Expand Up @@ -25,7 +25,7 @@
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
from pymaging.pixelarray import get_pixel_array

__all__ = ('nearest', 'bilinear')
__all__ = ('nearest', 'bilinear', 'Resampler')

from pymaging.affine import AffineTransform
from pymaging.helpers import get_transformed_dimensions
Expand All @@ -39,7 +39,6 @@ def __init__(self):
raise NotImplementedError(
"%r is abstract, instantiate a subclass instead" % Resampler
)
return super(Resampler, self).__init__()

def affine(self, source, transform, resize_canvas=True):
if resize_canvas:
Expand Down
7 changes: 6 additions & 1 deletion pymaging/shapes.py
Expand Up @@ -28,7 +28,12 @@
import math


class Pixel(object):
class BaseShape(object):
def iter_pixels(self, color):
raise StopIteration()


class Pixel(BaseShape):
def __init__(self, x, y):
self.x = x
self.y = y
Expand Down
23 changes: 23 additions & 0 deletions pymaging/test_utils.py
@@ -0,0 +1,23 @@
# -*- coding: utf-8 -*-
import unittest
import array
from pymaging.colors import ColorType
from pymaging.image import Image
from pymaging.pixelarray import get_pixel_array


def image_factory(colors, alpha=True):
height = len(colors)
width = len(colors[0]) if height else 0
pixel_size = 4 if alpha else 3
pixel_array = get_pixel_array(array.array('B', [0] * width * height * pixel_size), width, height, pixel_size)
for y in range(height):
for x in range(width):
pixel_array.set(x, y, colors[y][x].to_pixel(pixel_size))
return Image(pixel_array, ColorType(pixel_size, alpha))


class PymagingBaseTestCase(unittest.TestCase):
def assertImage(self, img, colors, alpha=True):
check = image_factory(colors, alpha)
self.assertEqual(img.pixels, check.pixels)
23 changes: 2 additions & 21 deletions pymaging/tests/test_basic.py
Expand Up @@ -23,14 +23,12 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
from __future__ import absolute_import
from pymaging.colors import Color, ColorType
from pymaging.colors import Color
from pymaging.exceptions import FormatNotSupported
from pymaging.image import Image
from pymaging.pixelarray import get_pixel_array
from pymaging.shapes import Line, Pixel
from pymaging.test_utils import PymagingBaseTestCase, image_factory
from pymaging.webcolors import Red, Green, Blue, Black, White, Lime
import array
import unittest
try: # pragma: no-cover
# 2.x
from StringIO import StringIO
Expand All @@ -39,23 +37,6 @@
from io import StringIO


def image_factory(colors, alpha=True):
height = len(colors)
width = len(colors[0]) if height else 0
pixelsize = 4 if alpha else 3
pixel_array = get_pixel_array(array.array('B', [0] * width * height * pixelsize), width, height, pixelsize)
for y in range(height):
for x in range(width):
pixel_array.set(x, y, colors[y][x].to_pixel(pixelsize))
return Image(pixel_array, ColorType(pixelsize, alpha))


class PymagingBaseTestCase(unittest.TestCase):
def assertImage(self, img, colors, alpha=True):
check = image_factory(colors, alpha)
self.assertEqual(img.pixels, check.pixels)


class BasicTests(PymagingBaseTestCase):
def _get_fake_image(self):
return image_factory([
Expand Down
10 changes: 10 additions & 0 deletions runtests.sh
Expand Up @@ -2,6 +2,7 @@

PYTHON_VERSIONS="2.6 2.7 3.1 3.2 3.3"
COMMAND="setup.py test"
STATUS=0

for version in $PYTHON_VERSIONS; do
pybin="python$version"
Expand All @@ -10,6 +11,7 @@ for version in $PYTHON_VERSIONS; do
echo "Running tests for Python $version"
echo "****************************"
$pybin $COMMAND
STATUS=$(($STATUS+$?))
else
echo "****************************"
echo "Python $version not found, skipping"
Expand All @@ -23,4 +25,12 @@ if [ `which pypy` ]; then
echo "Running tests for PyPy $pypyversion"
echo "**************************************************"
pypy $COMMAND
STATUS=$(($STATUS+$?))
fi
echo
if [ $STATUS -eq 0 ]; then
echo "All versions OK"
else
echo "One or more versions FAILED"
fi

0 comments on commit 780b02a

Please sign in to comment.