summaryrefslogtreecommitdiff
path: root/src/cairo-png.c
AgeCommit message (Collapse)AuthorFilesLines
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.
2008-03-04[cairo-png] Use cairo_format_stride_for_width()Chris Wilson1-6/+10
Use cairo_format_stride_for_width() instead of assuming the pixel size and manually calculating the row stride. This should make it easier to support loading multiple image formats in future.
2008-03-04[cairo-png] Further hardening against malloc failures.Chris Wilson1-9/+29
On some OOM paths, libpng raises a warning as opposed to an error, these were not being propagated back to the caller. We were also not checking that we did not overwrite a pre-existing error status when raising an error whilst performing I/O.
2008-02-15[cairo-png] Improve error return for invalid parameters.Chris Wilson1-11/+13
Only translate an UNSUPPORTED error into a SURFACE_TYPE_MISMATCH, all others can be returned to the user unadulterated. PNG doesn't support width==0 or height==0 and generates an error whilst writing - which without further information is assumed to be a NO_MEMORY error. So check the image size at the start and return a WRITE_ERROR for a zero sized image.
2008-01-28[doc] Make sure all type names in docs are prefixed by #Behdad Esfahbod1-1/+1
2008-01-28[doc] Make sure all macro names in docs are prefixed by %Behdad Esfahbod1-5/+5
2008-01-16[cairo-surface] Introduce _cairo_surface_create_in_error().Chris Wilson1-16/+22
Unexport all the static error surfaces and use a function to select the appropriate error surface for the status.
2008-01-05Check errno for appropriate error return.Chris Wilson1-2/+8
After using fopen() and friends check the global errno to determine the most appropriate error return - especially important when running memfault, where correct reporting of NO_MEMORY errors is required.
2007-10-31[cairo-png] Check for feof whilst reading.Chris Wilson1-1/+1
We need to check for both ferror() and feof() when handling short reads.
2007-10-31[cairo-png] Handle missing PNG_SETJMP_SUPPORTEDChris Wilson1-4/+12
If libpng has not been compiled with jmpbuf support, then we cannot atempt to use it - in which case we fall back to png's default error handler and abort.
2007-10-11[cairo-png] Clean up volatile warning.Chris Wilson1-1/+1
gcc warns that 'rows' is missing a volatile qualifier - so add it.
2007-10-05[cairo-png] Markup a couple of original error sites with _cairo_error().Chris Wilson1-3/+3
Add the _cairo_error() markup to the original error sites within the png read/write functions.
2007-10-04[cairo-error] Clean up all the warnings and missing _cairo_error() calls.Chris Wilson1-12/+12
Every time we assign or return a hard-coded error status wrap that value with a call to _cairo_error(). So the idiom becomes: status = _cairo_error (CAIRO_STATUS_NO_MEMORY); or return _cairo_error (CAIRO_STATUS_INVALID_DASH); This ensures that a breakpoint placed on _cairo_error() will trigger immediately cairo detects the error.
2007-09-25[cairo-png] Propagate error from read and write funcs.Chris Wilson1-19/+38
Use the png_struct->error_ptr to propagate the error status from the user/stdio read and write functions through the png_error() to the cairo_surface_write_to_png*() and cairo_surface_read_from_png*() functions. From there the error is returned back to the user either directly or as the most appropriate error surface. (Fixes https://bugs.freedesktop.org/show_bug.cgi?id=6909)
2007-08-16[cairo-png] Protect against malloc(0).Chris Wilson1-9/+12
Avoid calling malloc(0) for an empty image.
2007-06-29[fix] Avoid int overflow when allocating large buffersVladimir Vukicevic1-3/+3
This patch introduces three macros: _cairo_malloc_ab, _cairo_malloc_abc, _cairo_malloc_ab_plus_c and replaces various calls to malloc(a*b), malloc(a*b*c), and malloc(a*b+c) with them. The macros return NULL if int overflow would occur during the allocation. See CODING_STYLE for more information.
2007-06-07Fix return value of cairo_surface_write_to_png for unsupported formatsCarl Worth1-1/+1
For some reason this was returning CAIRO_STATUS_NULL_POINTER. Now fixed to return CAIRO_STATUS_INVALID_FORMAT.
2007-04-23Merge branch 'master' of git+ssh://pmw@git.freedesktop.org/git/cairoPeter Weilbacher1-6/+26
2007-04-23Add a _cairo_error() to png_simple_error_callback()Chris Wilson1-0/+1
With the introduction of the error callbacks for PNG, we have the opportunity for the user to set a breakpoint (via _cairo_error) at the point the error is first rasied.
2007-04-23Do not print out libpng error messages to stderr.Chris Wilson1-6/+25
We wish to avoid writing to file descriptors (and streams) that are outside cairo's control. In this case, the messages are superfluous as the errors are propagated via the cairo_status_t returns.
2007-04-21Use deprecated png symbol only when compiling against old versionPeter Weilbacher1-0/+4
png_set_gray_1_2_4_to_8 is deprecated in libpng >= 1.2.9, the identical substitute for it is png_set_expand_gray_1_2_4_to_8
2007-04-20Clean up compiler warnings from cairo-pngChris Wilson1-2/+2
I introduced some compiler warnings into read_png() with the superfluous introduction of a couple of volatile qualifiers. I'm sure at the time, the reason was that gcc suggested adding them - however, ATM gcc issues no warnings without them.
2007-04-20cairo-png - handle short readsChris Wilson1-7/+17
During MT cairo testing we get the error "libpng: Read Error" which is emitted should the fread return fewer bytes than asked. However, this is not necessarily an error, so double-check the ferror() status before raising a png_error().
2007-04-03[src] Make sure all source files #include "cairoint.h" as their first includeBehdad Esfahbod1-1/+2
This is necessary to avoid many portability problems as cairoint.h includes config.h. Without a test, we will regress again, hence add it. The inclusion idiom for cairo now is: #include "cairoint.h" #include "cairo-something.h" #include "cairo-anotherthing-private.h" #include <some-library.h> #include <other-library/other-file.h> Moreover, some standard headers files are included from cairoint.h and need not be included again.