summaryrefslogtreecommitdiff
path: root/draw
AgeCommit message (Collapse)Author
2012-03-13Fix potential memory overrun.Robin Watts
Taken from Sumatra.patch - Many thanks.
2012-03-13Add ctx argument and rename fz_bound_pixmap to fz_pixmap_bbox.Tor Andersson
2012-03-13Rename some functions and accessors to be more consistent.Tor Andersson
Debug printing functions: debug -> print. Accessors: get noun attribute -> noun attribute. Find -> lookup when the returned value is not reference counted. pixmap_with_rect -> pixmap_with_bbox. We are reserving the word "find" to mean lookups that give ownership of objects to the caller. Lookup is used in other places where the ownership is not transferred, or simple values are returned. The rename is done by the sed script in scripts/rename3.sed
2012-03-13Fix Bug 692915: fz_copy_aa_context was broken.Robin Watts
Code was copying the wrong structure. Thanks to Pedro Rivera for pointing this out.
2012-03-12Merge branch 'header-split'Robin Watts
2012-03-12Store AA level used to render a glyph in the glyphcache.Robin Watts
In the existing code, glyphs are stored/retrieved from the glyphcache with no reference to the antialias level used to create them. This means that if we are using different aa levels in different threads, we can retrieve 'non-matching' glyphs and hence get rendering indeterminisms. Fixed simply here by storing the aa level in the glyphcache too.
2012-03-12Change order of params in fz_convert_color to C standard.Robin Watts
C's standard is copy(dst, src), so we move to adopt that here. Hopefully no one is calling this routine other than us - if they are, then I apologise! Better to aim for consistency before we freeze the API at v1.0 than to carry an inconsistent API around ever after.
2012-03-12Change order of params in fz_convert_pixmap to C standard.Robin Watts
C's standard is copy(dst, src), so we move to adopt that here. Hopefully no one is calling this routine other than us - if they are, then I apologise! Better to aim for consistency before we freeze the API at v1.0 than to carry an inconsistent API around ever after.
2012-03-12Merge branch 'master' into header-splitRobin Watts
2012-03-12Remove unnecessary assignments.Sebastian Rasmussen
2012-03-12More API tidying.Robin Watts
Make fz_clone_context copy existing AA settings. Add accessor function for fz_bitmap. Add more documentation for various functions/types.
2012-03-09Fix overeager cleanup code.Robin Watts
In the cancel or error case, we cleanup pixmaps left on the draw devices stack. We were cleaning up one layer more in the error code than in normal code, leading to a double free.
2012-03-06Split fitz.h/mupdf.h into internal/external headers.Robin Watts
Attempt to separate public API from internal functions.
2012-02-25Rework image handling for on demand decodeRobin Watts
Introduce a new 'fz_image' type; this type contains rudimentary information about images (such as native, size, colorspace etc) and a function to call to get a pixmap of that image (with a size hint). Instead of passing pixmaps through the device interface (and holding pixmaps in the display list) we now pass images instead. The rendering routines therefore call fz_image_to_pixmap to get pixmaps to render, and fz_pixmap_drop those afterwards. The file format handling routines therefore need to produce images rather than pixmaps; xps and cbz currently just wrap pixmaps as images. PDF is more involved. The stream handling routines in PDF have been altered so that they can recognise when the last stream entry in a filter dictionary is an image decoding filter. Rather than applying this filter, they read and store the parameters into a pdf_image_params structure, and stop decoding at that point. This allows us to read the compressed data for an image into memory as a block. We can then restart the image decode process later. pdf_images therefore consist of the compressed image data for images. When a pixmap is requested for such an image, the code checks to see if we have one (of an appropriate size), and if not, decodes it. The size hint is used to determine whether it is possible to subsample the image; currently this is only supported for JPEGs, but we could add generic subsampling code later. In order to handle caching the produced images, various changes have been made to the store and the underlying hash table. Previously the store was indexed purely by fz_obj keys; we don't have an fz_obj key any more, so have extended the store by adding a concept of a key 'type'. A key type is a pointer to a set of functions that keep/drop/compare and make a hashable key from a key pointer. We make a pdf_store.c file that contains functions to offer the existing fz_obj based functions, and add a new 'type' for keys (based on the fz_image handle, and the subsample factor) in the pdf_image.c file. While working on this, a problem became apparent in the existing store codel; fz_obj objects had no protection on their reference counts, hence an interpreter thread could try to alter a ref count at the same time as a malloc caused an eviction from the store. This has been solved by using the alloc lock as protection. This in turn requires some tweaks to the code to make sure we don't try and keep/drop fz_obj's from the store code while the alloc lock is held. A side effect of this work is that when a hash table is created, we inform it what lock should be used to protect its innards (if any). If the alloc lock is used, the insert method knows to drop/retake it to allow it to safely expand the hash table. Callers to the hash functions have the responsibility of taking/dropping the appropriate lock, and ensuring that they cope with the possibility that insert might drop the alloc lock, causing race conditions.
2012-02-13Add locking around freetype calls.Robin Watts
We only open one instance of freetype per document. We therefore have to ensure that only 1 call to it takes place at a time. We introduce a lock for this purpose (FZ_LOCK_FREETYPE), and arrange to take/release it as required. We also update the font context so it is properly shared.
2012-02-11Purge unused and bit rotted fz_accelerate stuff.Tor Andersson
2012-02-08Lock reworking.Robin Watts
This is a significant change to the use of locks in MuPDF. Previously, the user had the option of passing us lock/unlock functions for a single mutex as part of the allocation struct. Now we remove these entries from the allocation struct, and make a separate 'locks' struct. This enables people to use fz_alloc_default with locking. If multithreaded operation is required, then the user is required to create FZ_LOCK_MAX mutexes, which will be locked or unlocked by MuPDF calling the lock/unlock functions within the new fz_locks_context structure passed in at context creation. These mutexes are not required to be recursive (they may be, but MuPDF should never call them in this way). MuPDF avoids deadlocks by imposing a locking ordering on itself; a thread will never take lock n, if it already holds any lock i for which 0 <= i <= n. Currently, there are 4 locks used within MuPDF. Lock 0: The alloc lock; taken around all calls to user supplied (or default) allocation functions. Also taken around all accesses to the refs field of storable items. Lock 1: The store lock; taken whenever the store data structures (specifically the linked list pointers) are accessed. Lock 2: The file lock; taken whenever a thread is accessing the raw file. We use the debugging macros to insist that this is held whenever we do a file based seek or read. We also insist that this is never held when we resolve an indirect reference, as this can have the effect of moving the file pointer. Lock 3: The glyphcache lock; taken whenever a thread calls freetype, or accesses the glyphcache data structures. This introduces some complexities w.r.t type3 fonts. Locking can be hugely problematic, so to ease our minds as to the correctness of this code, we introduce some debugging macros. These compile away to nothing unless FITZ_DEBUG_LOCKING is defined. fz_assert_lock_held(ctx, lock) checks that we hold lock. fz_assert_lock_not_held(ctx, lock) checks that we do not hold lock. In addition fz_lock_debug_lock and fz_lock_debug_unlock are used on every fz_lock/fz_unlock to check the validity of the operation we are performing - in particular it checks that we do/do not already hold the lock we are trying to take/drop, and that by taking this lock we are not violating our defined locking order. The RESOLVE macro (used throughout the code to check whether we need to resolve an indirect reference) calls fz_assert_lock_not_held to ensure that we aren't about to resolve an indirect reference (and hence move the stream pointer) when the file is locked. In order to implement the file locking properly, pdf_open_stream (and friends) now lock the file as a side effect (because they fz_seek to the start of the stream). The lock is automatically dropped on an fz_close of such streams. Previously, the glyph cache was created in a context when it was first required; this presents problems as it can be shared between several contexts or not, depending on whether it is created before the contexts are cloned. We now always create it at startup, so it is always shared. This means that we need reference counting for the glyph caches. Added here. In fz_render_glyph, we take the glyph cache lock, and check to see whether the glyph is in the cache. If it is, we bump the refcount, drop the lock and returned the cached character. If it is not, we need to render the character. For freetype based fonts we keep the lock throughout the rendering process, thus ensuring that freetype is only called in a single threaded manner. For type3 fonts, however, we need to invoke the interpreter again to render the glyph streams. This can require reentrance to this routine. We therefore drop the glyph cache lock, call the interpreter to render us our pixmap, and take the lock again. This dropping and retaking of the lock introduces a possible race condition; 2 threads may try to render the same character at the same time. We therefore modify our hash table insert routines to behave differently if it comes to insert an entry only to find that an entry with the same key is already there. We spot this case; if we have just rendered a type3 glyph and when we try to insert it into the cache discover that someone has beaten us to it, we just discard our entry and use the cached one. Hopefully this will seldom be a problem in practise; to solve it properly would require greater complexity (probably involving spotting that another thread is already working on the desired rendering, and sleeping on a semaphore until it completes).
2012-02-07Rename a few functions.Tor Andersson
2012-02-03Be consistent about passing a fz_context in path/text/shade functions.Tor Andersson
2012-02-03Be consistent about passing a fz_context argument in pixmap functions.Tor Andersson
2012-02-03Pass context explicitly to hash table functions.Tor Andersson
2012-02-03Remove extraneous blank lines.Tor Andersson
2012-02-03Make fz_malloc_struct return zeroed memory.Tor Andersson
2012-01-26Fix possible SEGV/assert in downscaler.Robin Watts
On extreme downscales, the weights for each pixel can all round to zero; this results in no weights being stored at all, and causes either an exception or a SEGV. The simple fix is to ensure that the first pixel that's actually in range (and there will always be one) always has a weight of at least 1. Thanks to malc for finding the test cases that lead to this bugfix.
2012-01-24Correct SEGV/assert in cluster tests.Robin Watts
fz_draw_fill_image_mask was improperly nesting group start/ends, by calling fz_knockout_start at the top, and then fz_knockout_start again at the end. Changing this latter one to fz_knockout_end solves the problem. Also tweak the debugging code slightly to give more readable results.
2012-01-24Solve (some) SEGVS in cluster tests.Robin Watts
The cluster testing of MuPDF repeatedly crashes on pdf/PDF_1.7_FTS/fts_20_2008.pdf. Investigation shows this is because we fail to write the newly allocated mask back to the graphics state stack when starting a clip_stroke_text drawing operation. This causes later pops to fall over. Simple fix.
2012-01-23Do XPS mitering properly.Robin Watts
Modified version of Sumatras patch. Thanks for this.
2012-01-23Update ARM optimised scaling code in line with recent changes.Robin Watts
The ARM optimised code relied on the size of the weights structure which was changed by the addition of a new member as part of the patch scaling changes. Fix the code here, and add a note to the structure in the hopes that this will avoid such breakages happening in future.
2012-01-23Remove assert in tiling code.Robin Watts
Both Zeniko and Malc have said that this causes problems. Following a hint from malc, the following command causes the assert to trigger: win32/Debug/pdfdraw.exe -r0.3 -o out.png ../MyTests/pdf_reference17.pdf 1143 I suspect it's because of the extreme resolution, and the round_rect call. At any rate, disabling the assert is of no real import.
2012-01-21Update image scaling subpixel offset calculations for top-down images.Tor Andersson
2012-01-21Clean up some stray mixed tabs and spaces.Tor Andersson
2012-01-20Bitmap 'patch' scaling - second attempt.Robin Watts
When scaling a bitmap, currently we always scale the entire bitmap, even if we only need a small section of the result. This patch changes the code to take an optional 'clip' bbox, and only scales as many pixels as are required to generate the required output region.
2012-01-20Flip images the right side up in the PDF interpreter.Tor Andersson
This way both pixmaps for rendering and image data are top-down.
2012-01-20Revert "Bitmap 'patch' scaling."Tor Andersson
This reverts commit 08e84b18e5c1dbe8f3d32dd0aeb4b4c43debce9f.
2012-01-19Bitmap 'patch' scaling.Robin Watts
When scaling a bitmap, currently we always scale the entire bitmap, even if we only need a small section of the result. This patch changes the code to take an optional 'clip' bbox, and only scales as much of the input as as required for this output region.
2012-01-19Multi-threading support for MuPDFRobin Watts
When we moved over to a context based system, we laid the foundation for a thread-safe mupdf. This commit should complete that process. Firstly, fz_clone_context is properly implemented so that it makes a new context, but shares certain sections (currently just the allocator, and the store). Secondly, we add locking (to parts of the code that have previously just had placeholder LOCK/UNLOCK comments). Functions to lock and unlock a mutex are added to the allocator structure; omit these (as is the case today) and no multithreading is (safely) possible. The context will refuse to clone if these are not provided. Finally we flesh out the LOCK/UNLOCK comments to be real calls of the functions - unfortunately this requires us to plumb fz_context into the fz_keep_storable function (and all the fz_keep_xxx functions that call it). This is the largest section of the patch. No changes expected to any test files.
2012-01-12Support proper XPS mitering. (And stroke fixes).Robin Watts
XPS differs from PS/PDF/etc in the way it handles miters; rather than simply converting a miter that's overly long to a bevel, it truncates it at the miter limit. As such it needs to be handled correctly. For clarity, expose new enumerated types for linejoins and linecaps, and use these throughout code. When we upgrade our freetype, we can move to using proper xps mitering in that too. Add new fz_matrix_max_expansion function to return a safer expansion value that works in the case where we scale up in one direction and down in another. In the xps path drawing code, avoid generating unnecessary linetos. Thanks to Zeniko for spotting these and providing implementations.
2012-01-11Hide glyph cache in context.Tor Andersson
2012-01-11Stylistic comment and whitespace fixes.Tor Andersson
2012-01-11Calculate accurate per-glyph bounding boxes for fz_bound_text.Tor Andersson
2012-01-10Add fz_blend_pixel_function.Robin Watts
Inspired by Sumatras gdi devices need for such a function expose the blending functions. Note that we produce unsigned char's where Zenikos original produces ints, but it's otherwise identical. This requires us to make various knockon changes throughout the code from int to unsigned char, none of which should make any difference at all - I hope! We reserve the right to change/amend this function in future to operate on blocks of pixels (or pixels in different colorspaces) (or anything else we think of) in future.
2012-01-10Fix many spelling errors.Sebastian Rasmussen
2012-01-09Fix Bug 692356 (comment #2)Robin Watts
Take on a modified version of Zenikos patch; only take the quick exit if the whole dash length is small, or if the dash_length scaled up by the maximum possible scale in the ctm is less than 1/2 a pixel.
2012-01-06Various fixes to avoid arithmetic problems.Robin Watts
Various fixes to avoid overflow problems, division by zeros, use of uninitialised variables etc. All from/suggested by Zenikos patch.
2012-01-06Clamp pixel values after applying Decode array to images.Robin Watts
Thanks to Zeniko for pointing this out.
2012-01-06draw_device; device state stack handling fixes.Robin Watts
Only create a shape if we need to. Correctly cleanup, thus avoiding a double free of mask later on. Thanks to Zeniko for spotting these.
2012-01-03Rework draw device stack handling.Robin Watts
As we create clips/transparency groups etc, we maintain a stack of draw device states. Here we change this from having a 'current' state, and storing changes on the stack to always keeping the complete current state on the head of the stack. This should make error cleanup easier, as well as being conceptually easier to follow (for me at least).
2012-01-02Fix bug 692593 - solve crash due to inappropriately sized shape plane.Robin Watts
When starting to tile, create a shape plane if one exists. When finishing tiling, plot the shape plane back too. This solves the SEGVs. Something isn't quite right with the blending colours on part of this file though.
2011-12-30Enable knockout and non-isolated group support.Robin Watts
Testsseem to indicate that this works, and gives noticable improvements. Enabling by default.
2011-12-30Fix typo in draw/draw_affine.c causing offsetting of shape planeRobin Watts
The shape plane was being incorrectly offset from the dest plane. This could have caused SEGVs or incorrect results when blending back. This solves the hivemind.pdf iphone being clipped on the right hand side.