inline void AlphaBlend( Uint32& p, int cr, int cg, int cb, int a, int ia ) { //888 p = R16G16B16_TO_RGB888( a * cr + ia * R32(p), a * cg + ia * G32(p), a * cb + ia * B32(p) ); }
void OnPaint(GSurface *pDC) { GRect r = GetClient(); LgiWideBorder(pDC, r, DefaultRaisedEdge); pDC->Colour(LC_MED, 24); pDC->Rectangle(&r); SysFont->Transparent(true); if (Colour->Presets.Length()) { char s[64]; SysFont->Colour(LC_BLACK, LC_MED); GDisplayString ds(SysFont, (char*)LgiLoadString(L_COLOUR_NONE, "No Colour")); ds.Draw(pDC, r.x1 + 2, r.y1 + 2); for (unsigned i=0; i<Colour->Presets.Length(); i++) { int y = r.y1 + ((i+1) * Ly); COLOUR p32 = Colour->Presets[i]; pDC->Colour(p32, 32); pDC->Rectangle(r.x1+1, y+1, r.x1+Ly-1, y+Ly-1); sprintf_s(s, sizeof(s), "%2.2X,%2.2X,%2.2X", R32(p32), G32(p32), B32(p32)); GDisplayString ds(SysFont, s); ds.Draw(pDC, r.x1 + Ly + 10, y + 2); } } }
void ExtractRgb( uint32 c, int& r, int &g, int &b ) { r = R32(c); g = G32(c); b = B32(c); }
int verifysigner(uchar *sign, int len, uchar *data, ulong ndata) { Get sig; int alg; ulong issued, expires, now; int footprint, r, n; uchar buf[128], digest[SHA1dlen]; DigestState *ds; volatile struct {mpint* b;} b; volatile struct {mpint* s;} s; SigAlgVec *sa; Signerkey *key; Skeyset *sigs; /* alg[1] issued[4] expires[4] footprint[2] signer[n] sig[m] */ sigs = up->env->sigs; if(sigs == nil) return 1; /* not enforcing signed modules */ sig.p = sign; sig.ep = sign+len; alg = vc(&sig); if(alg != 2) return 0; /* we do only SHA1/RSA */ sa = findsigalg("rsa"); if(sa == nil) return 0; if(vs(buf, sizeof(buf), &sig, 4) < 0) return 0; now = osusectime()/1000000; issued = G32(buf); if(vs(buf, sizeof(buf), &sig, 4) < 0) return 0; if(issued != 0 && now < issued) return 0; expires = G32(buf); if(expires != 0 && now >= expires) return 0; footprint = vc(&sig) << 8; footprint |= vc(&sig); if(footprint < 0) return 0; r = 0; b.b = nil; s.s = nil; qlock(&sigs->l); if(waserror()) goto out; if((n = vs(buf, sizeof(buf)-NUMSIZE-1, &sig, -1)) < 0) /* owner */ goto out; buf[n] = 0; key = findsignerkey(sigs, sa->name, footprint, (char*)buf); if(key == nil) goto out; n += snprint((char*)buf+n, NUMSIZE, " %lud", expires); ds = sha1(buf, n, nil, nil); sha1(data, ndata, digest, ds); b.b = betomp(digest, SHA1dlen, nil); if(b.b == nil) goto out; s.s = betomp(sig.p, sig.ep-sig.p, nil); if(s.s == nil) goto out; r = (*sa->verify)(b.b, s.s, key->pk); out: qunlock(&sigs->l); if(b.b != nil) mpfree(b.b); if(s.s != nil) mpfree(s.s); return r; }
int JpegCompressor::compressRawImage(const void * image, int width, int height, int quality, int useEffect = 0) { void * src = const_cast<void *>(image); uint8_t *yp = static_cast<uint8_t *>(src); struct jpeg_compress_struct cinfo; struct jpeg_error_mgr jerr; JSAMPROW row_pointer[1]; uint8_t *line_buffer; int bufferlen = width*height<<1; line_buffer = (uint8_t*)calloc(width*3,1); mJpegBuffer = new uint8_t[bufferlen]; mJpegSize = 0; if(!line_buffer) { LOGE("@TEI compress_yuv_to_jpeg: line_buffer calloc failed!" ); return -1; } if (!mJpegBuffer) { free(line_buffer); return -1; } cinfo.err = jpeg_std_error (&jerr); jpeg_create_compress (&cinfo); jpeg_nf_stdio_dest(&cinfo,(char*)mJpegBuffer,&bufferlen ); cinfo.image_width = width; cinfo.image_height = height; cinfo.input_components = 3; cinfo.in_color_space = JCS_RGB; jpeg_set_defaults (&cinfo); jpeg_set_quality (&cinfo, quality, TRUE); jpeg_start_compress (&cinfo, TRUE); uint8_t *vp, *up,*vpos, *upos; getYuvOffsets(width, height, yp, &up, &vp); vpos=vp; upos=up; uint32_t rgb = 0xFFFFFFFF; int z = 0; while (cinfo.next_scanline < cinfo.image_height) { unsigned char *ptr = line_buffer; for (int x = 0; x < width; x += 2) { rgb = YUVToRGB32WithEffect(*yp, *up, *vp, useEffect); *ptr++ = R32(rgb); *ptr++ = G32(rgb); *ptr++ = B32(rgb); // yp += mStrides[0]; rgb = YUVToRGB32WithEffect(*yp, *up, *vp, useEffect); *ptr++ = R32(rgb); *ptr++ = G32(rgb); *ptr++ = B32(rgb); // yp += mStrides[0]; up += mStrides[1]; vp += mStrides[2]; } if (mIs420) { if (z == 0) { vp = vpos; up = upos; z++; } else { vpos = vp; upos = up; z--; } } row_pointer[0] = line_buffer; jpeg_write_scanlines (&cinfo, row_pointer, 1); } jpeg_finish_compress (&cinfo); jpeg_destroy_compress (&cinfo); free (line_buffer); mJpegSize = bufferlen; LOGD("====== Jpeg size: %d ======", mJpegSize); return 0; }