summaryrefslogtreecommitdiff
path: root/src/cairo-png.c
AgeCommit message (Collapse)AuthorFilesLines
2018-01-13fix warning: variable X might be clobbered by 'longjmp'Uli Schlachter1-3/+3
According to "man setjmp", one possible way to avoid variable clobbering is to declare them as volatile. Thus, this commit turns the variables that are changed between setjmp() and longjmp() and whose values are still needed after setjmp() returned the second time into volatile variables. The warning in cairo-bentley-ottmann-rectangular.c is worked around by not initializing the variable before setjmp(). To be honest, I don't understand why the compiler warns here at all since the value of update is clearly not used after setjmp()'s second return. This commit re-fixes the warnings that were reintroduced in commit 82f40285 which reverted b092b63. Signed-off-by: Uli Schlachter <psychon@znc.in> Acked-by: Bryce Harrington <bryce@osg.samsung.com>
2017-12-23Revert "fix warning: variable X might be clobbered by 'longjmp'"Uli Schlachter1-11/+6
This reverts commit b092b63119cbfe3cb4bc786eee81630998996acf which introduced a wrapper function around setjmp(). To quote from man setjmp: If the function which called setjmp() returns before longjmp() is called, the behavior is undefined. Some kind of subtle or unsubtle chaos is sure to result. Since after the above commit setjmp() is called from the wrapper function, the result might or might not work, depending on compiler settings. If the setjmp() wrapper is not inlined, then the state of the stack after longjmp() will likely be garbage.
2017-11-26Use UTF-8 filenames on WindowsTom Schoonjans1-5/+15
Until now fopen was used on Windows to open files for reading and writing. This assumed however that the filename would be encoded in the current codepage, which is a major inconvenience and makes it even impossible to use filenames that use characters from more than one codepage. This patch enforces the use of UTF-8 filenames on all platforms. Based on the work of Owen Taylor (https://lists.cairographics.org/archives/cairo/2007-February/009591.html)
2017-11-07image: prevent invalid ptr access for > 4GB imagesAdrian Johnson1-1/+1
Image data is often accessed using: image->data + y * image->stride On 64-bit achitectures if the image data is > 4GB, this computation will overflow since both y and stride are 32-bit types. Fixes: https://bugs.freedesktop.org/show_bug.cgi?id=98165 Reviewed-by: Bryce Harrington <bryce@osg.samsung.com>
2017-10-21fix warning: variable X might be clobbered by 'longjmp'Adrian Johnson1-6/+11
Move calls to setjmp into separate function to avoid clobbering local variables.
2016-03-26Add CAIRO_STATUS_PNG_ERROR for errors returned by libpngAdrian Johnson1-3/+7
2013-04-16png: Avoid marking the surface as in error after a png warningChris Wilson1-7/+7
It turns out that libpng will continue to load an image after throwing a warning, and that libpng16 now throws warnings for images that libpng15 and earlier loaded without error. As we were happily loading those images into cairo surfaces before, we are therefore being overzealous in throwing an error now - so just squelch the warning. Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
2012-03-29doc: Add "since" tag to documentationAndrea Canciani1-0/+10
The following Python script was used to compute "Since: 1.X" tags, based on the first version where a symbol became officially supported. This script requires a concatenation of the the cairo public headers for the officially supported beckends to be available as "../../includes/1.X.0.h". from sys import argv import re syms = {} def stripcomments(text): def replacer(match): s = match.group(0) if s.startswith('/'): return "" else: return s pattern = re.compile( r'//.*?$|/\*.*?\*/|\'(?:\\.|[^\\\'])*\'|"(?:\\.|[^\\"])*"', re.DOTALL | re.MULTILINE ) return re.sub(pattern, replacer, text) for minor in range(12,-2,-2): version = "1.%d" % minor names = re.split('([A-Za-z0-9_]+)', stripcomments(open("../../includes/%s.0.h" % version).read())) for s in names: syms[s] = version for filename in argv[1:]: is_public = False lines = open(filename, "r").read().split("\n") newlines = [] for i in range(len(lines)): if lines[i] == "/**": last_sym = lines[i+1][2:].strip().replace(":", "") is_public = last_sym.lower().startswith("cairo") elif is_public and lines[i] == " **/": if last_sym in syms: v = syms[last_sym] if re.search("Since", newlines[-1]): newlines = newlines[:-1] if newlines[-1].strip() != "*": newlines.append(" *") newlines.append(" * Since: %s" % v) else: print "%s (%d): Cannot determine the version in which '%s' was introduced" % (filename, i, last_sym) newlines.append(lines[i]) out = open(filename, "w") out.write("\n".join(newlines)) out.close()
2012-03-29doc: Make documentation comments symmetricAndrea Canciani1-2/+2
Documentation comments should always start with "/**" and end with "**/". This is not required by gtk-doc, but it makes the documentations formatting more consistent and simplifies the checking of documentation comments. The following Python script tries to enforce this. from sys import argv from sre import search for filename in argv[1:]: in_doc = False lines = open(filename, "r").read().split("\n") for i in range(len(lines)): ls = lines[i].strip() if ls == "/**": in_doc = True elif in_doc and ls == "*/": lines[i] = " **/" if ls.endswith("*/"): in_doc = False out = open(filename, "w") out.write("\n".join(lines)) out.close() This fixes most 'documentation comment not closed with **/' warnings by check-doc-syntax.awk.
2011-08-13image: move surface definition to new header for subclassingChris Wilson1-0/+1
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
2011-07-31Remove useless checks for NULL before freeingAndrea Canciani1-4/+2
This patch has been generated by the following Coccinelle semantic patch: // Remove useless checks for NULL before freeing // // free (NULL) is a no-op, so there is no need to avoid it @@ expression E; @@ + free (E); + E = NULL; - if (unlikely (E != NULL)) { - free(E); ( - E = NULL; | - E = 0; ) ... - } @@ expression E; @@ + free (E); - if (unlikely (E != NULL)) { - free (E); - }
2011-07-19clip: Rudimentary support for clip-polygon extractionChris Wilson1-1/+1
Step 1, fix the failings sighted recently by tracking clip-boxes as an explicit property of the clipping and of composition. Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
2011-07-13png: Fix support of depth-30 imagesChris Wilson1-8/+8
Rename the variable depth to bpc to prevent future confusion. Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
2011-05-01Expose 30bpp/10bpc support: CAIRO_FORMAT_RGB30Jesse Barnes1-0/+4
This is a common format used by framebuffers to drive 10bpc displays and is often hardware accelerated by XRender with underlying support from pixman's x2r10g10b10 format (which provides coercion paths for fallbacks). Signed-off-by: Jesse Barnes <jbarnes@virtuousgeek.org> Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
2011-01-10doc: Add a remark about toy status of the PNG APIMaarten Bosmans1-0/+8
The PNG API is just a toy API whose main purpose is to make it easy to write minimal examples of cairo features or testcases for bugs. For these purposes there is no need to tune the output PNG file or to provide additional information in optional PNG chuncks, but real applications need to do that quite often. The documentation now points out what is the correct procedure to write image data to a file.
2010-07-10Convert mime data length to use unsigned longChris Wilson1-1/+1
What we want to use is size_t, but we don't want the implied POSIX dependency. However, POSIX does say that size_t is an unsigned integer that is no longer than a long, so it would appear safe to use an unsigned long as a replacement. Safer at least than unsigned int.
2010-07-08doc: Move tmpl/ docs to inline docsBenjamin Otte1-0/+18
I did this manually so I could review the docs at the same time. If anyone finds typos or other mistakes I did, please complain to me (or better: fix them).
2010-04-27Update FSF addressAndrea Canciani1-1/+1
I updated the Free Software Foundation address using the following script. for i in $(git grep Temple | cut -d: -f1 ) do sed -e 's/59 Temple Place[, -]* Suite 330, Boston, MA *02111-1307[, ]* USA/51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA/' -i "$i" done Fixes http://bugs.freedesktop.org/show_bug.cgi?id=21356
2010-03-30Silence enumeration warnings following addition of RGB16_565Chris Wilson1-0/+1
2010-03-01api: Introduce CAIRO_FORMAT_INVALID formally in the API.M Joonas Pihlaja1-0/+1
We were exposing the actual value of CAIRO_FORMAT_INVALID through API functions already, so it makes sense to just go ahead and put it in the cairo_format_t enum.
2010-02-23image: split cairo_image_surface_coerce()Benjamin Otte1-2/+1
Split into a general cairo_image_surface_coerce() that coerces to one of the 3 supported formats (ARGB32, RGB24, A8) based on content and the more general cairo_image_surface_coerce_to_format() that coerces to a specified format.
2010-01-25[png] Simplify coercion codeBenjamin Otte1-10/+6
Call _cairo_image_surface_coerce() unconditionally to ensure coercion to one of the standard formats happens even when it's a format we support.
2010-01-22Move _cairo_error() to a standalone headerChris Wilson1-0/+2
A pending commit will want to include some utility code from cairo and so we need to extricate the error handling from the PLT symbol hiding.
2009-05-15[debug] Check image contents using memcheck.Chris Wilson1-0/+2
As an aide to tracking down the source of uninitialised reads, run VALGRIND_CHECK_MEM_IS_DEFINED() over the contents of image surfaces at the boundary between backends, e.g. upon setting a glyph image or acquiring a source image.
2009-05-05[png] Coerce FORMAT_INVALID to a known image formatChris Wilson1-14/+30
It is possible for cairo_surface_write_to_png() to acquire a non-standard image surface when, for example, we try to dump a low bit-depth XServer. Handle this scenario by coercing the unknown image format to a standard type via pixman.
2009-02-12Merge branch '1.8'Chris Wilson1-2/+15
2009-02-12[png] Correct documentation to avoid reference to NULLChris Wilson1-2/+15
As pointed out by Truc Truong, cairo_image_surface_create_from_png_stream() cannot return NULL and so the documentation was incorrect. Fixes http://bugs.freedesktop.org/show_bug.cgi?id=20075 Bug 20075 There is a misprint in the spec for cairo_image_surface_create_from_png_stream() function
2009-01-30Revert "[png] Complete the idempotent read_png() -> write_png()"Chris Wilson1-14/+0
This reverts commit 564d64a1323c5cbcde2dd9365ac790fe8aa1c5a6. In hindsight, and with further discussion with Jeff Muizelaar, this behaviour of using the stored contents from the mime-data is completely the opposite of the users' expectations. When the user calls cairo_surface_write_to_png(), usually in the course of debugging their rendering code, they expect the precise contents of the surface to be saved.
2009-01-29[png] Avoid a double free of the memory stream after error.Chris Wilson1-1/+1
_cairo_memory_stream_destroy() finalizes the stream even if the stream was in error and that error is reported back to the caller - so ensure we don't try to free the stream again.
2008-11-29[png] Fix leak of original png data on error path.Chris Wilson1-4/+11
The error path was missing a _cairo_output_stream_destroy() to cleanup a copy of the incoming PNG data.
2008-11-29Mark allocation failures as unlikely.Chris Wilson1-7/+7
Use the gcc likelihood annotation to indicate that allocation failures are extremely unlikely.
2008-11-29Mark if(status) as being unlikely.Chris Wilson1-7/+7
The error paths should be hit very rarely during normal operation, so mark them as being unlikely so gcc may emit better code.
2008-11-26[png] Use FILE* instead of void*.Chris Wilson1-2/+4
Adrian Johnson reported that cygwin complained about the use of the void * within feof() as it was using a macro and attempted a to deference the void*...
2008-11-07[surface] Pass a separate closure for the mime-type destroy notifier.Chris Wilson1-1/+2
A limitation of the current API was that the destroy notifier was called on the mime-data block. This prevents the user from passing in a pointer to a managed block, for example a mime-data block belonging to a ref-counted object. We can overcome this by allowing the user to specify the closure to be used with the destroy notifier.
2008-11-05[png] Complete the idempotent read_png() -> write_png()Chris Wilson1-0/+14
Write out the original PNG mime-data if attached to the surface during cairo_surface_write_to_png(). Similar to how the compressed alternate representations are handled by the other backends. Note: by automatically attaching and using the mime-data in preference to the image data, we break the read_from_png(); draw(); write_to_png() cycle.
2008-11-05[png] Attach the png representation to cairo_surface_create_from_png().Chris Wilson1-49/+78
Attach the original png data as an alternate representation for image surfaces created by cairo_surface_create_from_png().
2008-11-04[png] Use RGB for opaque images.Chris Wilson1-4/+7
If the ARGB32 is opaque, discard the alpha channel - so we should generate byte identical output to the reference images.
2008-09-24Eliminate paranoid check for PNG_INTERLACE_NONE.Carl Worth1-1/+1
Commit 20b1b33c0fc7 added some "paranoid checks" to our png loading code. One of these was checking that if png_get_IHDR first reports an interlace value other than PNG_INTERLACE_NONE that after we call png_set_interlace_handling then we do get PNG_INTERLACE_NONE from the next call to png_get_IHDR. However, libpng doesn't seem to actually have that behavior. When testing cairo_image_surface_create_from_png with an interlanced PNG file, (which the test suite happens not to do---even now), the call to png_set_interlace_handling is doing the trick, but the check for PNG_INTERLACE_NONE is failing. So, with the check in place, loading an interlaced PNG image fails with CAIRO_STATUS_READ_ERROR. By simply removing that check, an interlaced image loads just fine.
2008-08-20[test] Cache last output and compare next time.Chris Wilson1-3/+6
Compare the current output against a previous run to determine if there has been any change since last time, and only run through imagediff if there has been. For the vector surfaces, we can check the vector output first and potentially skip the rasterisation. On my machine this reduces the time for a second run from 6 minutes to 2m30s. As most of the time, most test output will remain unchanged, so this seems to be a big win. On unix systems, hard linking is used to reduce the amount of storage space required - others will see about a three-fold increase in the amount of disk used. The directory continues to be a stress test for file selectors. In order to reduce the changes between runs, the current time is no longer written to the PNG files (justified by that it only exists as a debugging aid) and the boilerplate tweaks the PS surface so that the creation date is fixed. To fully realise the benefits here, we need to strip the creation time from all the reference images... The biggest problem with using the caches is that different runs of the test suite can go through different code paths, introducing potential Heisenbergs. If you suspect that caching is interfering with the test results, use 'make -C test clean-caches check'.
2008-08-19[png] Specify a no-op flush callback (NULL deref)Alex Rostovtsev1-1/+8
libpng changed behaviour in v1.2.30 to call the png_ptr->output_flush_fn in png_write_end(). If no flush function is provided with png_set_write_fn(), libpng will use its default fflush() instead - which assumes that closure passed is a FILE* and not an arbitrary user pointer. Consequently, we must actually set a dummy output_flush_fn to avoid segfaulting.
2008-06-04Bit swap when writing FORMAT_A1 to PNG on little endianAdrian Johnson1-0/+3
2008-06-01Fix newly detected doc syntax issuesBehdad Esfahbod1-5/+5
2008-04-21[cairo-png] Call png_set_filler() before png_read_update_info().Chris Wilson1-1/+2
Otherwise libpng gets very confused and we start scribbling over invalid memory whilst reading in the PNG.
2008-04-21[cairo-png] Recheck png_info after setting transformation options.Chris Wilson1-18/+20
After specifying how to transform the various colour modes into ones we can handle, re-read the image header to confirm that the output on reading the PNG will be RGB24 or ARGB32. This simplifies our logic considerably as we no longer have to second guess the colour space transformation that will be performed by libpng. (And allows for some paranoid checks.)
2008-04-21[cairo-png] Create an ARGB32 surface for paletted PNGs.Chris Wilson1-5/+14
jeremie54 reported a regression in the handling of transparent paletted PNGs beween 1.4.14 and 1.6.4. This was caused by the change to load opaque PNGs into a RGB24 image surface, which made the assumption that indexed PNGs were opaque. However, alpha/transparency in PNG is more complicated, as PNG uses a tRNS chunk to supply transparency data for paletted images and other image types that don't need a full alpha channel. Therefore if the PNG contains a tRNS chunk always generate an ARGB32 surface.
2008-04-08Check surface->status and finished in cairo_surface_write_to_png_streamChris Wilson1-0/+6
Cut'n'paste from commit c1f765: Without these checks, a user could hit an assertion failure by passing a finished surface to cairo_surface_write_to_png_stream. Now we return a nice CAIRO_STATUS_SURFACE_FINISHED error in that case instead.
2008-04-08Check surface->status and finished in cairo_surface_write_to_pngCarl Worth1-0/+6
Without these checks, a user could hit an assertion failure by passing a finished surface to cairo_surface_write_to_png. Now we return a nice CAIRO_STATUS_SURFACE_FINISHED error in that case instead.
2008-03-21[cairo-png] Set bKGD gray value.Chris Wilson1-3/+2
For PNG_COLOR_TYPE_GRAY images the bKGD value is read from white.gray which was uninitialized, triggering the "PNG warning = Ignoring attempt to write bKGD chunk out-of-range for bit_depth" reported by Emmanuel Pacaud. This patch sets the background gray value to white, the same as for RGB images.
2008-03-06[cairo-png] Revert accidental chunk from FORMAT_A1 support.Chris Wilson1-1/+3
Whilst splitting the patches, I left in this line which would preserve 1-bit grayscale unexpanded, but without any of the other FORMAT_A1 support.
2008-03-04[cairo-png] Support generating CAIRO_FORMAT_RGB24 from PNGs.Chris Wilson1-17/+52
If the PNG does not have an alpha channel, then create an opaque image.