Exemplo n.º 1
0
 Array<unsigned char> pack_end() {
     
     stbtt_PackEnd(spc);
     
     return to_haxe_bytes(spc->pixels, spc->width * spc->height);
     
 }
Exemplo n.º 2
0
        Dynamic bake_font_bitmap(char const *filename, float pixel_height, int px, int py, int first_char, int num_chars) {

            unsigned char *bake_pixels = new unsigned char[px*py];
            stbtt_bakedchar *backed_char_data = new stbtt_bakedchar[num_chars];

            fread(ttf_buffer, 1, 1<<25, fopen(filename, "rb"));
            stbtt_BakeFontBitmap(ttf_buffer, 0, pixel_height, bake_pixels, px, py, first_char, num_chars, backed_char_data);
            
            hx::Anon result = hx::Anon_obj::Create();
            
            result->Add(HX_CSTRING("pixels"), to_haxe_bytes(bake_pixels, px * py));
            result->Add(HX_CSTRING("charData"), to_baked_char_data(backed_char_data, num_chars));

            return result;
        }
Exemplo n.º 3
0
      Dynamic read_frame(struct DecInputContext *input) {

        vpx_codec_iter_t iter = NULL;
        vpx_image_t *img;

        uint8_t *buf = NULL;
        size_t bytes_in_buffer = 0;
        size_t buffer_size = 0;
        int status = webm_read_frame(input->webm_ctx, &buf, &bytes_in_buffer, &buffer_size);
        if(status == 0) {
          if(vpx_codec_decode(input->decoder, buf, (unsigned int)bytes_in_buffer, NULL, 0)) {
            warn("Failed to decode frame: %s", vpx_codec_error(input->decoder));
          }
        } else {
          warn("EOF/Error %d", status);
        }

        if(status == 0) {
          img = vpx_codec_get_frame(input->decoder, &iter);
        } else {
          img = NULL;
        }

        /*
        {
          status:Int, (0 = success, 1 = EOF, -1 = Error)
          data:BytesData, // image bytes
          width:Int,
          height:Int,
          comp:Int, // RGBA = 4
        }
        */
        int width = 0;
        int height = 0;
        int comp = 4;
        unsigned char* rgba;


        hx::Anon result = hx::Anon_obj::Create();
        result->Add(HX_CSTRING("status"), status);

        if(img != NULL) {
          width = img->d_w;
          height = img->d_h;
          rgba = (unsigned char*)malloc(sizeof(unsigned char) * width * height * comp);
          if(img->fmt == VPX_IMG_FMT_I420) {
            ::libyuv::I420ToABGR(
              img->planes[VPX_PLANE_Y],img->stride[VPX_PLANE_Y],
              img->planes[VPX_PLANE_U],img->stride[VPX_PLANE_U],
              img->planes[VPX_PLANE_V],img->stride[VPX_PLANE_V],
              rgba, width * comp, width, height
            );

            ImgBytesData data = to_haxe_bytes(rgba, width * height * comp);
            result->Add(HX_CSTRING("data"), data);

          } else {
            warn("Img format unknown");
          }
        } else {
          warn("No image decoded!");
        }

        result->Add(HX_CSTRING("width"), width);
        result->Add(HX_CSTRING("height"), height);
        result->Add(HX_CSTRING("comp"), comp);


        return result;

      }