void writeuncompressed(int fd, Memimage *m) { char chanstr[32]; int bpl, y, j; uchar *buf; if(chantostr(chanstr, m->chan) == nil) sysfatal("can't convert channel descriptor: %r"); fprint(fd, "%11s %11d %11d %11d %11d ", chanstr, m->r.min.x, m->r.min.y, m->r.max.x, m->r.max.y); bpl = bytesperline(m->r, m->depth); buf = malloc(bpl); if(buf == nil) sysfatal("malloc failed: %r"); for(y=m->r.min.y; y<m->r.max.y; y++){ j = unloadmemimage(m, Rect(m->r.min.x, y, m->r.max.x, y+1), buf, bpl); if(j != bpl) sysfatal("image unload failed: %r"); if(write(fd, buf, bpl) != bpl) sysfatal("write failed: %r"); } free(buf); }
int memunload(Memimage *src, Rectangle r, uint8_t *data, int n) { Memimage *tmp; Memlayer *dl; Rectangle lr; int dx; Top: dl = src->layer; if(dl == nil) return unloadmemimage(src, r, data, n); /* * Convert to screen coordinates. */ lr = r; r.min.x += dl->delta.x; r.min.y += dl->delta.y; r.max.x += dl->delta.x; r.max.y += dl->delta.y; dx = dl->delta.x&(7/src->depth); if(dl->clear && dx==0){ src = dl->screen->image; goto Top; } /* * src is an obscured layer or data is unaligned */ if(dl->save && dx==0){ if(dl->refreshfn != nil) return -1; /* can't unload window if it's not Refbackup */ if(n > 0) memlhide(src, r); n = unloadmemimage(dl->save, lr, data, n); return n; } tmp = allocmemimage(lr, src->chan); if(tmp == nil) return -1; memdraw(tmp, lr, src, lr.min, nil, lr.min, S); n = unloadmemimage(tmp, lr, data, n); freememimage(tmp); return n; }
void getimage(Cimage *ci, Rune *altr) { Rectangle r; Memimage *mi; Image *i, *i2; char buf[128]; uchar *bits; int nbits; mi = ci->mi; if(mi == nil) { snprint(buf, sizeof(buf), "[%S]", altr ? altr : L"IMG"); r.min = Pt(0, 0); r.max.x = 2*Space + stringwidth(font, buf); r.max.y = 2*Space + font->height; ci->i = eallocimage(display, r, GREY1, 1, DBlack); r.min.x += Space; r.min.y += Space; string(ci->i, r.min, display->white, ZP, font, buf); return; } nbits = bytesperline(mi->r, mi->depth)*Dy(mi->r); bits = emalloc(nbits); unloadmemimage(mi, mi->r, bits, nbits); /* /* get rid of alpha channel from transparent gif * / if(mi->depth == 16){ for(y=1; y<nbits; y+=2) bits[y>>1] = bits[y]; } */ i = eallocimage(display, mi->r, mi->chan, 0, DNofill); loadimage(i, i->r, bits, nbits); i2 = eallocimage(display, i->r, RGB24, 1, DNofill); draw(i2, i2->r, display->black, nil, ZP); draw(i2, i2->r, i, nil, i->r.min); free(bits); freememimage(mi); freeimage(i); ci->i = i2; ci->mi = nil; }