Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #96661

Re: PNG coding

From Melzzzzz <mel@zzzzz.com>
Newsgroups comp.lang.c
Subject Re: PNG coding
Date 2016-11-15 23:42 +0100
Organization albasani.net
Message-ID <20161115234214.3c2bf7e4@maxa-pc> (permalink)
References <o0foak$4cu$1@reader2.panix.com> <efb414a2-37fd-f415-1353-d92dad04592b@verizon.net> <o0fvki$c8n$1@dont-email.me> <58044c2b-c4d4-cfd7-7142-2b5ca73a6c28@verizon.net>

Show all headers | View raw


On Tue, 15 Nov 2016 17:15:55 -0500
"James R. Kuyper" <jameskuyper@verizon.net> 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, 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.
> 

Well, how about Golang implementation?
[bmaxa@maxa-pc png]$ ls -l
total 28
drwxr-xr-x 3 bmaxa users    15 14.07.2015 20:01 testdata/
-rw-r--r-- 1 bmaxa users  3685 24.09.2016 02:52 example_test.go
-rw-r--r-- 1 bmaxa users  1768 11.12.2014 20:19 paeth.go
-rw-r--r-- 1 bmaxa users  2252 11.12.2014 20:19 paeth_test.go
-rw-r--r-- 1 bmaxa users 25588 28.10.2016 16:47 reader.go
-rw-r--r-- 1 bmaxa users 17597 28.10.2016 16:47 reader_test.go
-rw-r--r-- 1 bmaxa users 12530 01.10.2016 00:01 writer.go
-rw-r--r-- 1 bmaxa users  4670 11.12.2014 20:19 writer_test.go

reader/writer_test are bunch of golang routines to test every aspect of
library.
This is example decode:

func ExampleDecode() {
        // This example uses png.Decode which can only decode PNG images.
        // Consider using the general image.Decode as it can sniff and decode any registered image format.
        img, err := png.Decode(gopherPNG())
        if err != nil {
                log.Fatal(err)
        }

        levels := []string{" ", "░", "▒", "▓", "█"}

        for y := img.Bounds().Min.Y; y < img.Bounds().Max.Y; y++ {
                for x := img.Bounds().Min.X; x < img.Bounds().Max.X; x++ {
                        c := color.GrayModel.Convert(img.At(x, y)).(color.Gray)
                        level := c.Y / 51 // 51 * 5 = 255
                        if level == 5 {
                                level--
                        }
                        fmt.Print(levels[level])
                }
                fmt.Print("\n")
        }
}

-- 
press any key to continue or any other to quit

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

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

csiph-web