Comments (11)
I'm glad you have such motivation, but image scaling/resizing is not something easy, there are many filter/algorithm. And I'm afraid all of them fall into the realm of image processing/rendering.
one of the main purpose of PNG is to preserve pixel data intact because PNG use lossless compression,
scaling/resizing will make the pixel data altered.
But I don't want to kill your motivation either, perhaps you can working with APNG offset and alpha rendering(please read the readme.md and APNG spec). They are fairly easy and can be implemented on top of existing API without knowing to much about the underlying details.
If you already mastered this technique, then you'll have very good foundation to understand resizing/scaling problem.
in the tests folder there is minibmp.nim, you can use that to produce the result of the rendering. your work will become additional tools for nimPNG that is still inside the scope of this library.
from nimpng.
https://github.com/SolitudeSF/imageman/blob/master/src/imageman/resize.nim I think this file can be ported to nimPNG
from nimpng.
no need to port them, you can use nimPNG
and imageman
together. You only need to convert PNGResult
to imageman Image
with RGBAU
colorspace. And with some pointer tricks, you actually can have almost free conversion.
example:
type
MyImage = ref Image[ColorRGBAU]
let png = loadPNG32("pngfile.png")
let img = cast[MyImage](png)
let res = resizeBilinear(img[], target_w, target_h)
from nimpng.
that's cool , there's problem imageman
relys on libpng
which is not pure, would it acceptable to make a PR port of resize.nim?
from nimpng.
you can safely import imageman's images
and colors
module and use it with nimPNG
, if LTO(link time optimization) works properly. no need to worry libpng will be included in your final binary.
no need to port it.
from nimpng.
Thanks! helpfull , that type casting is magic. solve my problem.
from nimpng.
I have another problem , how to construct PNG(or encode png bytes) from MyImage
I need pass it to my optimizePNG
proc or save it somewhere directly, if I use imageman
when writePng it will need libpng.
from nimpng.
I assume you get the image after resizing then it would be something like this:
type
MyImage = ref Image[ColorRGBAU]
TImage = ptr object
width: int
height: int
pixels: seq[uint8]
let png = loadPNG32("pngfile.png")
let img = cast[MyImage](png)
var res = resizeBilinear(img[], target_w, target_h)
let timg = cast[TImage](unsafeAddr(res))
var r = savePNG32("filename.png", timg.pixels, timg.width, timg.height)
if r.isOK:
# do something
else:
# do something
tips: as long as the target object have similar structure/size, you can cast it using pointer(no copies), or using object if you can afford copies. you can read more about this trick from C programming language manual.
from nimpng.
I got unhandled exception: not enough input to encode [PNGError]
whether encodePNG
or savePNG32
, I suppose to store it in memory and pass to next proc,
yeah, that tips helpful, seq[ColorRGBAU]
cast to string
surprised me , since ColorRGBAU is 4 components, I check the source it's array so it's just bytes
from nimpng.
the pixels element length should be w x h x 4 for RGBAU and w x h x 3 for RGBU.
from nimpng.
yeah, casting can't adjust that seq size , that cause this , I'll retry later . use copymem or something else.
from nimpng.
Related Issues (20)
- Throw exceptions on errors instead of writing to stdout HOT 12
- Tests fail when using --gc:arc HOT 3
- This hash look up in calculateColorProfile is the slowest part of saving an image. HOT 2
- compiletime decoder HOT 2
- New API βΒ can't savePNG32 with a seq[uint8] HOT 2
- Error: unhandled exception: cannot read from stream [IOError] HOT 4
- Improve chunk parser flexibility when decoding incomplete input data.
- savePNG doesn't work for arrays
- Allow parsing into different data types HOT 1
- nim 1.6.0 savePNG results in too nested template instantiation HOT 4
- How to remove all unnecessary data HOT 8
- Enable user to configure compression library settings
- Need better documentation for encoder settings
- Warning: conversion to enum with holes is unsafe: PNGColorType(typ`gensym14) [HoleEnumConv]
- Doesn't compile on Nim devel due to `shallowCopy` being removed from the language.
- `decodePNG` colorType unexpected HOT 3
- savePNGImpl maybe have bug? HOT 3
- Doesn't work by default on Nim v2.0.0 HOT 2
- nimPNG relies on bugs of `newString` to work
- Move tests to another repo HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nimpng.