Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #96631 > unrolled thread
| Started by | ruben safir <ruben@mrbrklyn.com> |
|---|---|
| First post | 2016-11-15 14:40 -0500 |
| Last post | 2016-11-16 22:24 +0000 |
| Articles | 20 on this page of 32 — 16 participants |
Back to article view | Back to comp.lang.c
PNG coding ruben safir <ruben@mrbrklyn.com> - 2016-11-15 14:40 -0500
Re: PNG coding "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2016-11-15 12:02 -0800
Re: PNG coding ruben safir <ruben@mrbrklyn.com> - 2016-11-15 15:20 -0500
Re: PNG coding "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2016-11-15 12:25 -0800
Re: PNG coding "James R. Kuyper" <jameskuyper@verizon.net> - 2016-11-15 15:34 -0500
Re: PNG coding Popping mad <rainbow@colition.gov> - 2016-11-15 20:57 +0000
Re: PNG coding "James R. Kuyper" <jameskuyper@verizon.net> - 2016-11-15 16:12 -0500
Re: PNG coding jadill33@gmail.com - 2016-11-15 14:00 -0800
Re: PNG coding Jorgen Grahn <grahn+nntp@snipabacken.se> - 2016-11-20 11:14 +0000
Re: PNG coding Richard Heathfield <rjh@cpax.org.uk> - 2016-11-15 21:45 +0000
Re: PNG coding "James R. Kuyper" <jameskuyper@verizon.net> - 2016-11-15 17:15 -0500
Re: PNG coding Richard Heathfield <rjh@cpax.org.uk> - 2016-11-15 22:41 +0000
Re: PNG coding Melzzzzz <mel@zzzzz.com> - 2016-11-15 23:49 +0100
Re: PNG coding Anton Shepelev <anton.txt@g{oogle}mail.com> - 2016-11-16 15:23 +0300
Re: PNG coding Richard Heathfield <rjh@cpax.org.uk> - 2016-11-16 13:57 +0000
Re: PNG coding BGB <cr88192@hotmail.com> - 2016-11-18 01:24 -0600
Re: PNG coding BartC <bc@freeuk.com> - 2016-11-18 11:56 +0000
Re: PNG coding BGB <cr88192@hotmail.com> - 2016-11-18 12:48 -0600
Re: PNG coding BartC <bc@freeuk.com> - 2016-11-19 00:21 +0000
Re: PNG coding BGB <cr88192@hotmail.com> - 2016-11-19 01:50 -0600
Re: PNG coding Melzzzzz <mel@zzzzz.com> - 2016-11-15 23:42 +0100
Re: PNG coding BGB <cr88192@hotmail.com> - 2016-11-15 17:53 -0600
Re: PNG coding "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2016-11-15 16:25 -0800
Re: PNG coding raltbos@xs4all.nl (Richard Bos) - 2016-11-18 08:15 +0000
Re: PNG coding jameskuyper@verizon.net - 2016-11-18 09:35 -0800
Re: PNG coding supercat@casperkitty.com - 2016-11-20 14:34 -0800
Re: PNG coding BartC <bc@freeuk.com> - 2016-11-16 19:38 +0000
Re: PNG coding Richard Heathfield <rjh@cpax.org.uk> - 2016-11-16 22:16 +0000
Re: PNG coding "Mr. Man-wai Chang" <toylet.toylet@gmail.com> - 2016-11-16 21:14 +0800
Re: PNG coding Jean-marc Lienher <jean-marc.lienher@bluewin.ch> - 2016-11-16 20:55 +0100
Re: PNG coding BartC <bc@freeuk.com> - 2016-11-16 20:31 +0000
Re: PNG coding Richard Heathfield <rjh@cpax.org.uk> - 2016-11-16 22:24 +0000
Page 1 of 2 [1] 2 Next page →
| From | ruben safir <ruben@mrbrklyn.com> |
|---|---|
| Date | 2016-11-15 14:40 -0500 |
| Subject | PNG coding |
| Message-ID | <o0foak$4cu$1@reader2.panix.com> |
Does anyone know of any sample code for reading PNG files that doesn't include using libpng.... just straight direct access.
[toc] | [next] | [standalone]
| From | "Rick C. Hodgin" <rick.c.hodgin@gmail.com> |
|---|---|
| Date | 2016-11-15 12:02 -0800 |
| Message-ID | <c2a742d9-5291-4446-9671-fde3e84f8c06@googlegroups.com> |
| In reply to | #96631 |
On Tuesday, November 15, 2016 at 2:40:15 PM UTC-5, ruben safir wrote:
> Does anyone know of any sample code for reading PNG files that doesn't
> include using libpng.... just straight direct access.
I've never come across one in C.
On Windows and with a C++ compiler, you can use the built-in
Gdiplus::Bitmap object and load the png and then write it out
as a standard .bmp format, which is much easier to access
line-by-line.
See:
Bitmap class:
https://msdn.microsoft.com/en-us/library/windows/desktop/ms534420(v=vs.85).aspx
Basically, load the image, convert it to a HBITMAP which you then
BitBlt onto another HBITMAP you've created using CreateDIBSection().
In that one you obtain a pointer to the bits and can write them out
in any format you desire:
https://msdn.microsoft.com/en-us/library/windows/desktop/ms536295(v=vs.85).aspx
Some steps in this operation:
Make sure structures are packed to 1-byte (and not the default 8-
or 16-bytes).
Use GdiplusStartup() to engage the Gdiplus engine.
Use the image->GetWidth() and image->GetHeight() to determine size.
Use image->LockBits() to obtain a BitmapData object.
Use image->GetHorizontalResolution() * 39.700787f to get pixels
per meter for the output bmp setting. And GetVerticalResolution().
Use image->unlockBits() when finished.
Use GdiplusShutdown() to disengage the Gdiplus engine.
Best regards,
Rick C. Hodgin
[toc] | [prev] | [next] | [standalone]
| From | ruben safir <ruben@mrbrklyn.com> |
|---|---|
| Date | 2016-11-15 15:20 -0500 |
| Message-ID | <o0fqm5$8n7$1@reader2.panix.com> |
| In reply to | #96632 |
On 11/15/2016 03:02 PM, Rick C. Hodgin wrote: > On Windows and with a C++ compiler, you can use the built-in > Gdiplus::Bitmap object and load the png and then write it out > as a standard .bmp format, which is much easier to access > line-by-line I can't use MS, and I'm not looking for a solution, just source code to learn by, read and adapt. FWIW, Rick, I wouldn't touch a slaveware MS OS if it was the last platform on earth. I suggest strongly for you to try something else.
[toc] | [prev] | [next] | [standalone]
| From | "Rick C. Hodgin" <rick.c.hodgin@gmail.com> |
|---|---|
| Date | 2016-11-15 12:25 -0800 |
| Message-ID | <0926c75e-8ccf-4e74-9887-82396932235d@googlegroups.com> |
| In reply to | #96635 |
On Tuesday, November 15, 2016 at 3:20:29 PM UTC-5, ruben safir wrote:
> On 11/15/2016 03:02 PM, Rick C. Hodgin wrote:
> > On Windows and with a C++ compiler, you can use the built-in
> > Gdiplus::Bitmap object and load the png and then write it out
> > as a standard .bmp format, which is much easier to access
> > line-by-line
>
> I can't use MS, and I'm not looking for a solution, just source code to
> learn by, read and adapt.
>
> FWIW, Rick, I wouldn't touch a slaveware MS OS if it was the last
> platform on earth. I suggest strongly for you to try something else.
Couldn't agree more, though I also extend the definition to include
Mac OS and Linux among others:
http://www.libsf.org/wiki/index.php/Main_Page
https://github.com/RickCHodgin/libsf/tree/master/exodus
I named it Exodus in the 1990s, about six years before I became a
Christian. It was given that name because I wanted it to be "a mass
departure from evil" which was Microsoft.
Today I am pursuing Exodus an OS/2 compatible kernel with some more
modern extensions, called ES/2.
Best regards,
Rick C. Hodgin
[toc] | [prev] | [next] | [standalone]
| From | "James R. Kuyper" <jameskuyper@verizon.net> |
|---|---|
| Date | 2016-11-15 15:34 -0500 |
| Message-ID | <efb414a2-37fd-f415-1353-d92dad04592b@verizon.net> |
| In reply to | #96631 |
On 11/15/2016 02:40 PM, ruben safir wrote: > Does anyone know of any sample code for reading PNG files that doesn't > include using libpng.... just straight direct access. How about looking at libpng itself? It is the official reference implementation for PNG, and the source code is available under a permissive free software license. I'd think you'd learn at least as much by looking at the code for the official reference implementation as you'd learn by looking at any other code.
[toc] | [prev] | [next] | [standalone]
| From | Popping mad <rainbow@colition.gov> |
|---|---|
| Date | 2016-11-15 20:57 +0000 |
| Message-ID | <o0fsr3$k40$6@reader2.panix.com> |
| In reply to | #96639 |
On Tue, 15 Nov 2016 15:34:19 -0500, James R. Kuyper wrote: > How about looking at libpng itself? because after 15 years they suddenly broke half my images with their bug update and I specifically need to work around it to fix my images, not through it.
[toc] | [prev] | [next] | [standalone]
| From | "James R. Kuyper" <jameskuyper@verizon.net> |
|---|---|
| Date | 2016-11-15 16:12 -0500 |
| Message-ID | <31145d76-97ae-0d80-363f-b0b2ebbaffc5@verizon.net> |
| In reply to | #96641 |
On 11/15/2016 03:57 PM, Popping mad wrote: > On Tue, 15 Nov 2016 15:34:19 -0500, James R. Kuyper wrote: > >> How about looking at libpng itself? > > because after 15 years they suddenly broke half my images with their bug > update and I specifically need to work around it to fix my images, not > through it. Reading the source code might be the easiest way to figure out how to work around it.
[toc] | [prev] | [next] | [standalone]
| From | jadill33@gmail.com |
|---|---|
| Date | 2016-11-15 14:00 -0800 |
| Message-ID | <529b73c9-0c8c-4f30-8291-56e4d31f61e4@googlegroups.com> |
| In reply to | #96641 |
On Tuesday, November 15, 2016 at 3:57:17 PM UTC-5, Popping mad wrote: > On Tue, 15 Nov 2016 15:34:19 -0500, James R. Kuyper wrote: > > > How about looking at libpng itself? > > because after 15 years they suddenly broke half my images with their bug > update and I specifically need to work around it to fix my images, not > through it. One option is to use a tool like Beyond Compare to compare the source trees of the two versions of libpng to try to isolate the file change(s) that caused your problem. If the versions are not too far apart (so that there are not many large file differences), you may be able to merge the new file versions from the new libpng into the old libpng and try to rebuild incrementally to eliminate file changes that do not affect your images. An alternative is that you can do the same in Subversion/git or other source control program to visualize the differences. Commit the newest version of libpng that works with your images to a repo, then copy over files from the new version of libpng one at a time until you hack a version that works for you. You can also try contacting a libpng developer and if you have a couple sample images that demonstrate the problem that you're able to share, they may be considerate enough to do this analysis for you. I've experienced something similar myself when I need to migrate Wireshark plugin code to new major versions (e.g. 1.10->1.12->2.0->2.2) as the API changes can be somewhat significant. Best regards, John D.
[toc] | [prev] | [next] | [standalone]
| From | Jorgen Grahn <grahn+nntp@snipabacken.se> |
|---|---|
| Date | 2016-11-20 11:14 +0000 |
| Message-ID | <slrno331dd.5q5.grahn+nntp@frailea.sa.invalid> |
| In reply to | #96656 |
On Tue, 2016-11-15, jadill33@gmail.com wrote: > On Tuesday, November 15, 2016 at 3:57:17 PM UTC-5, Popping mad wrote: >> On Tue, 15 Nov 2016 15:34:19 -0500, James R. Kuyper wrote: >> >> > How about looking at libpng itself? >> >> because after 15 years they suddenly broke half my images with their bug >> update and I specifically need to work around it to fix my images, not >> through it. > > One option is to use a tool like Beyond Compare to compare the source trees > of the two versions of libpng to try to isolate the file change(s) that > caused your problem. If the versions are not too far apart (so that there > are not many large file differences), you may be able to merge the new file > versions from the new libpng into the old libpng and try to rebuild > incrementally to eliminate file changes that do not affect your images. > > An alternative is that you can do the same in Subversion/git or other source > control program to visualize the differences. Commit the newest version of > libpng that works with your images to a repo, then copy over files from the > new version of libpng one at a time until you hack a version that works for > you. I'd just clone the libpng git repo (listed at http://libpng.sourceforge.net/) and do a 'git bisect' on it. Or do the binary search for the oldest bad version manually. > You can also try contacting a libpng developer and if you have a couple > sample images that demonstrate the problem that you're able to share, they > may be considerate enough to do this analysis for you. Yes, they may find that interesting. Especially if there's software out there generating such files. /Jorgen -- // Jorgen Grahn <grahn@ Oo o. . . \X/ snipabacken.se> O o .
[toc] | [prev] | [next] | [standalone]
| From | Richard Heathfield <rjh@cpax.org.uk> |
|---|---|
| Date | 2016-11-15 21:45 +0000 |
| Message-ID | <o0fvki$c8n$1@dont-email.me> |
| In reply to | #96639 |
On 15/11/16 20:34, James R. Kuyper wrote:
> On 11/15/2016 02:40 PM, ruben safir wrote:
>> Does anyone know of any sample code for reading PNG files that doesn't
>> include using libpng.... just straight direct access.
>
> How about looking at libpng itself? It is the official reference
> implementation for PNG, and the source code is available under a
> permissive free software license. I'd think you'd learn at least as much
> by looking at the code for the official reference implementation as
> you'd learn by looking at any other code.
Just to encourage people to take James up on his suggestion, here are
some statistics from the libpng code.
Firstly, there'd better be LOTS of it. We want to learn a lot, don't we?
C files: 17
H files: 6
That looks promising, but not too impressive. Maybe we'd better count
lines instead:
Lines of C: 33593
Lines of H: 6791
Ah, that's better! But how much does it all *weigh*?
Kilobytes of C: 1116
Kilobytes of H: 304
Ah, that's very reassuring. Over a megabyte of C code. Let's remind
ourselves what we're doing: reading a PNG into memory, or writing it
out. Okay, a megabyte (of *source*) seems perfectly reasonable for that.
Now, we all know that there's nothing like the pre-processor for making
code readable, so let's hope they use the pre-processor a *lot*:
Number of lines of H starting #: 1667
Number of lines of C starting #: 2223
Yep, excellent.
Disappointingly, they supply a file, example.c, that shows you how to
use the library. You'd have thought you'd learn more from reading the
whole of the library code line by line in order to understand how to
call it.
But they redeem themselves in a most unexpected manner --- example.c
/does not compile/! And it's not supposed to. There's a comment to that
effect:
"This file does not currently compile, because it is missing certain
parts, like allocating memory to hold an image. You will have to supply
these parts to get it to compile."
They refer the interested reader, instead, to a 2000+ line test program,
which I presume was originally developed as an IOCCC entry. The main()
function calls a function named test_one_file(), which sounds quite a
promising place to start. Let's take a look at it:
/* Test one file */
static int
test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
{
static png_FILE_p fpin;
static png_FILE_p fpout; /* "static" prevents setjmp corruption */
pngtest_error_parameters error_parameters;
png_structp read_ptr;
png_infop read_info_ptr, end_info_ptr;
#ifdef PNG_WRITE_SUPPORTED
png_structp write_ptr;
png_infop write_info_ptr;
png_infop write_end_info_ptr;
#ifdef PNG_WRITE_FILTER_SUPPORTED
int interlace_preserved = 1;
#endif /* WRITE_FILTER */
#else /* !WRITE */
png_structp write_ptr = NULL;
Actually, since it's about 900 lines long, I don't think I'll show any
more of it. It's obviously all quite self-explanatory, and you won't
need any help at all in understanding it completely. Five minutes should
do it. Maybe ten if you're having a bad day. For the whole library?
Perhaps an hour. After all, it's only 40,000 lines.
--
Richard Heathfield
Email: rjh at cpax dot org dot uk
"Usenet is a strange place" - dmr 29 July 1999
Sig line 4 vacant - apply within
[toc] | [prev] | [next] | [standalone]
| From | "James R. Kuyper" <jameskuyper@verizon.net> |
|---|---|
| Date | 2016-11-15 17:15 -0500 |
| Message-ID | <58044c2b-c4d4-cfd7-7142-2b5ca73a6c28@verizon.net> |
| In reply to | #96650 |
On 11/15/2016 04:45 PM, Richard Heathfield wrote: > On 15/11/16 20:34, James R. Kuyper wrote: >> On 11/15/2016 02:40 PM, ruben safir wrote: >>> Does anyone know of any sample code for reading PNG files that doesn't >>> include using libpng.... just straight direct access. >> >> How about looking at libpng itself? It is the official reference >> implementation for PNG, and the source code is available under a >> permissive free software license. I'd think you'd learn at least as much >> by looking at the code for the official reference implementation as >> you'd learn by looking at any other code. > > Just to encourage people to take James up on his suggestion, here are > some statistics from the libpng code. ... > Ah, that's very reassuring. Over a megabyte of C code. Let's remind > ourselves what we're doing: reading a PNG into memory, or writing it > out. Okay, a megabyte (of *source*) seems perfectly reasonable for that. With you, it's sometimes hard to tell, but I'm going to assume you're being sarcastic. Keep in mind that this is the official reference implementation of PNG. Any fully functional alternative to libpng is likely to be comparably complicated - unless the implementors of libpng are exceptionally incompetent. I know nothing about that personally, but it seems unlikely that PNG would be as popular as it is if that were the case. Would a less-than-fully-functional alternative be acceptable? In that case, such an alternative could be a lot simpler - but that depends upon which features of PNG ruben needs to handle correctly.
[toc] | [prev] | [next] | [standalone]
| From | Richard Heathfield <rjh@cpax.org.uk> |
|---|---|
| Date | 2016-11-15 22:41 +0000 |
| Message-ID | <o0g2tk$ou4$1@dont-email.me> |
| In reply to | #96659 |
On 15/11/16 22:15, James R. Kuyper wrote:
> On 11/15/2016 04:45 PM, Richard Heathfield wrote:
>> On 15/11/16 20:34, James R. Kuyper wrote:
>>> On 11/15/2016 02:40 PM, ruben safir wrote:
>>>> Does anyone know of any sample code for reading PNG files that doesn't
>>>> include using libpng.... just straight direct access.
>>>
>>> How about looking at libpng itself? It is the official reference
>>> implementation for PNG, and the source code is available under a
>>> permissive free software license. I'd think you'd learn at least as much
>>> by looking at the code for the official reference implementation as
>>> you'd learn by looking at any other code.
>>
>> Just to encourage people to take James up on his suggestion, here are
>> some statistics from the libpng code.
> ...
>> Ah, that's very reassuring. Over a megabyte of C code. Let's remind
>> ourselves what we're doing: reading a PNG into memory, or writing it
>> out. Okay, a megabyte (of *source*) seems perfectly reasonable for that.
>
> With you, it's sometimes hard to tell,
Good. :-)
> but I'm going to assume you're being sarcastic.
On this occasion, you have correctly divined my intent.
> Keep in mind that this is the official reference implementation of PNG.
> Any fully functional alternative to libpng is likely to be comparably
> complicated - unless the implementors of libpng are exceptionally
> incompetent. I know nothing about that personally, but it seems unlikely
> that PNG would be as popular as it is if that were the case.
I don't think for a moment that they're incompetent. But readable code
clearly is not their priority.
>
> Would a less-than-fully-functional alternative be acceptable?
Hell yes!
> In that
> case, such an alternative could be a lot simpler - but that depends upon
> which features of PNG ruben needs to handle correctly.
I can't speak for Ruben's needs. But if anyone is planning to write a
simple PNG library, I would recommend the following interface:
/* returns width*height unsigned longs, encoding RGBA 00-FF */
unsigned long *png_load(const char *filename,
size_t *width,
size_t *height);
int png_save(const char filename,
unsigned long *frame,
size_t width,
size_t height);
And *nothing else*!
--
Richard Heathfield
Email: rjh at cpax dot org dot uk
"Usenet is a strange place" - dmr 29 July 1999
Sig line 4 vacant - apply within
[toc] | [prev] | [next] | [standalone]
| From | Melzzzzz <mel@zzzzz.com> |
|---|---|
| Date | 2016-11-15 23:49 +0100 |
| Message-ID | <20161115234903.5851f221@maxa-pc> |
| In reply to | #96660 |
On Tue, 15 Nov 2016 22:41:23 +0000 Richard Heathfield <rjh@cpax.org.uk> wrote: > > I can't speak for Ruben's needs. But if anyone is planning to write a > simple PNG library, I would recommend the following interface: > > /* returns width*height unsigned longs, encoding RGBA 00-FF */ > unsigned long *png_load(const char *filename, > size_t *width, > size_t *height); > > int png_save(const char filename, > unsigned long *frame, > size_t width, > size_t height); > > And *nothing else*! > Well, one can write wrapper around libpng, possibly C++ ;) -- press any key to continue or any other to quit
[toc] | [prev] | [next] | [standalone]
| From | Anton Shepelev <anton.txt@g{oogle}mail.com> |
|---|---|
| Date | 2016-11-16 15:23 +0300 |
| Message-ID | <20161116152343.8f327ba657c914b38a9a8492@g{oogle}mail.com> |
| In reply to | #96660 |
Richard Heathfield: >I can't speak for Ruben's needs. But if anyone is >planning to write a simple PNG library, I would >recommend the following interface: > >/* returns width*height unsigned longs, encoding RGBA 00-FF */ >unsigned long *png_load(const char *filename, > size_t *width, > size_t *height); > >int png_save(const char filename, > unsigned long *frame, > size_t width, > size_t height); > >And *nothing else*! Why do you return a potentially sparce matrix? Whereas many APIs accept a raw companct pixel array, it might be good to return that, i.e. void* or char*, where each four bytes represent an RGBA pix- el. -- () ascii ribbon campaign - against html e-mail /\ http://preview.tinyurl.com/qcy6mjc [archived]
[toc] | [prev] | [next] | [standalone]
| From | Richard Heathfield <rjh@cpax.org.uk> |
|---|---|
| Date | 2016-11-16 13:57 +0000 |
| Message-ID | <o0hoim$hra$1@dont-email.me> |
| In reply to | #96681 |
On 16/11/16 12:23, Anton Shepelev wrote: > Richard Heathfield: > >> I can't speak for Ruben's needs. But if anyone is >> planning to write a simple PNG library, I would >> recommend the following interface: >> >> /* returns width*height unsigned longs, encoding RGBA 00-FF */ >> unsigned long *png_load(const char *filename, >> size_t *width, >> size_t *height); >> >> int png_save(const char filename, >> unsigned long *frame, >> size_t width, >> size_t height); >> >> And *nothing else*! > > Why do you return a potentially sparce matrix? Well, I don't return anything, because that's a suggested interface, not a report of existing code. But why /would/ I? Because it's easy to understand and easy to incorporate into one's own code, that's why. Them as wants complicated can use libpng. -- Richard Heathfield Email: rjh at cpax dot org dot uk "Usenet is a strange place" - dmr 29 July 1999 Sig line 4 vacant - apply within
[toc] | [prev] | [next] | [standalone]
| From | BGB <cr88192@hotmail.com> |
|---|---|
| Date | 2016-11-18 01:24 -0600 |
| Message-ID | <o0maak$tva$1@news.albasani.net> |
| In reply to | #96684 |
On 11/16/2016 7:57 AM, Richard Heathfield wrote:
> On 16/11/16 12:23, Anton Shepelev wrote:
>> Richard Heathfield:
>>
>>> I can't speak for Ruben's needs. But if anyone is
>>> planning to write a simple PNG library, I would
>>> recommend the following interface:
>>>
>>> /* returns width*height unsigned longs, encoding RGBA 00-FF */
>>> unsigned long *png_load(const char *filename,
>>> size_t *width,
>>> size_t *height);
>>>
>>> int png_save(const char filename,
>>> unsigned long *frame,
>>> size_t width,
>>> size_t height);
>>>
>>> And *nothing else*!
>>
>> Why do you return a potentially sparce matrix?
>
> Well, I don't return anything, because that's a suggested interface, not
> a report of existing code. But why /would/ I? Because it's easy to
> understand and easy to incorporate into one's own code, that's why. Them
> as wants complicated can use libpng.
>
FWIW, the reason mine used buffers, rather than files or file-names, was
because buffers are generally more versatile (pretty much everything can
be done via a buffer on modern systems).
a lot of my other formats have a more complicated interface and
implementation, but mostly for other reasons of speed. PNG remained
simple, partly as earlier on I have basically given up on making it
fast. some aspects of PNG's design basically make fast decoding (much
past around 40-50 megapixels/second) essentially a road-block.
I had tried before, but just couldn't really manage to get it much
faster than this.
some of my other codecs can generally be a lot faster (faster ones
getting 300-400 Mpix/sec per thread for decoding, *), but at the cost of
a lot of hair, and frequently lackluster quality/bitrate.
*: on a 3GHz K10, peak is ~ 1.4 Gpix/sec for 4 threads. have gotten
around 3 Gpix/sec on a dual-socket Xeon E5410 (2.33 GHz) with 8 threads.
though, this is with inherently lossy VQ based designs.
could work on a fast lossless codec (probably based around blocky
Haar-like filter and Rice coding or similar, 1), but lack a strong
use-case ATM.
1: ex, possible design:
colorspace=GDbDrA (G, B-G, R-G, A)
blocks use 8x8 blocky filter.
at a basic level, pairs of points may be transformed:
A,B -> A+B,A-((A+B)/2)
a1=a+b; b1=a-(a1>>1);
a2=(a1>>1)+b1; b2=a1-a2;
these could be stacked up into a 2D block transform.
coefficients would use RLE and Rice coding.
count coded as a signed Rice symbol
0=EOB
<0=number of zeroes (followed by single coeff)
>0=number of non-zero coeffs.
each coeff is a signed Rice-coded value
could probably use an adaptive length-limited variant.
...
I had promising results with a similar design in the past, but didn't
really pursue it, as, for lossly cases, speeds fell short of what was
possible with VQ, but if doing lossless it could make sense, given VQ is
basically incapable of doing lossless.
though, unclear is if it would offer any sufficient advantages (in terms
of speed) vs PNG to make it worthwhile.
[toc] | [prev] | [next] | [standalone]
| From | BartC <bc@freeuk.com> |
|---|---|
| Date | 2016-11-18 11:56 +0000 |
| Message-ID | <o0mq7i$67c$1@dont-email.me> |
| In reply to | #96789 |
On 18/11/2016 07:24, BGB wrote: > a lot of my other formats have a more complicated interface and > implementation, but mostly for other reasons of speed. PNG remained > simple, partly as earlier on I have basically given up on making it > fast. some aspects of PNG's design basically make fast decoding (much > past around 40-50 megapixels/second) essentially a road-block. That doesn't sound too bad. The fastest C jpeg decoder I've tried took 6 seconds for an 80 Mpixel image (IIRC), so some 13Mpix/second. (Although that image had full chroma resolution so more info than normal.) > I had tried before, but just couldn't really manage to get it much > faster than this. > > some of my other codecs can generally be a lot faster (faster ones > getting 300-400 Mpix/sec per thread for decoding, *), but at the cost of > a lot of hair, and frequently lackluster quality/bitrate. Again that's very good unless you're talking about something like uncompressed BMP where it depends on how fast you can load a file into memory. (But BMP is lossless so probably not.) Doing a test now, of simply reading an 80MB file and expanding each byte to three, to end up with 240MB in memory (and doing nothing more with the result), took 0.27 secs so an upper limit of just under 900MB/second, using gcc-O3, and even that takes advantage of the file already being cached. With your figures, what size of input file does 300-400Mpix represent? (I guess this will be video rather than still images.) -- Bartc
[toc] | [prev] | [next] | [standalone]
| From | BGB <cr88192@hotmail.com> |
|---|---|
| Date | 2016-11-18 12:48 -0600 |
| Message-ID | <o0nicd$tb8$1@news.albasani.net> |
| In reply to | #96806 |
On 11/18/2016 5:56 AM, BartC wrote: > On 18/11/2016 07:24, BGB wrote: > >> a lot of my other formats have a more complicated interface and >> implementation, but mostly for other reasons of speed. PNG remained >> simple, partly as earlier on I have basically given up on making it >> fast. some aspects of PNG's design basically make fast decoding (much >> past around 40-50 megapixels/second) essentially a road-block. > > That doesn't sound too bad. The fastest C jpeg decoder I've tried took 6 > seconds for an 80 Mpixel image (IIRC), so some 13Mpix/second. (Although > that image had full chroma resolution so more info than normal.) > yeah. mine are generally a little faster than this. IME, can get JPEG decoding up to around 70-90 Mpix/sec, but typically with 4:2:0 subsampling. > >> I had tried before, but just couldn't really manage to get it much >> faster than this. >> >> some of my other codecs can generally be a lot faster (faster ones >> getting 300-400 Mpix/sec per thread for decoding, *), but at the cost of >> a lot of hair, and frequently lackluster quality/bitrate. > > Again that's very good unless you're talking about something like > uncompressed BMP where it depends on how fast you can load a file into > memory. (But BMP is lossless so probably not.) > for uncompressed BMP, one is going to run head-on with being IO bound (well, at least if using normal HDDs, which is my case). but, no, it is not raw BMPs. though, I typically still use the BMP header for still images, for other reasons. FWIW: for loading, I use a VFS which can help optimize IO some by reading in groups of files all in a shared buffer (as reading lots of small files individually from the HDD tends to be fairly slow). generally files are clustered by type, and if Deflate is used, it is applied over the group of files (vs per-file, as it would be in ZIP). > Doing a test now, of simply reading an 80MB file and expanding each byte > to three, to end up with 240MB in memory (and doing nothing more with > the result), took 0.27 secs so an upper limit of just under > 900MB/second, using gcc-O3, and even that takes advantage of the file > already being cached. > > With your figures, what size of input file does 300-400Mpix represent? > (I guess this will be video rather than still images.) > my test images had generally been around 1 to 16 Mpix (ex: 1024x1024 to 4096x4096), but the figure is mostly how quickly they can be decoded in a loop (note that images this size are too big to fit in cache for the BGRA decode path). bitrates for still images are typically 0.8 to 1.6 bits/pixel. quality/bitrate (Q/bpp) is typically still worse than JPEG, but not drastically (and it has an advantage here at lower quality levels). in the use-case, I was mostly trying for something "competitive" with JPEGs, where it mostly needed to be able to maximize decode speed, not be overly large, have passable image quality, ... I have codecs for both still images and video (video is easier to make fast, and because of delta compression it can break the 400 Mpix/sec limit by not needing to update the whole framebuffer). here is a basic format spec for one of my faster designs (BTIC4B): https://github.com/cr88192/bgbtech_misc/blob/master/tool_btic4b/docs/2016-06-25_BTIC4B2.txt but, basic overview is this design: it encodes 8x8 pixel blocks as a color-vector, and a block of bits is used to select interpolated colors from this vector. typically, the vector is unpacked into a LUT, and for pixels, the values from this LUT are copied to the output pixels. for blocks which use lower resolutions, the same pixel values are copied to multiple output pixels (and a flat 8x8 block is basically a flood-fill operation). there are blocks with higher levels of chroma subsampling (4:1:0, 4:2:0, 4:2:2, or 4:4:4), which can give better image quality, but the encoder uses them sparingly (as they are fairly expensive). typically pixels are worked with as 32-bit words, and in some cases, SIMD/SSE2 operations may be used to optimize memory-fill operations (speed advantages from SSE2 are modest but still significant). an older, albeit more widely used slightly slower and with worse Q/bpp design is this (BTIC1H): https://github.com/cr88192/bgbtech_misc/wiki/BTIC1H like the above, it is also reasonably fast. BTIC1H was a successor to BTIC1C, which was a Deflate-compressed heavily-extended variant of the "Apple QuickTime RPZA" video format (from the early 90s), where 1H had notably improved over 1C's Q/bpp. BTIC4B was derived from BTIC1H, with the most significant differences being: BTIC4B uses 8x8 blocks rather than 4x4, which reduces per-block overheads; it also uses an LSB-first bitstream rather than MSB first, where LSB first has an advantage in terms of reducing the cost of bitstream operations. though, the 8x8 blocks result in a fair bit more complexity vs 4x4. for 4B I had also developed a slightly better MTF scheme for doing symbol entropy coding: 1H had used a scheme (SMTF) where symbols were either swapped towards the front (index 1..31), or the symbol space was rotated and a symbol was swapped into the resulting hole (index 32..255). 4B uses a scheme I had called STF2, which simply swaps symbols at index I with ((I*7)/8), which seems overall both more effective, and is also faster (given no "if()" branches are needed, where things like "if()" branches and "for()" loops have a fairly high risk of adverse effects on performance). interestingly, there is a company known as Binomial which is working on commercializing vaguely similar technology. though, they seem to be going at things in a different direction. and, my stuff here is basically MIT licensed.
[toc] | [prev] | [next] | [standalone]
| From | BartC <bc@freeuk.com> |
|---|---|
| Date | 2016-11-19 00:21 +0000 |
| Message-ID | <o0o5to$7qb$1@dont-email.me> |
| In reply to | #96881 |
On 18/11/2016 18:48, BGB wrote:
> On 11/18/2016 5:56 AM, BartC wrote:
>> On 18/11/2016 07:24, BGB wrote:
>>
>>> a lot of my other formats have a more complicated interface and
>>> implementation, but mostly for other reasons of speed. PNG remained
>>> simple, partly as earlier on I have basically given up on making it
>>> fast. some aspects of PNG's design basically make fast decoding (much
>>> past around 40-50 megapixels/second) essentially a road-block.
>>
>> That doesn't sound too bad. The fastest C jpeg decoder I've tried took 6
>> seconds for an 80 Mpixel image (IIRC), so some 13Mpix/second. (Although
>> that image had full chroma resolution so more info than normal.)
>>
>
> yeah. mine are generally a little faster than this.
> IME, can get JPEG decoding up to around 70-90 Mpix/sec, but typically
> with 4:2:0 subsampling.
OK, a bit of a challenge them! On a 2Mpix test image ('2x2' subsampling
if that means anything; I think chroma resolution is half luminance in X
and Y), I get 1.2Mpix/second on interpreted code, 12Mpix using my
compiler and 15Mpix using C and gcc-O3. (Pixel rates tend to reduce on
bigger images.)
However that's using a decoding algorithm I don't understand so it would
be interesting to try my own.
> bitrates for still images are typically 0.8 to 1.6 bits/pixel.
(Colour? I first played with this stuff in 1981 with 4-bit greyscale
images from a frame-grabber. If I wanted it efficient, I just used the
top bit to end up with 1.0 bits/pixels. But it /was/ just 1 bit per
pixel! Although high noise level, especially on video, made it seem a
little better.
An interesting experiment however a few years later, when I was
digitising live composite video using 6 bits (trying to get around some
scrambling then sending it out again via a DAC). I could disconnect
several of the lower bits and still get a reasonable colour picture with
just 3 or 4 bits! 1 bit was problematical though; not surprising as I
had to encode hoz and vert syncs in that one bit too.)
> here is a basic format spec for one of my faster designs (BTIC4B):
> https://github.com/cr88192/bgbtech_misc/blob/master/tool_btic4b/docs/2016-06-25_BTIC4B2.txt
That looks pretty comprehensive to me...
TBH when I work on this jpeg stuff I have to do it blindly without
understanding, and just see it gives something that looks about right as
the output.
--
Bartc
[toc] | [prev] | [next] | [standalone]
| From | BGB <cr88192@hotmail.com> |
|---|---|
| Date | 2016-11-19 01:50 -0600 |
| Message-ID | <o0p07l$2go$1@news.albasani.net> |
| In reply to | #96921 |
On 11/18/2016 6:21 PM, BartC wrote:
> On 18/11/2016 18:48, BGB wrote:
>> On 11/18/2016 5:56 AM, BartC wrote:
>>> On 18/11/2016 07:24, BGB wrote:
>>>
>>>> a lot of my other formats have a more complicated interface and
>>>> implementation, but mostly for other reasons of speed. PNG remained
>>>> simple, partly as earlier on I have basically given up on making it
>>>> fast. some aspects of PNG's design basically make fast decoding (much
>>>> past around 40-50 megapixels/second) essentially a road-block.
>>>
>>> That doesn't sound too bad. The fastest C jpeg decoder I've tried took 6
>>> seconds for an 80 Mpixel image (IIRC), so some 13Mpix/second. (Although
>>> that image had full chroma resolution so more info than normal.)
>>>
>>
>> yeah. mine are generally a little faster than this.
>> IME, can get JPEG decoding up to around 70-90 Mpix/sec, but typically
>> with 4:2:0 subsampling.
>
> OK, a bit of a challenge them! On a 2Mpix test image ('2x2' subsampling
> if that means anything; I think chroma resolution is half luminance in X
> and Y), I get 1.2Mpix/second on interpreted code, 12Mpix using my
> compiler and 15Mpix using C and gcc-O3. (Pixel rates tend to reduce on
> bigger images.)
>
> However that's using a decoding algorithm I don't understand so it would
> be interesting to try my own.
>
speed is fairly dependent on optimizations, and I had optimized mine a bit.
one strategy is basically to make the decoder go through everything an
MCU/macroblock at a time, rather than using multiple stages (this helps
to keep things from going out of cache).
similar goes for doing a lot of stuff with unrolled loops, ...
>> bitrates for still images are typically 0.8 to 1.6 bits/pixel.
>
> (Colour? I first played with this stuff in 1981 with 4-bit greyscale
> images from a frame-grabber. If I wanted it efficient, I just used the
> top bit to end up with 1.0 bits/pixels. But it /was/ just 1 bit per
> pixel! Although high noise level, especially on video, made it seem a
> little better.
>
it is an average, but yes.
the reason it can go so low is not every pixel needs bits.
say, one has an 8x8 block, but the encoder decided to use 4x4x2 bits.
so, we have 64 pixels in 32 bits, or 0.5 bpp for the pixel data.
if it used a 2x2x2 block, it is 0.125 bpp, and no bits are used for a
flat color. in effect, for a 2x2 block, the 8x8 output block is filled
with 4 large pixels.
granted, one still needs bits for the color vector.
the encoder tries to select blocks such that cheaper blocks are used
where it wont matter as much, and more expensive blocks are used where
it is likely to be more noticeable (using a lot decision trees and
heuristics).
in places where there is more detail, more expensive blocks are used,
which can express more complex patterns, but frequently in large parts
of the image not a whole lot is going on, so the blocks can be
downsampled or expressed as a flat color.
generally the vector is (Y,U,V,Dy,Du,Dv), which may be interpreted
either as a vector between a pair of endpoints colors, or as a
bounding-box in YUV space (where YUV gives the box center, and Dyuv
gives the size).
in the most common blocks, 2 bits are used, which interpolate along the
Y axis.
Ym=Y-(Dy>>1); Yn=Ym+Dy
Um=U-(Du>>1); Un=Um+Du
Vm=V-(Dv>>1); Vn=Vm+Dv
say, for pixel bits:
00=Ym
01=2/3*Ym+1/3*Yn
10=1/3*Ym+2/3*Yn
11=Yn
in some cases, the same bits also select the U/V values:
00=Ym,Um,Vm
...
11=Yn,Un,Vn
so, Du and Dv may be negative (if negatively correlated with Y).
some other (more expensive) blocks separately interpolate Y,U,V values.
for unpacking block pixels, one can first generate a 4-element table
with all 4 possible colors in it, then the 2 bits will select which of
the table elements goes into the output pixel.
some other block formats use larger lookup tables.
for each block, the color vector is stored as a difference from a
predicted vector, generally using a modified Paeth variant (vaguely like
in PNG). the vector deltas are Rice-coded, along with block-commands,
but pixel bits are dumped into the bitstream as-is (the pixel-bits data
isn't particularly compressible)
> An interesting experiment however a few years later, when I was
> digitising live composite video using 6 bits (trying to get around some
> scrambling then sending it out again via a DAC). I could disconnect
> several of the lower bits and still get a reasonable colour picture with
> just 3 or 4 bits! 1 bit was problematical though; not surprising as I
> had to encode hoz and vert syncs in that one bit too.)
>
typically the logical colorspace has a full 8-bit depth.
because the pixel bits mostly select the colors, rather than define
them, there are fewer adverse effects to using fewer bits per-pixel.
>> here is a basic format spec for one of my faster designs (BTIC4B):
>> https://github.com/cr88192/bgbtech_misc/blob/master/tool_btic4b/docs/2016-06-25_BTIC4B2.txt
>>
>
> That looks pretty comprehensive to me...
>
> TBH when I work on this jpeg stuff I have to do it blindly without
> understanding, and just see it gives something that looks about right as
> the output.
>
BTIC4B is not JPEG, basically completely different technology (mostly
based on designs that were popular in the early/mid 90s but pretty much
died when JPEG and MPEG came along).
though, it is worth noting that at the time, storage and bandwidth were
the dominant concerns, and CPU speeds were going up rapidly. however,
CPU speeds have since effectively hit a plateau, but storage space and
bandwidth continue to increase, likewise for resolutions.
for example, a simple case is my PC, vs a 13 year old laptop.
if I want to do full-screen capture, I actually get higher framerates on
the laptop than on my PC.
reason is because the budget of clock-cycles-per-pixel is lower on a
3GHz processor dealing with 1920x1080, than on a 1.7GHz processor
dealing with 1024x768.
between them is a laptop with a 2.1 GHz processor and a 1440x900 display.
so, CPU clock speed went up 77%, but screen resolution went up by 164%.
difference in RAM is 3200%, and difference in available HDD space is
6600%. likewise, I have 18200% as much internet bandwidth as well.
...
[toc] | [prev] | [next] | [standalone]
Page 1 of 2 [1] 2 Next page →
Back to top | Article view | comp.lang.c
csiph-web