int kCSRI::Draw(videoframe& dst) { // Check if CSRI loaded properly if(!kInstance) return 1; // no CSRI loaded // Load data into frame csri_frame frame; frame.pixfmt = CSRI_F_BGR_; for(size_t i = 0; i < 4; i++) { frame.planes[i] = NULL; frame.strides[0] = 0; } frame.planes[0] = dst.data; frame.strides[0] = 4 * dst.width; // Set format csri_fmt format; format.width = dst.width; format.height = dst.height; format.pixfmt = frame.pixfmt; int error = csri_request_fmt(kInstance, &format); if(error) return 2; // incompatible format // Render csri_render(kInstance, &frame, 0); return 0; }
void CSRISubtitlesProvider::DrawSubtitles(VideoFrame &dst,double time) { if (!instance) return; csri_frame frame; if (dst.flipped) { frame.planes[0] = dst.data.data() + (dst.height-1) * dst.width * 4; frame.strides[0] = -(signed)dst.width * 4; } else { frame.planes[0] = dst.data.data(); frame.strides[0] = dst.width * 4; } frame.pixfmt = CSRI_F_BGR_; csri_fmt format = { frame.pixfmt, dst.width, dst.height }; std::lock_guard<std::mutex> lock(csri_mutex); if (!csri_request_fmt(instance, &format)) csri_render(instance, &frame, time); }
PVideoFrame __stdcall CSRIAviSynth::GetFrame(int n, IScriptEnvironment *env) { PVideoFrame avsframe = child->GetFrame(n, env); struct csri_frame frame; env->MakeWritable(&avsframe); frame.pixfmt = GetPixfmt(); frame.planes[0] = avsframe->GetWritePtr(); frame.strides[0] = avsframe->GetPitch(); if (csri_is_yuv_planar(frame.pixfmt)) { frame.planes[1] = avsframe->GetWritePtr(PLANAR_U); frame.strides[1] = avsframe->GetPitch(PLANAR_U); frame.planes[2] = avsframe->GetWritePtr(PLANAR_V); frame.strides[2] = avsframe->GetPitch(PLANAR_V); } if (csri_is_rgb(frame.pixfmt)) { frame.planes[0] += (vi.height - 1) * frame.strides[0]; frame.strides[0] = -frame.strides[0]; } csri_render(inst, &frame, n * spf); return avsframe; }